annotate frontends/wix/card_game.py @ 100:50f1591c8fc6

split_card script: added syntaxe checking
author Goffi <goffi@goffi.org>
date Fri, 18 Jun 2010 17:14:14 +0800
parents 63c9067a1499
children 94011f553cd0
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
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 wix: a SAT frontend
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import wx
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 import os.path, glob
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 import pdb
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from logging import debug, info, error
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from tools.jid import JID
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
29 from form import Form
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
31 CARD_WIDTH = 74
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
32 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
33 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
34 MIN_HEIGHT = 500
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
35
94
1eb5ccead43c Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 93
diff changeset
36 suits_order = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] #I have swith the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
37 values_order = map(str,range(1,11))+["valet","cavalier","dame","roi"]
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
38
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 class Card():
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 """This class is used to represent a card, graphically and logically"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 def __init__(self, file):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 """@param file: path of the PNG file"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.bitmap = wx.Image(file).ConvertToBitmap()
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 root_name = os.path.splitext(os.path.basename(file))[0]
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
46 self.suit,self.value=root_name.split('_')
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
47 #gof: self.bout = True if self.suit=="atout" and self.value in ["1","21","excuse"] else False
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
49 print "Carte:",self.suit, self.value #, self.bout
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
51 def __cmp__(self, other):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
52 if other == None:
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
53 return 1
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
54 if self.suit != other.suit:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
55 idx1 = suits_order.index(self.suit)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
56 idx2 = suits_order.index(other.suit)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
57 return idx1.__cmp__(idx2)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
58 if self.suit == 'atout':
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
59 if self.value == other.value == 'excuse':
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
60 return 0
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
61 if self.value == 'excuse':
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
62 return -1
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
63 if other.value == 'excuse':
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
64 return 1
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
65 return int(self.value).__cmp__(int(other.value))
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
66 #at this point we have the same suit which is not 'atout'
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
67 idx1 = values_order.index(self.value)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
68 idx2 = values_order.index(other.value)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
69 return idx1.__cmp__(idx2)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
70
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
71 def __str__(self):
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
72 return "[%s,%s]" % (self.suit, self.value)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
73
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 def draw(self, dc, x, y):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 """Draw the card on the device context
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 @param dc: device context
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 @param x: abscissa
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 @param y: ordinate"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 dc.DrawBitmap(self.bitmap, x, y, True)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 class CardPanel(wx.Panel):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 """This class is used to display the cards"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
85 def __init__(self, parent, referee, players, player_nick):
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 wx.Panel.__init__(self, parent)
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 87
diff changeset
87 self.parent = parent
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 87
diff changeset
88 self.referee = referee
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
89 self.players = players
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
90 self.played = {}
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
91 for player in players:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
92 self.played[player] = None
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
93 self.player_nick = player_nick
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
94 self.bottom_nick = self.player_nick
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
95 idx = self.players.index(self.player_nick)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
96 idx = (idx + 1) % len(self.players)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
97 self.right_nick = self.players[idx]
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
98 idx = (idx + 1) % len(self.players)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
99 self.top_nick = self.players[idx]
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
100 idx = (idx + 1) % len(self.players)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
101 self.left_nick = self.players[idx]
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
102 self.bottom_nick = player_nick
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
103 self.SetMinSize(wx.Size(MIN_WIDTH, MIN_HEIGHT))
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
104 self.load_cards("/home/goffi/dev/divers/images/cards/")
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
105 self.mouse_over_card = None #contain the card to highlight
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
106 self.selected = [] #Card choosed by the player (e.g. during ecart)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
107 self.hand_size = 13 #number of cards in a hand
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
108 self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
109 self.hand = []
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
110 self.to_show = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
111 self.state = None
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.SetBackgroundColour(wx.GREEN)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
113 self.Bind(wx.EVT_SIZE, self.onResize)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.Bind(wx.EVT_PAINT, self.onPaint)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
115 self.Bind(wx.EVT_MOTION, self.onMouseMove)
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
116 self.Bind(wx.EVT_LEFT_UP, self.onMouseClick)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
117 self.parent.host.bridge.tarotGameReady(player_nick, referee, profile_key = self.parent.host.profile)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def load_cards(self, dir):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 """Load all the cards in memory
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 @param dir: directory where the PNG files are"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self.cards={}
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 self.deck=[]
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 self.cards["atout"]={} #As Tarot is a french game, it's more handy & logical to keep french names
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self.cards["pique"]={} #spade
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.cards["coeur"]={} #heart
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 self.cards["carreau"]={} #diamond
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 self.cards["trefle"]={} #club
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 for file in glob.glob(dir+'/*_*.png'):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 card = Card(file)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
131 self.cards[card.suit, card.value]=card
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self.deck.append(card)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 """for value in map(str,range(1,22))+['excuse']:
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.idx_cards.append(self.cards["atout",value])
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
135 for suit in ["pique", "coeur", "carreau", "trefle"]:
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 for value in map(str,range(1,11))+["valet","cavalier","dame","roi"]:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
137 self.idx_cards.append(self.cards[suit, value])""" #XXX: no need to sort the cards !
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
139 def newGame(self, hand):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
140 """Start a new game, with given hand"""
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
141 assert (len(self.hand) == 0)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
142 for suit, value in hand:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
143 self.hand.append(self.cards[suit, value])
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
144 self.hand.sort()
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
145 self.state = "init"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
146 self._recalc_ori()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
147 self.Refresh()
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
148
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
149 def contratSelected(self, data):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
150 """Called when the contrat has been choosed
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
151 @param data: form result"""
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
152 debug (_("Contrat choosed"))
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
153 contrat = data[0][1]
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
154 self.parent.host.bridge.tarotGameContratChoosed(self.player_nick, self.referee, contrat or 'Passe', self.parent.host.profile)
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
155
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
156 def chooseContrat(self, xml_data):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
157 """Called when the player as to select hist contrat
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
158 @param xml_data: SàT xml representation of the form"""
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
159 misc = {'callback': self.contratSelected}
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
160 form = Form(self.parent.host, xml_data, title = _('Please choose your contrat'), options = ['NO_CANCEL'], misc = misc)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
161
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
162 def showCards(self, game_stage, cards, data):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
163 """Display cards in the middle of the game (to show for e.g. chien ou poignée)"""
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
164 self.to_show = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
165 for suit, value in cards:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
166 self.to_show.append(self.cards[suit, value])
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
167 if game_stage == "chien" and data['attaquant'] == self.player_nick:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
168 self.state = "wait_for_ecart"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
169 else:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
170 self.state = "chien"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
171
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
172 def MyTurn(self):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
173 """Called when we have to play :)"""
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
174 if self.state == "chien":
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
175 self.to_show = []
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
176 self.state = "play"
95
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
177
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
178 def showScores(self, xml_data, winners, loosers):
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
179 """Called when the player as to select hist contrat
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
180 @param xml_data: SàT xml representation of the form"""
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
181 form = Form(self.parent.host, xml_data, title = _('You win \o/') if self.player_nick in winners else _('You loose :('), options = ['NO_CANCEL'])
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 94
diff changeset
182
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
183 def cardsPlayed(self, player, cards):
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
184 """A card has been played by player"""
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
185 if self.to_show:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
186 self.to_show = []
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
187 pl_cards = []
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
188 if self.played[player] != None: #gof: à supprimer
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
189 for pl in self.played:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
190 self.played[pl] = None
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
191 for suit, value in cards:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
192 pl_cards.append(self.cards[suit, value])
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
193 self.played[player] = pl_cards[0]
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
194 self.Refresh()
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
195
99
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
196 def invalidCards(self, phase, played_cards, invalid_cards):
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
197 """Invalid cards have been played
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
198 @param phase: phase of the game
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
199 @param played_cards: all the cards played
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
200 @param invalid_cards: cards which are invalid"""
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
201
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
202 if phase == "play":
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
203 self.state = "play"
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
204 elif phase == "ecart":
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
205 self.state = "ecart"
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
206 else:
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
207 error ('INTERNAL ERROR: unmanaged game phase')
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
208
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
209 for suit, value in played_cards:
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
210 self.hand.append(self.cards[suit, value])
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
211
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
212 self._recalc_ori()
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
213 self.Refresh()
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
214 self.hand.sort()
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
215 wx.MessageDialog(self, _("Cards played are invalid !"), _("Error"), wx.OK | wx.ICON_ERROR).ShowModal()
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
216
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
217
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 97
diff changeset
218
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
219
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
220 def _is_on_hand(self, pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
221 """Return True if the coordinate are on the hand cards"""
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
222 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
223 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
224 and pos_y < self.end_y:
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
225 return True
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
226 return False
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
227
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
228 def onResize(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
229 self._recalc_ori()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
230
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
231 def _recalc_ori(self):
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
232 """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
233 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
234 self.orig_y = self.GetSizeTuple()[1] - CARD_HEIGHT - 20
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
235 self.end_y = self.orig_y + CARD_HEIGHT
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
236
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
237 def onPaint(self, event):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
238 dc = wx.PaintDC(self)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
239
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
240 #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
241 max_x, max_y = self.GetSize()
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
242 border = 10 #border between nick and end of panel
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
243 right_y = left_y = 200
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
244 right_width, right_height = dc.GetTextExtent(self.right_nick)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
245 right_x = max_x - right_width - border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
246 left_x = border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
247 top_width, top_height = dc.GetTextExtent(self.top_nick)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
248 top_x = (max_x - top_width) / 2
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
249 top_y = border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
250 dc.DrawText(self.right_nick, right_x, right_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
251 dc.DrawText(self.top_nick, top_x, top_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
252 dc.DrawText(self.left_nick, left_x, left_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
253
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
254 #We draw the played cards:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
255 center_y = 200 #ordinate used as center point
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
256 left_x = (max_x - CARD_WIDTH)/2 - CARD_WIDTH - 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
257 right_x = (max_x/2) + (CARD_WIDTH/2) + 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
258 left_y = right_y = center_y - CARD_HEIGHT/2
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
259 top_x = bottom_x = (max_x - CARD_WIDTH)/2
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
260 top_y = center_y - CARD_HEIGHT - 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
261 bottom_y = center_y + 5
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
262 for side in ['left', 'top', 'right', 'bottom']:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
263 card = self.played[getattr(self, side+'_nick')]
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
264 if card != None:
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
265 card.draw(dc,locals()[side+'_x'], locals()[side+'_y'])
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
266
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
267 x=self.orig_x
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
268 for card in self.hand:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
269 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
270 or self.state == "ecart" and card in self.selected:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
271 y = self.orig_y - 30
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
272 else:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
273 y = self.orig_y
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
274
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
275 card.draw(dc,x,y)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
276 x+=self.visible_size
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
277
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
278 if self.to_show:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
279 """There are cards to display in the middle"""
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
280 size = len(self.to_show)*(CARD_WIDTH+10)-10
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
281 x = (max_x - size)/2
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
282 for card in self.to_show:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
283 card.draw(dc, x, 150)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
284 x+=CARD_WIDTH+10
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
285
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
286 def onMouseMove(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
287 pos_x,pos_y = event.GetPosition()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
288 if self._is_on_hand(pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
289 try:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
290 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
291 except IndexError:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
292 self.mouse_over_card = self.hand[-1]
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
293 self.Refresh()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
294 else:
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
295 self.mouse_over_card = None
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
296 self.Refresh()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
297
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
298 def onMouseClick(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
299 print "mouse click:",event.GetPosition()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
300 pos_x,pos_y = event.GetPosition()
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
301
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
302 if self.state == "chien":
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
303 self.to_show = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
304 self.state = "wait"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
305 return
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
306 elif self.state == "wait_for_ecart":
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
307 self.state = "ecart"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
308 self.hand.extend(self.to_show)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
309 self.hand.sort()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
310 self.to_show = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
311 self._recalc_ori()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
312 self.Refresh()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
313 return
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
314
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
315 if self._is_on_hand(pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
316 idx = (pos_x-self.orig_x)/self.visible_size
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
317 if idx == len(self.hand):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
318 idx-=1
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
319 if self.hand[idx] == self.mouse_over_card:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
320 if self.state == "ecart":
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
321 if self.hand[idx] in self.selected:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
322 self.selected.remove(self.hand[idx])
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
323 else:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
324 self.selected.append(self.hand[idx])
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
325 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
326 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
327 answer = dlg.ShowModal()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
328 if answer == wx.ID_YES:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
329 ecart = []
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
330 for card in self.selected:
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
331 ecart.append((card.suit, card.value))
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
332 self.hand.remove(card)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
333 print "gof: Cartes envoyes au chien:", ecart
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
334 del self.selected[:]
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
335 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, ecart, profile_key = self.parent.host.profile)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
336 self.state = "wait"
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
337
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
338 self._recalc_ori()
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
339 self.Refresh()
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
340 if self.state == "play":
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
341 card = self.hand[idx]
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
342 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, [(card.suit, card.value)], profile_key = self.parent.host.profile)
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
343 del self.hand[idx]
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
344 self.state = "wait"
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
345 self._recalc_ori()
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
346 self.Refresh()
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
347
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
348