comparison frontends/src/quick_frontend/quick_card_game.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children beaf6bec2fcd
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
23 from sat.tools.jid import JID 23 from sat.tools.jid import JID
24 24
25 25
26 26
27 class QuickCardGame(): 27 class QuickCardGame():
28 28
29 def __init__(self, parent, referee, players, player_nick): 29 def __init__(self, parent, referee, players, player_nick):
30 self._autoplay = None #XXX: use 0 to activate fake play, None else 30 self._autoplay = None #XXX: use 0 to activate fake play, None else
31 self.parent = parent 31 self.parent = parent
32 self.referee = referee 32 self.referee = referee
33 self.players = players 33 self.players = players
56 del self.hand[:] 56 del self.hand[:]
57 del self.to_show[:] 57 del self.to_show[:]
58 self.state = None 58 self.state = None
59 for pl in self.played: 59 for pl in self.played:
60 self.played[pl] = None 60 self.played[pl] = None
61 61
62 def getPlayerLocation(self, nick): 62 def getPlayerLocation(self, nick):
63 """return player location (top,bottom,left or right)""" 63 """return player location (top,bottom,left or right)"""
64 for location in ['top','left','bottom','right']: 64 for location in ['top','left','bottom','right']:
65 if getattr(self,'%s_nick' % location) == nick: 65 if getattr(self,'%s_nick' % location) == nick:
66 return location 66 return location
74 self.cards["atout"]={} #As Tarot is a french game, it's more handy & logical to keep french names 74 self.cards["atout"]={} #As Tarot is a french game, it's more handy & logical to keep french names
75 self.cards["pique"]={} #spade 75 self.cards["pique"]={} #spade
76 self.cards["coeur"]={} #heart 76 self.cards["coeur"]={} #heart
77 self.cards["carreau"]={} #diamond 77 self.cards["carreau"]={} #diamond
78 self.cards["trefle"]={} #club 78 self.cards["trefle"]={} #club
79 79
80 def newGame(self, hand): 80 def newGame(self, hand):
81 """Start a new game, with given hand""" 81 """Start a new game, with given hand"""
82 assert (len(self.hand) == 0) 82 assert (len(self.hand) == 0)
83 for suit, value in hand: 83 for suit, value in hand:
84 self.hand.append(self.cards[suit, value]) 84 self.hand.append(self.cards[suit, value])
85 self.hand.sort() 85 self.hand.sort()
86 self.state = "init" 86 self.state = "init"
87 87
88 def contratSelected(self, contrat): 88 def contratSelected(self, contrat):
89 """Called when the contrat has been choosed 89 """Called when the contrat has been choosed
90 @param data: form result""" 90 @param data: form result"""
91 self.parent.host.bridge.tarotGameContratChoosed(self.player_nick, self.referee, contrat or 'Passe', self.parent.host.profile) 91 self.parent.host.bridge.tarotGameContratChoosed(self.player_nick, self.referee, contrat or 'Passe', self.parent.host.profile)
92 92
93 def chooseContrat(self, xml_data): 93 def chooseContrat(self, xml_data):
94 """Called when the player as to select his contrat 94 """Called when the player as to select his contrat
95 @param xml_data: SàT xml representation of the form""" 95 @param xml_data: SàT xml representation of the form"""
96 raise NotImplementedError 96 raise NotImplementedError
97 97
98 def showCards(self, game_stage, cards, data): 98 def showCards(self, game_stage, cards, data):
99 """Display cards in the middle of the game (to show for e.g. chien ou poignée)""" 99 """Display cards in the middle of the game (to show for e.g. chien ou poignée)"""
100 self.to_show = [] 100 self.to_show = []
101 for suit, value in cards: 101 for suit, value in cards:
102 self.to_show.append(self.cards[suit, value]) 102 self.to_show.append(self.cards[suit, value])
109 """Called when we have to play :)""" 109 """Called when we have to play :)"""
110 if self.state == "chien": 110 if self.state == "chien":
111 self.to_show = [] 111 self.to_show = []
112 self.state = "play" 112 self.state = "play"
113 self.__fakePlay() 113 self.__fakePlay()
114 114
115 def __fakePlay(self): 115 def __fakePlay(self):
116 """Convenience method for stupid autoplay 116 """Convenience method for stupid autoplay
117 /!\ don't forgot to comment any interactive dialog for invalid card""" 117 /!\ don't forgot to comment any interactive dialog for invalid card"""
118 if self._autoplay == None: 118 if self._autoplay == None:
119 return 119 return
129 """Called at the end of a game 129 """Called at the end of a game
130 @param xml_data: SàT xml representation of the scores 130 @param xml_data: SàT xml representation of the scores
131 @param winners: list of winners' nicks 131 @param winners: list of winners' nicks
132 @param loosers: list of loosers' nicks""" 132 @param loosers: list of loosers' nicks"""
133 raise NotImplementedError 133 raise NotImplementedError
134 134
135 def cardsPlayed(self, player, cards): 135 def cardsPlayed(self, player, cards):
136 """A card has been played by player""" 136 """A card has been played by player"""
137 if self.to_show: 137 if self.to_show:
138 self.to_show = [] 138 self.to_show = []
139 pl_cards = [] 139 pl_cards = []
141 for pl in self.played: 141 for pl in self.played:
142 self.played[pl] = None 142 self.played[pl] = None
143 for suit, value in cards: 143 for suit, value in cards:
144 pl_cards.append(self.cards[suit, value]) 144 pl_cards.append(self.cards[suit, value])
145 self.played[player] = pl_cards[0] 145 self.played[player] = pl_cards[0]
146 146
147 def invalidCards(self, phase, played_cards, invalid_cards): 147 def invalidCards(self, phase, played_cards, invalid_cards):
148 """Invalid cards have been played 148 """Invalid cards have been played
149 @param phase: phase of the game 149 @param phase: phase of the game
150 @param played_cards: all the cards played 150 @param played_cards: all the cards played
151 @param invalid_cards: cards which are invalid""" 151 @param invalid_cards: cards which are invalid"""
154 self.state = "play" 154 self.state = "play"
155 elif phase == "ecart": 155 elif phase == "ecart":
156 self.state = "ecart" 156 self.state = "ecart"
157 else: 157 else:
158 error ('INTERNAL ERROR: unmanaged game phase') 158 error ('INTERNAL ERROR: unmanaged game phase')
159 159
160 for suit, value in played_cards: 160 for suit, value in played_cards:
161 self.hand.append(self.cards[suit, value]) 161 self.hand.append(self.cards[suit, value])
162 162
163 self.hand.sort() 163 self.hand.sort()
164 self.__fakePlay() 164 self.__fakePlay()
165 165