annotate browser_side/card_game.py @ 338:80016abf3ad3

server_side: raised default security_limit to 5
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 16:49:21 +0100
parents 9c6be29c714a
children 2067d6241927
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
165
9763dec220ed dates update
Goffi <goffi@goffi.org>
parents: 132
diff changeset
6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org>
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
22 import pyjd # this is dummy in pyjs
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.AbsolutePanel import AbsolutePanel
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
24 from pyjamas.ui.VerticalPanel import VerticalPanel
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
25 from pyjamas.ui.HorizontalPanel import HorizontalPanel
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
26 from pyjamas.ui.DockPanel import DockPanel
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
27 from pyjamas.ui.SimplePanel import SimplePanel
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
28 from pyjamas.ui.DialogBox import DialogBox
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
29 from pyjamas.ui.ListBox import ListBox
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.Image import Image
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
31 from pyjamas.ui.Label import Label
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
32 from pyjamas.ui.Button import Button
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
33 from pyjamas.ui.ClickListener import ClickHandler
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
34 from pyjamas.ui.MouseListener import MouseHandler
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
35 from pyjamas.ui import HasAlignment
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
36 from pyjamas import Window
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
37 from pyjamas import DOM
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 from pyjamas.ui.DragWidget import DragWidget, DragContainer
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 from jid import JID
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 42
diff changeset
41 from dialog import ConfirmDialog, InfoDialog
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 from tools import html_sanitize
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 from datetime import datetime
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 from time import time
276
aebb96bfa8d1 frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents: 275
diff changeset
45 from sat_frontends.tools.games import TarotCard
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
46 import re
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 CARD_WIDTH = 74
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 CARD_HEIGHT = 136
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
51 CARD_DELTA_Y = 30
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
52 MIN_WIDTH = 950 # Minimum size of the panel
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 MIN_HEIGHT = 500
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
55
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
56 class ContratChooser(DialogBox):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
57
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
58 def __init__(self, parent):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
59 """
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
60 Dialog asking to choose the contrat
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
61 """
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
62 self._parent = parent
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
63 DialogBox.__init__(self, modal=False, centered=True)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
64
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
65 content = VerticalPanel()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
66 content.setWidth('100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
67 self.contrats_list = ListBox()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
68 self.contrats_list.setVisibleItemCount(5)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
69 self.contrats_list.setWidth("100%")
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
70 self.contrats_list.setStyleName('contratsChooser')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
71 for contrat in ['Passe', 'Petite', 'Garde', 'Garde Sans', 'Garde Contre']:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
72 self.contrats_list.addItem(contrat)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
73 self.contrats_list.setSelectedIndex(0)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
74 content.add(self.contrats_list)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
75 button_panel = HorizontalPanel()
238
dec76d4536ad browser_side: set CSS margin: auto for all button panels
souliane <souliane@mailoo.org>
parents: 165
diff changeset
76 button_panel.addStyleName("marginAuto")
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
77 self.choose_button = Button("Choose", self.onChoose)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
78 button_panel.add(self.choose_button)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
79 content.add(button_panel)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
80 self.setHTML("Please select your contrat")
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
81 self.setWidget(content)
238
dec76d4536ad browser_side: set CSS margin: auto for all button panels
souliane <souliane@mailoo.org>
parents: 165
diff changeset
82
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 55
diff changeset
83 def onChoose(self, button):
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
84 self.hide()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
85 self._parent.contratSelected(self.contrats_list.getSelectedItemText()[0])
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
87
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
88 class CardWidget(TarotCard, Image, MouseHandler):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 """This class is used to represent a card, graphically and logically"""
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
91 def __init__(self, parent, file_):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 """@param file: path of the PNG file"""
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
93 self._parent = parent
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
94 Image.__init__(self, file_)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
95 root_name = file_[file_.rfind("/") + 1:-4]
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
96 suit, value = root_name.split('_')
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 TarotCard.__init__(self, (suit, value))
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
98 MouseHandler.__init__(self)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
99 self.addMouseListener(self)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
101 def onMouseEnter(self, sender):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
102 if self._parent.state == "ecart" or self._parent.state == "play":
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
103 DOM.setStyleAttribute(self.getElement(), "top", "0px")
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
105 def onMouseLeave(self, sender):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
106 if not self in self._parent.hand:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
107 return
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
108 if not self in list(self._parent.selected): # FIXME: Workaround pyjs bug, must report it
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
109 DOM.setStyleAttribute(self.getElement(), "top", "%dpx" % CARD_DELTA_Y)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
110
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
111 def onMouseUp(self, sender, x, y):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
112 if self._parent.state == "ecart":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
113 if self not in list(self._parent.selected):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
114 self._parent.addToSelection(self)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
115 else:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
116 self._parent.removeFromSelection(self)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
117 elif self._parent.state == "play":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
118 self._parent.playCard(self)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
119
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
120
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
121 class CardPanel(DockPanel, ClickHandler):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122
275
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 248
diff changeset
123 def __init__(self, parent, referee, player_nick, players):
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
124 DockPanel.__init__(self)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
125 ClickHandler.__init__(self)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self._parent = parent
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
127 self._autoplay = None # XXX: use 0 to activate fake play, None else
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 self.referee = referee
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 self.players = players
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 self.player_nick = player_nick
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.bottom_nick = self.player_nick
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 idx = self.players.index(self.player_nick)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.right_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 self.top_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 self.left_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 self.bottom_nick = player_nick
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
140 self.selected = set() # Card choosed by the player (e.g. during ecart)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
141 self.hand_size = 13 # number of cards in a hand
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self.hand = []
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 self.to_show = []
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 self.state = None
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
145 self.setSize("%dpx" % MIN_WIDTH, "%dpx" % MIN_HEIGHT)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 self.setStyleName("cardPanel")
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
147
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
148 # Now we set up the layout
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
149 _label = Label(self.top_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
150 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
151 self.add(_label, DockPanel.NORTH)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
152 self.setCellWidth(_label, '100%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
153 self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_CENTER)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
154
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
155 self.hand_panel = AbsolutePanel()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
156 self.add(self.hand_panel, DockPanel.SOUTH)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
157 self.setCellWidth(self.hand_panel, '100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
158 self.setCellHorizontalAlignment(self.hand_panel, HasAlignment.ALIGN_CENTER)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
159
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
160 _label = Label(self.left_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
161 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
162 self.add(_label, DockPanel.WEST)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
163 self.setCellHeight(_label, '100%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
164 self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
165
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
166 _label = Label(self.right_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
167 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
168 self.add(_label, DockPanel.EAST)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
169 self.setCellHeight(_label, '100%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
170 self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_RIGHT)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
171 self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
172
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
173 self.center_panel = DockPanel()
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
174 self.inner_left = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
175 self.inner_left.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
176 self.center_panel.add(self.inner_left, DockPanel.WEST)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
177 self.center_panel.setCellHeight(self.inner_left, '100%')
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
178 self.center_panel.setCellHorizontalAlignment(self.inner_left, HasAlignment.ALIGN_RIGHT)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
179 self.center_panel.setCellVerticalAlignment(self.inner_left, HasAlignment.ALIGN_MIDDLE)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
180
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
181 self.inner_right = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
182 self.inner_right.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
183 self.center_panel.add(self.inner_right, DockPanel.EAST)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
184 self.center_panel.setCellHeight(self.inner_right, '100%')
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
185 self.center_panel.setCellVerticalAlignment(self.inner_right, HasAlignment.ALIGN_MIDDLE)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
186
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
187 self.inner_top = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
188 self.inner_top.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
189 self.center_panel.add(self.inner_top, DockPanel.NORTH)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
190 self.center_panel.setCellHorizontalAlignment(self.inner_top, HasAlignment.ALIGN_CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
191 self.center_panel.setCellVerticalAlignment(self.inner_top, HasAlignment.ALIGN_BOTTOM)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
192
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
193 self.inner_bottom = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
194 self.inner_bottom.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
195 self.center_panel.add(self.inner_bottom, DockPanel.SOUTH)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
196 self.center_panel.setCellHorizontalAlignment(self.inner_bottom, HasAlignment.ALIGN_CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
197 self.center_panel.setCellVerticalAlignment(self.inner_bottom, HasAlignment.ALIGN_TOP)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
198
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
199 self.inner_center = SimplePanel()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
200 self.center_panel.add(self.inner_center, DockPanel.CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
201 self.center_panel.setCellHorizontalAlignment(self.inner_center, HasAlignment.ALIGN_CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
202 self.center_panel.setCellVerticalAlignment(self.inner_center, HasAlignment.ALIGN_MIDDLE)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
203
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
204 self.add(self.center_panel, DockPanel.CENTER)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
205 self.setCellWidth(self.center_panel, '100%')
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
206 self.setCellHeight(self.center_panel, '100%')
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
207 self.setCellVerticalAlignment(self.center_panel, HasAlignment.ALIGN_MIDDLE)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
208 self.setCellHorizontalAlignment(self.center_panel, HasAlignment.ALIGN_CENTER)
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
209
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210 self.loadCards()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
211 self.mouse_over_card = None # contain the card to highlight
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
212 self.visible_size = CARD_WIDTH / 2 # number of pixels visible for cards
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
213 self.addClickListener(self)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214
77
975e6be24e11 media paths update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
215 def loadCards(self):
975e6be24e11 media paths update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
216 """Load all the cards in memory"""
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
217 def _getTarotCardsPathsCb(paths):
77
975e6be24e11 media paths update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
218 print "_getTarotCardsPathsCb"
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
219 for file_ in paths:
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
220 print "path:", file_
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
221 card = CardWidget(self, file_)
77
975e6be24e11 media paths update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
222 print "card:", card
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
223 self.cards[(card.suit, card.value)] = card
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
224 self.deck.append(card)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
225 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
226 self.cards = {}
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
227 self.deck = []
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
228 self.cards["atout"] = {} # As Tarot is a french game, it's more handy & logical to keep french names
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
229 self.cards["pique"] = {} # spade
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
230 self.cards["coeur"] = {} # heart
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
231 self.cards["carreau"] = {} # diamond
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
232 self.cards["trefle"] = {} # club
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
233 self._parent.host.bridge.call('getTarotCardsPaths', _getTarotCardsPathsCb)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
234
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
235 def onClick(self, sender):
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
236 if self.state == "chien":
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
237 self.to_show = []
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
238 self.state = "wait"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
239 self.updateToShow()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
240 elif self.state == "wait_for_ecart":
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
241 self.state = "ecart"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
242 self.hand.extend(self.to_show)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
243 self.hand.sort()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
244 self.to_show = []
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
245 self.updateToShow()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
246 self.updateHand()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
247
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
248 def tarotGameNew(self, hand):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
249 """Start a new game, with given hand"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
250 for suit, value in hand:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
251 self.hand.append(self.cards[(suit, value)])
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
252 self.hand.sort()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
253 self.state = "init"
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
254 self.updateHand()
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
255
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
256 def updateHand(self):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
257 """Show the cards in the hand in the hand_panel (SOUTH panel)"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
258 self.hand_panel.clear()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
259 self.hand_panel.setSize("%dpx" % (self.visible_size * (len(self.hand) + 1)), "%dpx" % (CARD_HEIGHT + CARD_DELTA_Y + 10))
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
260 x_pos = 0
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
261 y_pos = CARD_DELTA_Y
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
262 for card in self.hand:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
263 self.hand_panel.add(card, x_pos, y_pos)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
264 x_pos += self.visible_size
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
265
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
266 def updateToShow(self):
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
267 """Show cards in the center panel"""
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
268 if not self.to_show:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
269 _widget = self.inner_center.getWidget()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
270 if _widget:
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
271 self.inner_center.remove(_widget)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
272 return
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
273 panel = AbsolutePanel()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
274 panel.setSize("%dpx" % ((CARD_WIDTH + 5) * len(self.to_show) - 5), "%dpx" % (CARD_HEIGHT))
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
275 x_pos = 0
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
276 y_pos = 0
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
277 for card in self.to_show:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
278 panel.add(card, x_pos, y_pos)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
279 x_pos += CARD_WIDTH + 5
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
280 self.inner_center.setWidget(panel)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
281
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
282 def _ecartConfirm(self, confirm):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
283 if not confirm:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
284 return
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
285 ecart = []
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
286 for card in self.selected:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
287 ecart.append((card.suit, card.value))
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
288 self.hand.remove(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
289 self.selected.clear()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
290 self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, ecart)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
291 self.state = "wait"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
292 self.updateHand()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
293
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
294 def addToSelection(self, card):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
295 self.selected.add(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
296 if len(self.selected) == 6:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
297 ConfirmDialog(self._ecartConfirm, "Put these cards into chien ?").show()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
298
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
299 def tarotGameInvalidCards(self, phase, played_cards, invalid_cards):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
300 """Invalid cards have been played
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
301 @param phase: phase of the game
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
302 @param played_cards: all the cards played
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
303 @param invalid_cards: cards which are invalid"""
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
304
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
305 if phase == "play":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
306 self.state = "play"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
307 elif phase == "ecart":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
308 self.state = "ecart"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
309 else:
334
9c6be29c714a browser side: removed logging imports: it's not working correctly with pyjamas
Goffi <goffi@goffi.org>
parents: 276
diff changeset
310 print 'INTERNAL ERROR: unmanaged game phase'
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
311
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
312 for suit, value in played_cards:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
313 self.hand.append(self.cards[(suit, value)])
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
314
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
315 self.hand.sort()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
316 self.updateHand()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
317 Window.alert('Cards played are invalid !')
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
318
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
319 def removeFromSelection(self, card):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
320 self.selected.remove(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
321 if len(self.selected) == 6:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
322 ConfirmDialog(self._ecartConfirm, "Put these cards into chien ?").show()
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
323
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
324 def tarotGameChooseContrat(self, xml_data):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
325 """Called when the player as to select his contrat
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
326 @param xml_data: SàT xml representation of the form"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
327 #for the moment we cheat a little bit and make our own dialog box
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
328 #but XMLUI must be user ASAP, as in other frontends
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
329 contrat_chooser = ContratChooser(self)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
330 contrat_chooser.show()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
331
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
332 def contratSelected(self, contrat):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
333 """Must be called when the contrat is selected
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
334 @param contrat: one of the valid contrat value"""
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
335 self._parent.host.bridge.call('tarotGameContratChoosed', None, self.player_nick, self.referee, contrat or 'Passe')
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
336
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
337 def tarotGameShowCards(self, game_stage, cards, data):
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
338 """Display cards in the middle of the game (to show for e.g. chien ou poignée)"""
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
339 self.to_show = []
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
340 for suit, value in cards:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
341 self.to_show.append(self.cards[(suit, value)])
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
342 self.updateToShow()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
343 if game_stage == "chien" and data['attaquant'] == self.player_nick:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
344 self.state = "wait_for_ecart"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
345 else:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
346 self.state = "chien"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
347
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
348 def getPlayerLocation(self, nick):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
349 """return player location (top,bottom,left or right)"""
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
350 for location in ['top', 'left', 'bottom', 'right']:
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
351 if getattr(self, '%s_nick' % location) == nick:
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
352 return location
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
353 print ("ERROR: This line should not be reached")
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
354
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
355 def tarotGameCardsPlayed(self, player, cards):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
356 """A card has been played by player"""
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
357 if not len(cards):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
358 print ("WARNING: cards should not be empty")
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
359 return
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
360 if len(cards) > 1:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
361 print ("ERROR: can't manage several cards played")
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
362 if self.to_show:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
363 self.to_show = []
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
364 self.updateToShow()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
365 suit, value = cards[0]
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
366 player_pos = self.getPlayerLocation(player)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
367 player_panel = getattr(self, "inner_%s" % player_pos)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
368
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
369 if player_panel.getWidget() != None:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
370 #We have already cards on the table, we remove them
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
371 for pos in ['top', 'left', 'bottom', 'right']:
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
372 getattr(self, "inner_%s" % pos).setWidget(None)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
373
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
374 card = self.cards[(suit, value)]
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
375 DOM.setElemAttribute(card.getElement(), "style", "")
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
376 player_panel.setWidget(card)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
377
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
378 def tarotGameYourTurn(self):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
379 """Called when we have to play :)"""
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
380 if self.state == "chien":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
381 self.to_show = []
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
382 self.updateToShow()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
383 self.state = "play"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
384
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
385 def playCard(self, card):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
386 self.hand.remove(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
387 self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, [(card.suit, card.value)])
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
388 self.state = "wait"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
389 self.updateHand()
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
390
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
391 def tarotGameScore(self, xml_data, winners, loosers):
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
392 """Show score at this end of a round"""
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
393 ###XXX: we cheat here as XMLUI is not implemented yet
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
394 #TODO: usr XMLUI
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
395 def _new_game():
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
396 self.selected.clear()
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
397 del self.hand[:]
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
398 del self.to_show[:]
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
399 self.state = None
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
400 #empty hand
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
401 self.updateHand()
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
402 #nothing on the table
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
403 self.updateToShow()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
404 for pos in ['top', 'left', 'bottom', 'right']:
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
405 getattr(self, "inner_%s" % pos).setWidget(None)
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
406 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee)
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
407
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
408 if not winners and not loosers:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
409 title = "Draw game"
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
410 else:
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
411 if self.player_nick in winners:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
412 title = "You <b>win</b> !"
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
413 else:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
414 title = "You <b>loose</b> :("
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
415 body = re.sub(r'<.*?>', lambda x: '<br />' if '/elem' in x.group(0) else '', xml_data) # Q&D conversion to simple HTML text
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 42
diff changeset
416 InfoDialog(title, body, _new_game).show()