Mercurial > libervia-backend
annotate sat_frontends/primitivus/game_tarot.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | 9d0df638c8b4 |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
4 # Primitivus: a SAT frontend |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
10 # (at your option) any later version. |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
15 # GNU Affero General Public License for more details. |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 import urwid |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
22 from urwid_satext import sat_widgets |
719
56aa0e98c92e
frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents:
687
diff
changeset
|
23 from sat_frontends.tools.games import TarotCard |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
24 from sat_frontends.quick_frontend.quick_game_tarot import QuickTarotGame |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
911
diff
changeset
|
25 from sat_frontends.primitivus import xmlui |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
26 from sat_frontends.primitivus.keys import action_key_map as a_key |
150 | 27 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
28 |
150 | 29 class CardDisplayer(urwid.Text): |
30 """Show a card""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
31 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 signals = ["click"] |
150 | 33 |
34 def __init__(self, card): | |
35 self.__selected = False | |
36 self.card = card | |
37 urwid.Text.__init__(self, card.getAttrText()) | |
38 | |
39 def selectable(self): | |
40 return True | |
41 | |
42 def keypress(self, size, key): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 if key == a_key["CARD_SELECT"]: |
150 | 44 self.select(not self.__selected) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
45 self._emit("click") |
150 | 46 return key |
47 | |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
48 def mouse_event(self, size, event, button, x, y, focus): |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
49 if urwid.is_mouse_event(event) and button == 1: |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
50 self.select(not self.__selected) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 self._emit("click") |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
52 return True |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
53 |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
153
diff
changeset
|
54 return False |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
55 |
150 | 56 def select(self, state=True): |
57 self.__selected = state | |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
58 attr, txt = self.card.getAttrText() |
150 | 59 if self.__selected: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 attr += "_selected" |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
61 self.set_text((attr, txt)) |
150 | 62 self._invalidate() |
63 | |
64 def isSelected(self): | |
65 return self.__selected | |
66 | |
67 def getCard(self): | |
68 return self.card | |
69 | |
70 def render(self, size, focus=False): | |
71 canvas = urwid.CompositeCanvas(urwid.Text.render(self, size, focus)) | |
72 if focus: | |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
73 canvas.set_cursor((0, 0)) |
150 | 74 return canvas |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
76 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 class Hand(urwid.WidgetWrap): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 """Used to display several cards, and manage a hand""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 signals = ["click"] |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
82 def __init__(self, hand=[], selectable=False, on_click=None, user_data=None): |
150 | 83 """@param hand: list of Card""" |
84 self.__selectable = selectable | |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
85 self.columns = urwid.Columns([], dividechars=1) |
150 | 86 if on_click: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 urwid.connect_signal(self, "click", on_click, user_data) |
150 | 88 if hand: |
89 self.update(hand) | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 urwid.WidgetWrap.__init__(self, self.columns) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
150 | 92 def selectable(self): |
93 return self.__selectable | |
94 | |
95 def keypress(self, size, key): | |
96 | |
97 if CardDisplayer in [wid.__class__ for wid in self.columns.widget_list]: | |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
98 return self.columns.keypress(size, key) |
150 | 99 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 # No card displayed, we still have to manage the clicks |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 if key == a_key["CARD_SELECT"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 self._emit("click", None) |
150 | 103 return key |
104 | |
105 def getSelected(self): | |
106 """Return a list of selected cards""" | |
107 _selected = [] | |
108 for wid in self.columns.widget_list: | |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
150
diff
changeset
|
109 if isinstance(wid, CardDisplayer) and wid.isSelected(): |
150 | 110 _selected.append(wid.getCard()) |
111 return _selected | |
112 | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 def update(self, hand): |
150 | 114 """Update the hand displayed in this widget |
115 @param hand: list of Card""" | |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
116 try: |
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
117 del self.columns.widget_list[:] |
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
118 del self.columns.column_types[:] |
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
119 except IndexError: |
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
686
diff
changeset
|
120 pass |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 self.columns.contents.append((urwid.Text(""), ("weight", 1, False))) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 for card in hand: |
150 | 123 widget = CardDisplayer(card) |
124 self.columns.widget_list.append(widget) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 self.columns.column_types.append(("fixed", 3)) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 urwid.connect_signal(widget, "click", self.__onClick) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
127 self.columns.contents.append((urwid.Text(""), ("weight", 1, False))) |
911
b12706d164d7
primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents:
878
diff
changeset
|
128 self.columns.focus_position = 1 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
130 def __onClick(self, card_wid): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 self._emit("click", card_wid) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
133 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 class Card(TarotCard): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 """This class is used to represent a card, logically |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 and give a text representation with attributes""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
138 SIZE = 3 # size of a displayed card |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 def __init__(self, suit, value): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 """@param file: path of the PNG file""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 TarotCard.__init__(self, (suit, value)) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 def getAttrText(self): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 """return text representation of the card with attributes""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 try: |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 value = "%02i" % int(self.value) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 except ValueError: |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
149 value = self.value[0].upper() + self.value[1] |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 if self.suit == "atout": |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 if self.value == "excuse": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 suit = "c" |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
154 suit = "A" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 color = "neutral" |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 elif self.suit == "pique": |
3028 | 157 suit = "♠" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 color = "black" |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 elif self.suit == "trefle": |
3028 | 160 suit = "♣" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 color = "black" |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 elif self.suit == "coeur": |
3028 | 163 suit = "♥" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
164 color = "red" |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 elif self.suit == "carreau": |
3028 | 166 suit = "♦" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 color = "red" |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if self.bout: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 color = "special" |
3028 | 170 return ("card_%s" % color, "%s%s" % (value, suit)) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
150 | 172 def getWidget(self): |
173 """Return a widget representing the card""" | |
174 return CardDisplayer(self) | |
175 | |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
176 |
150 | 177 class Table(urwid.FlowWidget): |
178 """Represent the cards currently on the table""" | |
179 | |
180 def __init__(self): | |
181 self.top = self.left = self.bottom = self.right = None | |
182 | |
183 def putCard(self, location, card): | |
184 """Put a card on the table | |
185 @param location: where to put the card (top, left, bottom or right) | |
186 @param card: Card to play or None""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 assert location in ["top", "left", "bottom", "right"] |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
188 assert isinstance(card, Card) or card == None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 if [getattr(self, place) for place in ["top", "left", "bottom", "right"]].count( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
190 None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 ) == 0: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
192 # If the table is full of card, we remove them |
150 | 193 self.top = self.left = self.bottom = self.right = None |
194 setattr(self, location, card) | |
195 self._invalidate() | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
196 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
197 def rows(self, size, focus=False): |
150 | 198 return self.display_widget(size, focus).rows(size, focus) |
199 | |
200 def render(self, size, focus=False): | |
201 return self.display_widget(size, focus).render(size, focus) | |
202 | |
203 def display_widget(self, size, focus): | |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
204 cards = {} |
150 | 205 max_col, = size |
206 separator = " - " | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 margin = max((max_col - Card.SIZE) / 2, 0) * " " |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 margin_center = max((max_col - Card.SIZE * 2 - len(separator)) / 2, 0) * " " |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
209 for location in ["top", "left", "bottom", "right"]: |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
210 card = getattr(self, location) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
211 cards[location] = card.getAttrText() if card else Card.SIZE * " " |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
212 render_wid = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
213 urwid.Text([margin, cards["top"]]), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
214 urwid.Text([margin_center, cards["left"], separator, cards["right"]]), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
215 urwid.Text([margin, cards["bottom"]]), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 ] |
150 | 217 return urwid.Pile(render_wid) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
218 |
150 | 219 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
220 class TarotGame(QuickTarotGame, urwid.WidgetWrap): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 """Widget for card games""" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
222 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
223 def __init__(self, parent, referee, players): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
224 QuickTarotGame.__init__(self, parent, referee, players) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 self.loadCards() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 self.top = urwid.Pile([urwid.Padding(urwid.Text(self.top_nick), "center")]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 # self.parent.host.debug() |
150 | 228 self.table = Table() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 self.center = urwid.Columns( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
230 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 ("fixed", len(self.left_nick), urwid.Filler(urwid.Text(self.left_nick))), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 urwid.Filler(self.table), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 "fixed", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
235 len(self.right_nick), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 urwid.Filler(urwid.Text(self.right_nick)), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
238 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 ) |
150 | 240 """urwid.Pile([urwid.Padding(self.top_card_wid,'center'), |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 urwid.Columns([('fixed',len(self.left_nick),urwid.Text(self.left_nick)), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 urwid.Padding(self.center_cards_wid,'center'), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 ('fixed',len(self.right_nick),urwid.Text(self.right_nick)) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 ]), |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 urwid.Padding(self.bottom_card_wid,'center') |
150 | 246 ])""" |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
247 self.hand_wid = Hand(selectable=True, on_click=self.onClick) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
248 self.main_frame = urwid.Frame( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 self.center, header=self.top, footer=self.hand_wid, focus_part="footer" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
250 ) |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
251 urwid.WidgetWrap.__init__(self, self.main_frame) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 self.parent.host.bridge.tarotGameReady( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
253 self.player_nick, referee, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
254 ) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 def loadCards(self): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 """Load all the cards in memory""" |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
258 QuickTarotGame.loadCards(self) |
3028 | 259 for value in list(map(str, list(range(1, 22)))) + ["excuse"]: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 card = Card("atout", value) |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
261 self.cards[card.suit, card.value] = card |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 self.deck.append(card) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 for suit in ["pique", "coeur", "carreau", "trefle"]: |
3028 | 264 for value in list(map(str, list(range(1, 11)))) + ["valet", "cavalier", "dame", "roi"]: |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
265 card = Card(suit, value) |
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
266 self.cards[card.suit, card.value] = card |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 self.deck.append(card) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
269 def tarotGameNewHandler(self, hand): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 """Start a new game, with given hand""" |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
271 if hand is []: # reset the display after the scores have been showed |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
272 self.resetRound() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 for location in ["top", "left", "bottom", "right"]: |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
274 self.table.putCard(location, None) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
275 self.parent.host.redraw() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 self.parent.host.bridge.tarotGameReady( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 self.player_nick, self.referee, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 ) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
279 return |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
280 QuickTarotGame.tarotGameNewHandler(self, hand) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 self.hand_wid.update(self.hand) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 self.parent.host.redraw() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
283 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
284 def tarotGameChooseContratHandler(self, xml_data): |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
285 """Called when the player has to select his contrat |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 @param xml_data: SàT xml representation of the form""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
287 form = xmlui.create( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
288 self.parent.host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
289 xml_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
290 title=_("Please choose your contrat"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 flags=["NO_CANCEL"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 profile=self.parent.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 form.show(valign="top") |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
296 def tarotGameShowCardsHandler(self, game_stage, cards, data): |
150 | 297 """Display cards in the middle of the game (to show for e.g. chien ou poignée)""" |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
298 QuickTarotGame.tarotGameShowCardsHandler(self, game_stage, cards, data) |
150 | 299 self.center.widget_list[1] = urwid.Filler(Hand(self.to_show)) |
300 self.parent.host.redraw() | |
301 | |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
302 def tarotGameYourTurnHandler(self): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
303 QuickTarotGame.tarotGameYourTurnHandler(self) |
150 | 304 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
305 def tarotGameScoreHandler(self, xml_data, winners, loosers): |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
306 """Called when the round is over, display the scores |
150 | 307 @param xml_data: SàT xml representation of the form""" |
328 | 308 if not winners and not loosers: |
309 title = _("Draw game") | |
310 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 title = _("You win \o/") if self.player_nick in winners else _("You loose :(") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
312 form = xmlui.create( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
313 self.parent.host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
314 xml_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
315 title=title, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
316 flags=["NO_CANCEL"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
317 profile=self.parent.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
318 ) |
162 | 319 form.show() |
150 | 320 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
321 def tarotGameInvalidCardsHandler(self, phase, played_cards, invalid_cards): |
150 | 322 """Invalid cards have been played |
323 @param phase: phase of the game | |
324 @param played_cards: all the cards played | |
325 @param invalid_cards: cards which are invalid""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
326 QuickTarotGame.tarotGameInvalidCardsHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
327 self, phase, played_cards, invalid_cards |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
328 ) |
150 | 329 self.hand_wid.update(self.hand) |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
330 if self._autoplay == None: # No dialog if there is autoplay |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 self.parent.host.barNotify(_("Cards played are invalid !")) |
150 | 332 self.parent.host.redraw() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
333 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
334 def tarotGameCardsPlayedHandler(self, player, cards): |
150 | 335 """A card has been played by player""" |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1158
diff
changeset
|
336 QuickTarotGame.tarotGameCardsPlayedHandler(self, player, cards) |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
337 self.table.putCard(self.getPlayerLocation(player), self.played[player]) |
323
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
338 self._checkState() |
150 | 339 self.parent.host.redraw() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
340 |
323
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
341 def _checkState(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
342 if isinstance( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
343 self.center.widget_list[1].original_widget, Hand |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
344 ): # if we have a hand displayed |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
345 self.center.widget_list[1] = urwid.Filler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
346 self.table |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
347 ) # we show again the table |
150 | 348 if self.state == "chien": |
349 self.to_show = [] | |
350 self.state = "wait" | |
351 elif self.state == "wait_for_ecart": | |
352 self.state = "ecart" | |
353 self.hand.extend(self.to_show) | |
354 self.hand.sort() | |
355 self.to_show = [] | |
356 self.hand_wid.update(self.hand) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
357 |
323
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
358 ##EVENTS## |
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
359 def onClick(self, hand, card_wid): |
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
360 """Called when user do an action on the hand""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
361 if not self.state in ["play", "ecart", "wait_for_ecart"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
362 # it's not our turn, we ignore the click |
323
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
363 card_wid.select(False) |
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
364 return |
7bc1b3401ecb
primitivus: fixed state state change in tarot game
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
365 self._checkState() |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
366 if self.state == "ecart": |
150 | 367 if len(self.hand_wid.getSelected()) == 6: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
368 pop_up_widget = sat_widgets.ConfirmDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
369 _("Do you put these cards in chien ?"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
370 yes_cb=self.onEcartDone, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
371 no_cb=self.parent.host.removePopUp, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
372 ) |
150 | 373 self.parent.host.showPopUp(pop_up_widget) |
374 elif self.state == "play": | |
375 card = card_wid.getCard() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
376 self.parent.host.bridge.tarotGamePlayCards( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
377 self.player_nick, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
378 self.referee, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
379 [(card.suit, card.value)], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
380 self.parent.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
381 ) |
150 | 382 self.hand.remove(card) |
383 self.hand_wid.update(self.hand) | |
384 self.state = "wait" | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 |
686
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
386 def onEcartDone(self, button): |
ae95b0327412
plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
387 """Called when player has finished his écart""" |
150 | 388 ecart = [] |
389 for card in self.hand_wid.getSelected(): | |
390 ecart.append((card.suit, card.value)) | |
391 self.hand.remove(card) | |
392 self.hand_wid.update(self.hand) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
393 self.parent.host.bridge.tarotGamePlayCards( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
394 self.player_nick, self.referee, ecart, self.parent.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
395 ) |
150 | 396 self.state = "wait" |
397 self.parent.host.removePopUp() |