comparison frontends/wix/card_game.py @ 81:104a815bb23f

Tarot game: first draft - wix: first draft of cards window - shell script to split cards from Tarot game found on wikimedia commons
author Goffi <goffi@goffi.org>
date Sun, 18 Apr 2010 15:47:10 +1000
parents
children 1ac759ea28c3
comparison
equal deleted inserted replaced
80:9681f18d06bd 81:104a815bb23f
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 wix: a SAT frontend
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22
23
24 import wx
25 import os.path, glob
26 import random
27 import pdb
28 from logging import debug, info, error
29 from tools.jid import JID
30 from quick_frontend.quick_chat import QuickChat
31 from contact_list import ContactList
32
33 class Card():
34 """This class is used to represent a card, graphically and logically"""
35
36 def __init__(self, file):
37 """@param file: path of the PNG file"""
38 self.bitmap = wx.Image(file).ConvertToBitmap()
39 root_name = os.path.splitext(os.path.basename(file))[0]
40 self.family,self.value=root_name.split('_')
41 self.bout = True if self.family=="atout" and self.value in ["1","21","excuse"] else False
42
43 print "Carte:",self.family, self.value, self.bout
44
45 def draw(self, dc, x, y):
46 """Draw the card on the device context
47 @param dc: device context
48 @param x: abscissa
49 @param y: ordinate"""
50 dc.DrawBitmap(self.bitmap, x, y, True)
51
52
53 class CardPanel(wx.Panel):
54 """This class is used to display the cards"""
55
56 def __init__(self, parent):
57 wx.Panel.__init__(self, parent)
58 self.SetBackgroundColour(wx.GREEN)
59 self.Bind(wx.EVT_PAINT, self.onPaint)
60 self.load_cards("/home/goffi/dev/divers/images/cards/")
61
62 def load_cards(self, dir):
63 """Load all the cards in memory
64 @param dir: directory where the PNG files are"""
65 self.cards={}
66 self.deck=[]
67 self.cards["atout"]={} #As Tarot is a french game, it's more handy & logical to keep french names
68 self.cards["pique"]={} #spade
69 self.cards["coeur"]={} #heart
70 self.cards["carreau"]={} #diamond
71 self.cards["trefle"]={} #club
72 for file in glob.glob(dir+'/*_*.png'):
73 card = Card(file)
74 self.cards[card.family, card.value]=card
75 self.deck.append(card)
76 """for value in map(str,range(1,22))+['excuse']:
77 self.idx_cards.append(self.cards["atout",value])
78 for family in ["pique", "coeur", "carreau", "trefle"]:
79 for value in map(str,range(1,11))+["valet","cavalier","dame","roi"]:
80 self.idx_cards.append(self.cards[family, value])""" #XXX: no need to sort the cards !
81
82 def onPaint(self, event):
83 print "toto", event
84 dc = wx.PaintDC(self)
85 x=0
86 for card in random.sample(self.deck,13):
87 card.draw(dc,x,0)
88 x+=37
89
90 class CardGame(wx.Frame, QuickChat):
91 """The chat Window for one to one conversations"""
92
93 def __init__(self, host):
94 wx.Frame.__init__(self, None, pos=(0,0), size=(800,550))
95
96 self.host = host
97
98 self.sizer = wx.BoxSizer(wx.VERTICAL)
99 self.panel = CardPanel(self)
100 self.sizer.Add(self.panel, 1, flag=wx.EXPAND)
101 self.SetSizer(self.sizer)
102 self.SetAutoLayout(True)
103
104
105 #events
106