comparison frontends/wix/card_game.py @ 93:2f87651a5ad8

Tarot game: basic trick - plugin xep-0045: new method getRoomNick - plugin tarot: basic trick - wix: played card are shown in CardPanel
author Goffi <goffi@goffi.org>
date Sun, 30 May 2010 15:33:08 +0930
parents 2503de7fb4c7
children 1eb5ccead43c
comparison
equal deleted inserted replaced
92:2503de7fb4c7 93:2f87651a5ad8
85 def __init__(self, parent, referee, players, player_nick): 85 def __init__(self, parent, referee, players, player_nick):
86 wx.Panel.__init__(self, parent) 86 wx.Panel.__init__(self, parent)
87 self.parent = parent 87 self.parent = parent
88 self.referee = referee 88 self.referee = referee
89 self.players = players 89 self.players = players
90 self.played = {}
91 for player in players:
92 self.played[player] = None
90 self.player_nick = player_nick 93 self.player_nick = player_nick
91 self.bottom_nick = self.player_nick 94 self.bottom_nick = self.player_nick
92 idx = self.players.index(self.player_nick) 95 idx = self.players.index(self.player_nick)
93 idx = (idx + 1) % len(self.players) 96 idx = (idx + 1) % len(self.players)
94 self.right_nick = self.players[idx] 97 self.right_nick = self.players[idx]
95 idx = (idx + 1) % len(self.players) 98 idx = (idx + 1) % len(self.players)
96 self.top_nick = self.players[idx] 99 self.top_nick = self.players[idx]
97 idx = (idx + 1) % len(self.players) 100 idx = (idx + 1) % len(self.players)
98 self.left_nick = self.players[idx] 101 self.left_nick = self.players[idx]
102 self.bottom_nick = player_nick
99 self.SetMinSize(wx.Size(MIN_WIDTH, MIN_HEIGHT)) 103 self.SetMinSize(wx.Size(MIN_WIDTH, MIN_HEIGHT))
100 self.load_cards("/home/goffi/dev/divers/images/cards/") 104 self.load_cards("/home/goffi/dev/divers/images/cards/")
101 self.mouse_over_card = None #contain the card to highlight 105 self.mouse_over_card = None #contain the card to highlight
102 self.selected = [] #Card choosed by the player (e.g. during ecart) 106 self.selected = [] #Card choosed by the player (e.g. during ecart)
103 self.hand_size = 13 #number of cards in a hand 107 self.hand_size = 13 #number of cards in a hand
167 171
168 def MyTurn(self): 172 def MyTurn(self):
169 """Called when we have to play :)""" 173 """Called when we have to play :)"""
170 if self.state == "chien": 174 if self.state == "chien":
171 self.to_show = [] 175 self.to_show = []
172 self.state="play" 176 self.state = "play"
177
178 def cardsPlayed(self, player, cards):
179 """A card has been played by player"""
180 if self.to_show:
181 self.to_show = []
182 pl_cards = []
183 if self.played[player] != None: #gof: à supprimer
184 for pl in self.played:
185 self.played[pl] = None
186 for suit, value in cards:
187 pl_cards.append(self.cards[suit, value])
188 self.played[player] = pl_cards[0]
189 self.Refresh()
190
173 191
174 def _is_on_hand(self, pos_x, pos_y): 192 def _is_on_hand(self, pos_x, pos_y):
175 """Return True if the coordinate are on the hand cards""" 193 """Return True if the coordinate are on the hand cards"""
176 if pos_x > self.orig_x and pos_y > self.orig_y \ 194 if pos_x > self.orig_x and pos_y > self.orig_y \
177 and pos_x < self.orig_x + (len(self.hand)+1) * self.visible_size \ 195 and pos_x < self.orig_x + (len(self.hand)+1) * self.visible_size \
202 top_x = (max_x - top_width) / 2 220 top_x = (max_x - top_width) / 2
203 top_y = border 221 top_y = border
204 dc.DrawText(self.right_nick, right_x, right_y) 222 dc.DrawText(self.right_nick, right_x, right_y)
205 dc.DrawText(self.top_nick, top_x, top_y) 223 dc.DrawText(self.top_nick, top_x, top_y)
206 dc.DrawText(self.left_nick, left_x, left_y) 224 dc.DrawText(self.left_nick, left_x, left_y)
225
226 #We draw the played cards:
227 center_y = 200 #ordinate used as center point
228 left_x = (max_x - CARD_WIDTH)/2 - CARD_WIDTH - 5
229 right_x = (max_x/2) + (CARD_WIDTH/2) + 5
230 left_y = right_y = center_y - CARD_HEIGHT/2
231 top_x = bottom_x = (max_x - CARD_WIDTH)/2
232 top_y = center_y - CARD_HEIGHT - 5
233 bottom_y = center_y + 5
234 for side in ['left', 'top', 'right', 'bottom']:
235 card = self.played[getattr(self, side+'_nick')]
236 if card != None:
237 card.draw(dc,locals()[side+'_x'], locals()[side+'_y'])
207 238
208 x=self.orig_x 239 x=self.orig_x
209 for card in self.hand: 240 for card in self.hand:
210 if (self.state == "play" or self.state == "ecart") and card == self.mouse_over_card \ 241 if (self.state == "play" or self.state == "ecart") and card == self.mouse_over_card \
211 or self.state == "ecart" and card in self.selected: 242 or self.state == "ecart" and card in self.selected:
276 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, ecart, profile_key = self.parent.host.profile) 307 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, ecart, profile_key = self.parent.host.profile)
277 self.state = "wait" 308 self.state = "wait"
278 309
279 self._recalc_ori() 310 self._recalc_ori()
280 self.Refresh() 311 self.Refresh()
312 if self.state == "play":
313 card = self.hand[idx]
314 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, [(card.suit, card.value)], profile_key = self.parent.host.profile)
315 del self.hand[idx]
316 self.state = "wait"
317 self._recalc_ori()
318 self.Refresh()
319
320