Mercurial > libervia-web
changeset 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 | a7ff1e6f1229 |
files | browser_side/card_game.py browser_side/dialog.py browser_side/register.py |
diffstat | 3 files changed, 26 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/card_game.py Sun May 22 17:56:59 2011 +0200 +++ b/browser_side/card_game.py Mon May 23 00:45:19 2011 +0200 @@ -125,9 +125,6 @@ self._autoplay = None #XXX: use 0 to activate fake play, None else self.referee = referee self.players = players - self.played = {} - for player in players: - self.played[player] = None self.player_nick = player_nick self.bottom_nick = self.player_nick idx = self.players.index(self.player_nick) @@ -212,13 +209,6 @@ self.setCellVerticalAlignment(self.center_panel, HasAlignment.ALIGN_MIDDLE) self.setCellHorizontalAlignment(self.center_panel, HasAlignment.ALIGN_CENTER) - - """for side in zip(['left', 'top', 'right'], - [DockPanel.WEST, DockPanel.NORTH, DockPanel.EAST]): - _nick = getattr(self, "%s_nick" % side[0]) - _label = Label(_nick) - _label.setStyleName('cardGamePlayerNick') - self.add(_label, side[1])""" self.loadCards() self.mouse_over_card = None #contain the card to highlight self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards @@ -403,9 +393,25 @@ """Show score at this end of a round""" ###XXX: we cheat here as XMLUI is not implemented yet #TODO: usr XMLUI - if self.player_nick in winners: - title = "You <b>win</b> !" + def _new_game(): + self.selected.clear() + del self.hand[:] + del self.to_show[:] + self.state = None + #empty hand + self.updateHand() + #nothing on the table + self.updateToShow() + for pos in ['top','left','bottom','right']: + getattr(self, "inner_%s" % pos).setWidget(None) + self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) + + if not winners and not loosers: + title = "Draw game" else: - title = "You <b>loose</b> :(" + if self.player_nick in winners: + title = "You <b>win</b> !" + else: + title = "You <b>loose</b> :(" body = re.sub(r'<.*?>',lambda x:'<br />' if '/elem' in x.group(0) else '', xml_data) #Q&D conversion to simple HTML text - SimpleDialog(title, body).show() + SimpleDialog(title, body, _new_game).show()
--- a/browser_side/dialog.py Sun May 22 17:56:59 2011 +0200 +++ b/browser_side/dialog.py Mon May 23 00:45:19 2011 +0200 @@ -112,11 +112,12 @@ class SimpleDialog(DialogBox): - def __init__(self, title, body): + def __init__(self, title, body, callback = None): """Simple notice dialog box @param title: HTML put in the header @param body: HTML put in the body""" DialogBox.__init__(self, centered=True) + self.callback = callback _body = VerticalPanel() _body.setSpacing(4) _body.add(HTML(body)) @@ -127,3 +128,5 @@ def onClose(self): self.hide() + if self.callback: + self.callback()
--- a/browser_side/register.py Sun May 22 17:56:59 2011 +0200 +++ b/browser_side/register.py Mon May 23 00:45:19 2011 +0200 @@ -48,8 +48,10 @@ vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) self.loginBox = TextBox() self.loginBox.setName("login") + self.loginBox.setText("goffi_local") self.passBox = PasswordTextBox() self.passBox.setName("password") + self.passBox.setText("toto") grid = Grid(2, 2) grid.setText(0,0,"Login:") grid.setWidget(0,1, self.loginBox)