我正在浏览一个网上找到的举重模式的例子。
CustomCell cell = tableView.DequeueReusableCell("MailCell") as CustomCell ?? new CustomCell();
实施:这在反恐精英游戏中实现了恐怖分子和反恐怖分子的创建。因此,我们有2个类别,一个是针对Terrorist(T)的,另一个是针对Counter Terrorist(CT)的。每当玩家要求武器时,我们都会将其分配给他。在任务中,恐怖分子的任务是植入炸弹,而反恐怖分子则必须扩散炸弹。
我相信这个例子是错误的。在此代码中Object保持不变,我们只是在更改武器,如果有新的Player进入游戏,那么每个人武器的状态都会改变。我了解这个权利吗? 任何人都可以给我一个很好的例子。
答案 0 :(得分:1)
你是对的,你的榜样是错误的。哈希图中您只有2个玩家(CT和Tero)。使用哈希表存储2个必须播放的对象非常简单。
由于您只有两次比赛,并且您要更改他们的属性,因此实际上是在更改所有玩家配置:)
我有modified a litle the example来证明这是错误的。我只是将播放器存储在一个数组中,然后重新打印。
System.out.println("reuse --------------------------");
for(Player p : players){
p.mission();
}
这给了我流畅的输出:
Terrorist Created
Terrorist with weapon Maverick| Task is PLANT A BOMB
Counter Terrorist Created
Counter Terrorist with weapon AK-47| Task is DIFFUSE BOMB
Terrorist with weapon AK-47| Task is PLANT A BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
Terrorist with weapon Gut Knife| Task is PLANT A BOMB
Counter Terrorist with weapon Desert Eagle| Task is DIFFUSE BOMB
Terrorist with weapon Gut Knife| Task is PLANT A BOMB
Counter Terrorist with weapon Gut Knife| Task is DIFFUSE BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
reuse --------------------------
Terrorist with weapon Maverick| Task is PLANT A BOMB
Counter Terrorist with weapon Gut Knife| Task is DIFFUSE BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
Counter Terrorist with weapon Gut Knife| Task is DIFFUSE BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
Counter Terrorist with weapon Gut Knife| Task is DIFFUSE BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
Terrorist with weapon Maverick| Task is PLANT A BOMB
您清楚地看到每个团队都是相同的武器(最后选择)。
如果您想获得一个很好的例子,请遵循您文章的引用;):) :)像wikipedia
原则是重用已经创建的配置。