annotate frontends/wix/card_game.py @ 87:66d784082930

Tarot game - Tarot plugin: game session start, first draft - wix: Tarot: names of players are now printed - wix: Tarot: game session start first draft - wix : Tarot: card can be compared and sorted
author Goffi <goffi@goffi.org>
date Tue, 11 May 2010 23:58:32 +0930
parents 4b5f2d55b6ac
children 4020931569b8
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
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from quick_frontend.quick_chat import QuickChat
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from contact_list import ContactList
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
32 CARD_WIDTH = 74
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
33 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
34 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
35 MIN_HEIGHT = 500
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
36
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
37 families_order = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] #I have swith the usual order 'trefle' and 'carreau' because card are more easy to see if couleur change (black, red, black, red)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
38 values_order = map(str,range(1,11))+["valet","cavalier","dame","roi"]
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
39
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 class Card():
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """This class is used to represent a card, graphically and logically"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def __init__(self, file):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 """@param file: path of the PNG file"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.bitmap = wx.Image(file).ConvertToBitmap()
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 root_name = os.path.splitext(os.path.basename(file))[0]
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.family,self.value=root_name.split('_')
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.bout = True if self.family=="atout" and self.value in ["1","21","excuse"] else False
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 print "Carte:",self.family, self.value, self.bout
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
52 def __cmp__(self, other):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
53 if other == None:
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
54 return 1
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
55 if self.family != other.family:
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
56 idx1 = families_order.index(self.family)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
57 idx2 = families_order.index(other.family)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
58 return idx1.__cmp__(idx2)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
59 if self.family == 'atout':
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
60 if self.value == other.value == 'excuse':
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
61 return 0
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
62 if self.value == 'excuse':
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
63 return -1
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
64 if other.value == 'excuse':
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
65 return 1
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
66 return int(self.value).__cmp__(int(other.value))
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
67 #at this point we have the same family which is not 'atout'
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
68 idx1 = values_order.index(self.value)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
69 idx2 = values_order.index(other.value)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
70 return idx1.__cmp__(idx2)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
71
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
72 def __str__(self):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
73 return "[%s,%s]" % (self.family, self.value)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
74
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def draw(self, dc, x, y):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 """Draw the card on the device context
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 @param dc: device context
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 @param x: abscissa
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 @param y: ordinate"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 dc.DrawBitmap(self.bitmap, x, y, True)
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
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 class CardPanel(wx.Panel):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """This class is used to display the cards"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
86 def __init__(self, parent, players, user):
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 wx.Panel.__init__(self, parent)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
88 self.players = players
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
89 self.user = user
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
90 self.bottom_nick = self.user
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
91 idx = self.players.index(self.user)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
92 idx = (idx + 1) % len(self.players)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
93 self.right_nick = self.players[idx]
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
94 idx = (idx + 1) % len(self.players)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
95 self.top_nick = self.players[idx]
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.left_nick = self.players[idx]
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
98 self.SetMinSize(wx.Size(MIN_WIDTH, MIN_HEIGHT))
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
99 self.load_cards("/home/goffi/dev/divers/images/cards/")
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
100 self.selected = None #contain the card to highlight
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
101 self.hand_size = 13 #number of cards in a hand
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
102 self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
103 self.hand = []
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
104 self.my_turn = False
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.SetBackgroundColour(wx.GREEN)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
106 self.Bind(wx.EVT_SIZE, self.onResize)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.Bind(wx.EVT_PAINT, self.onPaint)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
108 self.Bind(wx.EVT_MOTION, self.onMouseMove)
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
109 self.Bind(wx.EVT_LEFT_UP, self.onMouseClick)
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def load_cards(self, dir):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 """Load all the cards in memory
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 @param dir: directory where the PNG files are"""
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.cards={}
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.deck=[]
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 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
117 self.cards["pique"]={} #spade
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 self.cards["coeur"]={} #heart
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.cards["carreau"]={} #diamond
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self.cards["trefle"]={} #club
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 for file in glob.glob(dir+'/*_*.png'):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 card = Card(file)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 self.cards[card.family, card.value]=card
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 self.deck.append(card)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 """for value in map(str,range(1,22))+['excuse']:
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.idx_cards.append(self.cards["atout",value])
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 for family in ["pique", "coeur", "carreau", "trefle"]:
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 for value in map(str,range(1,11))+["valet","cavalier","dame","roi"]:
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 self.idx_cards.append(self.cards[family, value])""" #XXX: no need to sort the cards !
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
131 def newGame(self, hand):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
132 """Start a new game, with given hand"""
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
133 assert (len(self.hand) == 0)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
134 for family, value in hand:
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
135 self.hand.append(self.cards[family, value])
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
136 self.hand.sort()
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
137 self.my_turn = True
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
138
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
139 def _is_on_hand(self, pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
140 """Return True if the coordinate are on the hand cards"""
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
141 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
142 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
143 and pos_y < self.end_y:
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
144 return True
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
145 return False
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
146
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
147 def onResize(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
148 self._recalc_ori()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
149
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
150 def _recalc_ori(self):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
151 """Recalculate origines, must be call when size change"""
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
152 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
153 self.orig_y = self.GetSizeTuple()[1] - CARD_HEIGHT - 20
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
154 self.end_y = self.orig_y + CARD_HEIGHT
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
155
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 def onPaint(self, event):
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 dc = wx.PaintDC(self)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
158
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
159 #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
160 max_x, max_y = self.GetSize()
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
161 border = 10 #border between nick and end of panel
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
162 right_y = left_y = 200
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
163 right_width, right_height = dc.GetTextExtent(self.right_nick)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
164 right_x = max_x - right_width - border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
165 left_x = border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
166 top_width, top_height = dc.GetTextExtent(self.top_nick)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
167 top_x = (max_x - top_width) / 2
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
168 top_y = border
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
169 dc.DrawText(self.right_nick, right_x, right_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
170 dc.DrawText(self.top_nick, top_x, top_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
171 dc.DrawText(self.left_nick, left_x, left_y)
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
172
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
173 x=self.orig_x
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
174 for card in self.hand:
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
175 card.draw(dc,x,self.orig_y - 30 if self.my_turn and card == self.selected else self.orig_y)
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
176 x+=self.visible_size
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
177
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
178 def onMouseMove(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
179 pos_x,pos_y = event.GetPosition()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
180 if self._is_on_hand(pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
181 try:
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
182 self.selected = self.hand[(pos_x-self.orig_x)/self.visible_size]
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
183 except IndexError:
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
184 self.selected = self.hand[-1]
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
185 self.Refresh()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
186 else:
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
187 self.selected = None
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
188 self.Refresh()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
189
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
190 def onMouseClick(self, event):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
191 print "mouse click:",event.GetPosition()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
192 pos_x,pos_y = event.GetPosition()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
193 if self._is_on_hand(pos_x, pos_y):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
194 idx = (pos_x-self.orig_x)/self.visible_size
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
195 if idx == len(self.hand):
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
196 idx-=1
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
197 if self.hand[idx] == self.selected:
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
198 del self.hand[idx]
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
199 self._recalc_ori()
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
200 self.Refresh()
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
201
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
202 class CardGame(wx.Frame, QuickChat):
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
203 """The window used to play all kind of card games"""
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
204
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
205 def __init__(self, host):
83
1ac759ea28c3 wix: tarot game preparation step
Goffi <goffi@goffi.org>
parents: 81
diff changeset
206 wx.Frame.__init__(self, None, pos=(0,0), size=(950,500))
81
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
207
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208 self.host = host
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
209
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210 self.sizer = wx.BoxSizer(wx.VERTICAL)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
211 self.panel = CardPanel(self)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
212 self.sizer.Add(self.panel, 1, flag=wx.EXPAND)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
213 self.SetSizer(self.sizer)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214 self.SetAutoLayout(True)
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
215
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
216
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
217 #events
104a815bb23f Tarot game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218