Mercurial > libervia-web
comparison browser_side/card_game.py @ 42:71a9cc9b9d57
Browser side: Tarot game
- draw game managed
- we can now play continuously \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 23 May 2011 00:45:19 +0200 |
parents | 7782a786b2f0 |
children | d5266c41ca24 |
comparison
equal
deleted
inserted
replaced
41:7782a786b2f0 | 42:71a9cc9b9d57 |
---|---|
123 ClickHandler.__init__(self) | 123 ClickHandler.__init__(self) |
124 self._parent = parent | 124 self._parent = parent |
125 self._autoplay = None #XXX: use 0 to activate fake play, None else | 125 self._autoplay = None #XXX: use 0 to activate fake play, None else |
126 self.referee = referee | 126 self.referee = referee |
127 self.players = players | 127 self.players = players |
128 self.played = {} | |
129 for player in players: | |
130 self.played[player] = None | |
131 self.player_nick = player_nick | 128 self.player_nick = player_nick |
132 self.bottom_nick = self.player_nick | 129 self.bottom_nick = self.player_nick |
133 idx = self.players.index(self.player_nick) | 130 idx = self.players.index(self.player_nick) |
134 idx = (idx + 1) % len(self.players) | 131 idx = (idx + 1) % len(self.players) |
135 self.right_nick = self.players[idx] | 132 self.right_nick = self.players[idx] |
210 self.setCellWidth(self.center_panel, '100%') | 207 self.setCellWidth(self.center_panel, '100%') |
211 self.setCellHeight(self.center_panel, '100%') | 208 self.setCellHeight(self.center_panel, '100%') |
212 self.setCellVerticalAlignment(self.center_panel, HasAlignment.ALIGN_MIDDLE) | 209 self.setCellVerticalAlignment(self.center_panel, HasAlignment.ALIGN_MIDDLE) |
213 self.setCellHorizontalAlignment(self.center_panel, HasAlignment.ALIGN_CENTER) | 210 self.setCellHorizontalAlignment(self.center_panel, HasAlignment.ALIGN_CENTER) |
214 | 211 |
215 | |
216 """for side in zip(['left', 'top', 'right'], | |
217 [DockPanel.WEST, DockPanel.NORTH, DockPanel.EAST]): | |
218 _nick = getattr(self, "%s_nick" % side[0]) | |
219 _label = Label(_nick) | |
220 _label.setStyleName('cardGamePlayerNick') | |
221 self.add(_label, side[1])""" | |
222 self.loadCards() | 212 self.loadCards() |
223 self.mouse_over_card = None #contain the card to highlight | 213 self.mouse_over_card = None #contain the card to highlight |
224 self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards | 214 self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards |
225 self.addClickListener(self) | 215 self.addClickListener(self) |
226 | 216 |
401 | 391 |
402 def tarotGameScore(self, xml_data, winners, loosers): | 392 def tarotGameScore(self, xml_data, winners, loosers): |
403 """Show score at this end of a round""" | 393 """Show score at this end of a round""" |
404 ###XXX: we cheat here as XMLUI is not implemented yet | 394 ###XXX: we cheat here as XMLUI is not implemented yet |
405 #TODO: usr XMLUI | 395 #TODO: usr XMLUI |
406 if self.player_nick in winners: | 396 def _new_game(): |
407 title = "You <b>win</b> !" | 397 self.selected.clear() |
398 del self.hand[:] | |
399 del self.to_show[:] | |
400 self.state = None | |
401 #empty hand | |
402 self.updateHand() | |
403 #nothing on the table | |
404 self.updateToShow() | |
405 for pos in ['top','left','bottom','right']: | |
406 getattr(self, "inner_%s" % pos).setWidget(None) | |
407 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) | |
408 | |
409 if not winners and not loosers: | |
410 title = "Draw game" | |
408 else: | 411 else: |
409 title = "You <b>loose</b> :(" | 412 if self.player_nick in winners: |
413 title = "You <b>win</b> !" | |
414 else: | |
415 title = "You <b>loose</b> :(" | |
410 body = re.sub(r'<.*?>',lambda x:'<br />' if '/elem' in x.group(0) else '', xml_data) #Q&D conversion to simple HTML text | 416 body = re.sub(r'<.*?>',lambda x:'<br />' if '/elem' in x.group(0) else '', xml_data) #Q&D conversion to simple HTML text |
411 SimpleDialog(title, body).show() | 417 SimpleDialog(title, body, _new_game).show() |