条件是正确的,类仍然没有追加/删除-Python
当我遇到这个问题时,我正在编写自己版本的Lucky 9(每个玩家得到2张牌,并被询问是否需要另一张牌,他们的分数相当于(值的总和)%10)。 每个玩家只有在有足够的钱下注的情况下才能继续,如果他们没有足够的钱,他们将从游戏的活动玩家列表中删除条件是正确的,类仍然没有追加/删除-Python,python,design-patterns,append,Python,Design Patterns,Append,当我遇到这个问题时,我正在编写自己版本的Lucky 9(每个玩家得到2张牌,并被询问是否需要另一张牌,他们的分数相当于(值的总和)%10)。 每个玩家只有在有足够的钱下注的情况下才能继续,如果他们没有足够的钱,他们将从游戏的活动玩家列表中删除self.playing在class game()中,并移动到self.playible。但是,即使要移动的条件满足,也不是所有类都能正确处理 这就是我遇到问题的地方: self.observer.notifyListeners(self.playing,
self.playing
在class game()
中,并移动到self.playible
。但是,即使要移动的条件满足,也不是所有类都能正确处理
这就是我遇到问题的地方:
self.observer.notifyListeners(self.playing, self.deck.cards, self) '''yeah, i used an observer design pattern'''
然后重定向到此部分:
def notifyListeners(self, x, kards, system):
#These are all in an observer class and I pass class game as "system" as the parameter
x.sort(key = lambda x: x.points)
for y in x:
print y.name, y.points
for z in y.cards:
self.pastcards.append(z)
y.cards = []
winners = []
winners.append(x[len(x)-1])
for y in x:
if y.points == winners[0].points and y is not x[len(x)-1]:
winners.append(y)
self.money = self.money/len(winners)
for y in winners:
y.handlemove(self.money)
print y.name, " wins."
for y in x:
if y.name == "Streaky" and y not in winnders:
y.wins = 0
else:
pass
for y in x:
print y.name, ": ", y.money
print len(self.pastcards)
print "Cards left: ", len(kards)
for y in x:
if y.money < 100:
y.isEligible = False
for y in x:
if y.isEligible == False:
system.playable.append(y)
self.removelisteners(y)
system.playing.remove(y)
for y in x:
print y.name, y.money
def notifyListeners(self、x、kards、system):
#这些都在一个观察者类中,我通过类游戏作为“系统”作为参数
x、 排序(key=lambda x:x.points)
对于x中的y:
打印y.name,y.points
对于y卡中的z:
self.passcards.append(z)
y、 卡片=[]
优胜者=[]
winners.append(x[len(x)-1])
对于x中的y:
如果y.points==winners[0],则为点且y不是x[len(x)-1]:
获奖者。附加(y)
self.money=self.money/len(优胜者)
对于获奖者中的y:
y、 handlemove(自我金钱)
打印y.name,“赢”
对于x中的y:
如果y.name==“Streaky”且y不在winnders中:
y、 wins=0
其他:
通过
对于x中的y:
打印y.name,“:”,y.money
打印len(自复制卡片)
打印“左卡:”,len(卡丁车)
对于x中的y:
如果y.money<100:
y、 易懂=错误
对于x中的y:
如果y.isEligible==False:
system.playable.append(y)
自重构监听器(y)
系统。播放。删除(y)
对于x中的y:
打印你的名字,你的钱
我把它们打印出来,这样我就可以看到谁离开了,但是有时候,玩家们为什么要在x上循环四次?每个循环都是为了完成不同的任务(第一个决定胜利者,下一个给他们奖金,第三个决定留下谁,最后一个做适当的删除/附加)。我不想把它们都放在一个循环中(尽管这样会更好吗?),这样我就可以一步一步地看到它们的走向。