comparison frontends/wix/card_game.py @ 141:8c80d4dec7a8

mover Card class to tools/games and renamed it in TarotCard
author Goffi <goffi@goffi.org>
date Thu, 22 Jul 2010 15:49:16 +0800
parents d998adb62d1a
children 80661755ea8d
comparison
equal deleted inserted replaced
140:e496134ed679 141:8c80d4dec7a8
24 import wx 24 import wx
25 import os.path, glob 25 import os.path, glob
26 import pdb 26 import pdb
27 from logging import debug, info, error 27 from logging import debug, info, error
28 from tools.jid import JID 28 from tools.jid import JID
29 from tools.games import TarotCard
29 from xmlui import XMLUI 30 from xmlui import XMLUI
30 31
31 CARD_WIDTH = 74 32 CARD_WIDTH = 74
32 CARD_HEIGHT = 136 33 CARD_HEIGHT = 136
33 MIN_WIDTH = 950 #Minimum size of the panel 34 MIN_WIDTH = 950 #Minimum size of the panel
34 MIN_HEIGHT = 500 35 MIN_HEIGHT = 500
35 36
36 suits_order = ['pique', 'coeur', 'trefle', 'carreau', 'atout'] #I have switched the usual order 'trefle' and 'carreau' because card are more easy to see if suit colour change (black, red, black, red) 37 class wxCard(TarotCard):
37 values_order = map(str,range(1,11))+["valet","cavalier","dame","roi"]
38
39 class Card():
40 """This class is used to represent a card, graphically and logically""" 38 """This class is used to represent a card, graphically and logically"""
41 39
42 def __init__(self, file): 40 def __init__(self, file):
43 """@param file: path of the PNG file""" 41 """@param file: path of the PNG file"""
44 self.bitmap = wx.Image(file).ConvertToBitmap() 42 self.bitmap = wx.Image(file).ConvertToBitmap()
45 root_name = os.path.splitext(os.path.basename(file))[0] 43 root_name = os.path.splitext(os.path.basename(file))[0]
46 self.suit,self.value=root_name.split('_') 44 self.suit,self.value=root_name.split('_')
47 #gof: self.bout = True if self.suit=="atout" and self.value in ["1","21","excuse"] else False 45 TarotCard.__init__(self, (self.suit, self.value))
48
49 print "Carte:",self.suit, self.value #, self.bout 46 print "Carte:",self.suit, self.value #, self.bout
50
51 def __cmp__(self, other):
52 if other == None:
53 return 1
54 if self.suit != other.suit:
55 idx1 = suits_order.index(self.suit)
56 idx2 = suits_order.index(other.suit)
57 return idx1.__cmp__(idx2)
58 if self.suit == 'atout':
59 if self.value == other.value == 'excuse':
60 return 0
61 if self.value == 'excuse':
62 return -1
63 if other.value == 'excuse':
64 return 1
65 return int(self.value).__cmp__(int(other.value))
66 #at this point we have the same suit which is not 'atout'
67 idx1 = values_order.index(self.value)
68 idx2 = values_order.index(other.value)
69 return idx1.__cmp__(idx2)
70
71 def __str__(self):
72 return "[%s,%s]" % (self.suit, self.value)
73 47
74 def draw(self, dc, x, y): 48 def draw(self, dc, x, y):
75 """Draw the card on the device context 49 """Draw the card on the device context
76 @param dc: device context 50 @param dc: device context
77 @param x: abscissa 51 @param x: abscissa
125 self.cards["pique"]={} #spade 99 self.cards["pique"]={} #spade
126 self.cards["coeur"]={} #heart 100 self.cards["coeur"]={} #heart
127 self.cards["carreau"]={} #diamond 101 self.cards["carreau"]={} #diamond
128 self.cards["trefle"]={} #club 102 self.cards["trefle"]={} #club
129 for file in glob.glob(dir+'/*_*.png'): 103 for file in glob.glob(dir+'/*_*.png'):
130 card = Card(file) 104 card = wxCard(file)
131 self.cards[card.suit, card.value]=card 105 self.cards[card.suit, card.value]=card
132 self.deck.append(card) 106 self.deck.append(card)
133 """for value in map(str,range(1,22))+['excuse']: 107 """for value in map(str,range(1,22))+['excuse']:
134 self.idx_cards.append(self.cards["atout",value]) 108 self.idx_cards.append(self.cards["atout",value])
135 for suit in ["pique", "coeur", "carreau", "trefle"]: 109 for suit in ["pique", "coeur", "carreau", "trefle"]: