annotate frontends/src/wix/card_game.py @ 1037:6e975c6b0faf

core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin: - the bridge method has been removed, now a plugin takes care of it with XMLUI callback system - TODO: xmpp.RegisteringAuthenticator still needs to be fixed
author souliane <souliane@mailoo.org>
date Fri, 16 May 2014 00:58:20 +0200
parents 5a6354ff468c
children e2e1e27a3680
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
4 # wix: a SAT frontend
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
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: 587
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: 587
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: 587
diff changeset
10 # (at your option) any later version.
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
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: 587
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: 587
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: 587
diff changeset
15 # GNU Affero General Public License for more details.
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
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: 587
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 719
diff changeset
21 from sat.core.i18n import _
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import wx
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import os.path, glob
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 878
diff changeset
24 from sat.core.log import getLogger
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 878
diff changeset
25 log = getLogger(__name__)
719
56aa0e98c92e frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents: 686
diff changeset
26 from sat_frontends.tools.games import TarotCard
227
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
27 from sat_frontends.quick_frontend.quick_card_game import QuickCardGame
533507bb4e32 distutils wix installation
Goffi <goffi@goffi.org>
parents: 225
diff changeset
28 from sat_frontends.wix.xmlui import XMLUI
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
30 CARD_WIDTH = 74
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
31 CARD_HEIGHT = 136
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 83
diff changeset
32 MIN_WIDTH = 950 #Minimum size of the panel
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 83
diff changeset
33 MIN_HEIGHT = 500
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
34
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 878
diff changeset
35
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
36 class WxCard(TarotCard):
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 """This class is used to represent a card, graphically and logically"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def __init__(self, file):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 """@param file: path of the PNG file"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.bitmap = wx.Image(file).ConvertToBitmap()
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 root_name = os.path.splitext(os.path.basename(file))[0]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
43 suit,value = root_name.split('_')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
44 TarotCard.__init__(self, (suit, value))
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 878
diff changeset
45 log.debug("Card: %s %s" % (suit, value)) #, self.bout
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def draw(self, dc, x, y):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 """Draw the card on the device context
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 @param dc: device context
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
50 @param x: abscissa
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 @param y: ordinate"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 dc.DrawBitmap(self.bitmap, x, y, True)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
686
ae95b0327412 plugin card_game: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 682
diff changeset
55 class CardPanel(QuickCardGame, wx.Panel):
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 """This class is used to display the cards"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
58 def __init__(self, parent, referee, players, player_nick):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
59 QuickCardGame.__init__(self, parent, referee, players, player_nick)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 wx.Panel.__init__(self, parent)
86
4b5f2d55b6ac wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents: 83
diff changeset
61 self.SetMinSize(wx.Size(MIN_WIDTH, MIN_HEIGHT))
366
0806a65a5fa9 wix: updated paths to use media_dir
Goffi <goffi@goffi.org>
parents: 328
diff changeset
62 self.loadCards(os.path.join(self.parent.host.media_dir, 'games/cards/tarot'))
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
63 self.mouse_over_card = None #contain the card to highlight
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
64 self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
65 self.hand = []
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
66 self.to_show = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
67 self.state = None
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.SetBackgroundColour(wx.GREEN)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
69 self.Bind(wx.EVT_SIZE, self.onResize)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.Bind(wx.EVT_PAINT, self.onPaint)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
71 self.Bind(wx.EVT_MOTION, self.onMouseMove)
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
72 self.Bind(wx.EVT_LEFT_UP, self.onMouseClick)
680
8281587eb528 primitivus, wix: fixed bridge methods calls for plugins radiocol and card game
souliane <souliane@mailoo.org>
parents: 609
diff changeset
73
8281587eb528 primitivus, wix: fixed bridge methods calls for plugins radiocol and card game
souliane <souliane@mailoo.org>
parents: 609
diff changeset
74 self.parent.host.bridge.tarotGameReady(player_nick, referee, self.parent.host.profile)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
76 def loadCards(self, dir):
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 """Load all the cards in memory
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 @param dir: directory where the PNG files are"""
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
79 QuickCardGame.loadCards(self)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 for file in glob.glob(dir+'/*_*.png'):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
81 card = WxCard(file)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
82 self.cards[card.suit, card.value]=card
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.deck.append(card)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
85 def newGame(self, hand):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
86 """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
87 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
88 self.resetRound()
36c6495d86b0 plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents: 811
diff changeset
89 self.Refresh()
36c6495d86b0 plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents: 811
diff changeset
90 self.parent.host.bridge.tarotGameReady(self.player_nick, self.referee, self.parent.host.profile)
36c6495d86b0 plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents: 811
diff changeset
91 return
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
92 QuickCardGame.newGame(self, hand)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
93 self._recalc_ori()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
94 self.Refresh()
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
95
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
96 def contratSelected(self, data):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
97 """Called when the contrat has been choosed
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
98 @param data: form result"""
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 878
diff changeset
99 log.debug (_("Contrat choosed"))
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
100 contrat = data[0][1]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
101 QuickCardGame.contratSelected(self, contrat)
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
102
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
103 def chooseContrat(self, xml_data):
878
36c6495d86b0 plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents: 811
diff changeset
104 """Called when the player has to select his contrat
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
105 @param xml_data: SàT xml representation of the form"""
878
36c6495d86b0 plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents: 811
diff changeset
106 XMLUI(self.parent.host, xml_data, title=_('Please choose your contrat'), flags=['NO_CANCEL'])
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
107
95
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
108 def showScores(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
109 """Called when the round is over, display the scores
95
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
110 @param xml_data: SàT xml representation of the form"""
328
809733b8d9be Tarot game:
Goffi <goffi@goffi.org>
parents: 228
diff changeset
111 if not winners and not loosers:
809733b8d9be Tarot game:
Goffi <goffi@goffi.org>
parents: 228
diff changeset
112 title = _("Draw game")
809733b8d9be Tarot game:
Goffi <goffi@goffi.org>
parents: 228
diff changeset
113 else:
809733b8d9be Tarot game:
Goffi <goffi@goffi.org>
parents: 228
diff changeset
114 title = _('You win \o/') if self.player_nick in winners else _('You loose :(')
878
36c6495d86b0 plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents: 811
diff changeset
115 XMLUI(self.parent.host, xml_data, title=title, flags=['NO_CANCEL'])
95
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
116
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
117 def cardsPlayed(self, player, cards):
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
118 """A card has been played by player"""
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
119 QuickCardGame.cardsPlayed(self, player, cards)
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
120 self.Refresh()
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
121
99
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
122 def invalidCards(self, phase, played_cards, invalid_cards):
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
123 """Invalid cards have been played
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
124 @param phase: phase of the game
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
125 @param played_cards: all the cards played
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
126 @param invalid_cards: cards which are invalid"""
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 141
diff changeset
127 QuickCardGame.invalidCards(self, phase, played_cards, invalid_cards)
99
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
128
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
129 self._recalc_ori()
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
130 self.Refresh()
162
ae50b53ff868 misc Tarot fixes
Goffi <goffi@goffi.org>
parents: 158
diff changeset
131 if self._autoplay==None: #No dialog if there is autoplay
ae50b53ff868 misc Tarot fixes
Goffi <goffi@goffi.org>
parents: 158
diff changeset
132 wx.MessageDialog(self, _("Cards played are invalid !"), _("Error"), wx.OK | wx.ICON_ERROR).ShowModal()
99
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
133
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
134 def _is_on_hand(self, pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
135 """Return True if the coordinate are on the hand cards"""
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
136 if pos_x > self.orig_x and pos_y > self.orig_y \
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
137 and pos_x < self.orig_x + (len(self.hand)+1) * self.visible_size \
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
138 and pos_y < self.end_y:
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
139 return True
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
140 return False
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
141
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
142 def onResize(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
143 self._recalc_ori()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
144
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
145 def _recalc_ori(self):
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
146 """Recalculate origins of hand, must be call when hand size change"""
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
147 self.orig_x = (self.GetSizeTuple()[0]-(len(self.hand)+1)*self.visible_size)/2 #where we start to draw cards
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
148 self.orig_y = self.GetSizeTuple()[1] - CARD_HEIGHT - 20
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
149 self.end_y = self.orig_y + CARD_HEIGHT
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
150
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 def onPaint(self, event):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 dc = wx.PaintDC(self)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
153
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
154 #We print the names to know who play where TODO: print avatars when available
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
155 max_x, max_y = self.GetSize()
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
156 border = 10 #border between nick and end of panel
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
157 right_y = left_y = 200
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
158 right_width, right_height = dc.GetTextExtent(self.right_nick)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
159 right_x = max_x - right_width - border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
160 left_x = border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
161 top_width, top_height = dc.GetTextExtent(self.top_nick)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
162 top_x = (max_x - top_width) / 2
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
163 top_y = border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
164 dc.DrawText(self.right_nick, right_x, right_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
165 dc.DrawText(self.top_nick, top_x, top_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
166 dc.DrawText(self.left_nick, left_x, left_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
167
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
168 #We draw the played cards:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
169 center_y = 200 #ordinate used as center point
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
170 left_x = (max_x - CARD_WIDTH)/2 - CARD_WIDTH - 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
171 right_x = (max_x/2) + (CARD_WIDTH/2) + 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
172 left_y = right_y = center_y - CARD_HEIGHT/2
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
173 top_x = bottom_x = (max_x - CARD_WIDTH)/2
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
174 top_y = center_y - CARD_HEIGHT - 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
175 bottom_y = center_y + 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
176 for side in ['left', 'top', 'right', 'bottom']:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
177 card = self.played[getattr(self, side+'_nick')]
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
178 if card != None:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
179 card.draw(dc,locals()[side+'_x'], locals()[side+'_y'])
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
180
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
181 x=self.orig_x
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
182 for card in self.hand:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
183 if (self.state == "play" or self.state == "ecart") and card == self.mouse_over_card \
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
184 or self.state == "ecart" and card in self.selected:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
185 y = self.orig_y - 30
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
186 else:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
187 y = self.orig_y
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
188
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
189 card.draw(dc,x,y)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
190 x+=self.visible_size
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
191
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
192 if self.to_show:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
193 """There are cards to display in the middle"""
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
194 size = len(self.to_show)*(CARD_WIDTH+10)-10
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
195 x = (max_x - size)/2
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
196 for card in self.to_show:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
197 card.draw(dc, x, 150)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
198 x+=CARD_WIDTH+10
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
199
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
200 def onMouseMove(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
201 pos_x,pos_y = event.GetPosition()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
202 if self._is_on_hand(pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
203 try:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
204 self.mouse_over_card = self.hand[(pos_x-self.orig_x)/self.visible_size]
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
205 except IndexError:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
206 self.mouse_over_card = self.hand[-1]
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
207 self.Refresh()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
208 else:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
209 self.mouse_over_card = None
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
210 self.Refresh()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
211
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
212 def onMouseClick(self, event):
1011
5a6354ff468c wix: use of new logging system
Goffi <goffi@goffi.org>
parents: 878
diff changeset
213 log.debug("mouse click: %s" % event.GetPosition())
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
214 pos_x,pos_y = event.GetPosition()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
215
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
216 if self.state == "chien":
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
217 self.to_show = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
218 self.state = "wait"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
219 return
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
220 elif self.state == "wait_for_ecart":
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
221 self.state = "ecart"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
222 self.hand.extend(self.to_show)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
223 self.hand.sort()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
224 self.to_show = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
225 self._recalc_ori()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
226 self.Refresh()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
227 return
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
228
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
229 if self._is_on_hand(pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
230 idx = (pos_x-self.orig_x)/self.visible_size
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
231 if idx == len(self.hand):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
232 idx-=1
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
233 if self.hand[idx] == self.mouse_over_card:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
234 if self.state == "ecart":
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
235 if self.hand[idx] in self.selected:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
236 self.selected.remove(self.hand[idx])
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
237 else:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
238 self.selected.append(self.hand[idx])
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
239 if len(self.selected) == 6: #TODO: use variable here, as chien len can change with variants
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
240 dlg = wx.MessageDialog(self, _("Do you put these cards in chien ?"), _(u"Écart"), wx.YES_NO | wx.ICON_QUESTION)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
241 answer = dlg.ShowModal()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
242 if answer == wx.ID_YES:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
243 ecart = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
244 for card in self.selected:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
245 ecart.append((card.suit, card.value))
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
246 self.hand.remove(card)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
247 del self.selected[:]
680
8281587eb528 primitivus, wix: fixed bridge methods calls for plugins radiocol and card game
souliane <souliane@mailoo.org>
parents: 609
diff changeset
248 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, ecart, self.parent.host.profile)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
249 self.state = "wait"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
250
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
251 self._recalc_ori()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
252 self.Refresh()
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
253 if self.state == "play":
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
254 card = self.hand[idx]
680
8281587eb528 primitivus, wix: fixed bridge methods calls for plugins radiocol and card game
souliane <souliane@mailoo.org>
parents: 609
diff changeset
255 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, [(card.suit, card.value)], self.parent.host.profile)
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
256 del self.hand[idx]
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
257 self.state = "wait"
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
258 self._recalc_ori()
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
259 self.Refresh()
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
260
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
261