annotate browser_side/card_game.py @ 37:b306aa090438

Tarot game: game launching (first hand showed), and contract selection
author Goffi <goffi@goffi.org>
date Wed, 18 May 2011 01:45:28 +0200
parents 1d406077b49b
children 7bea2ae0c4fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import pyjd # this is dummy in pyjs
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.AbsolutePanel import AbsolutePanel
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
24 from pyjamas.ui.VerticalPanel import VerticalPanel
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
25 from pyjamas.ui.HorizontalPanel import HorizontalPanel
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
26 from pyjamas.ui.DockPanel import DockPanel
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
27 from pyjamas.ui.DialogBox import DialogBox
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
28 from pyjamas.ui.ListBox import ListBox
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.Image import Image
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
30 from pyjamas.ui.Label import Label
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
31 from pyjamas.ui.Button import Button
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
32 from pyjamas.ui import HasAlignment
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from pyjamas.dnd import makeDraggable
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from pyjamas.ui.DragWidget import DragWidget, DragContainer
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from jid import JID
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from tools import html_sanitize
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from datetime import datetime
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 from time import time
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 from games import TarotCard
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 CARD_WIDTH = 74
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 CARD_HEIGHT = 136
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 MIN_WIDTH = 950 #Minimum size of the panel
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 MIN_HEIGHT = 500
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
49 class ContratChooser(DialogBox):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
50
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
51 def __init__(self, parent):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
52 """
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
53 Dialog asking to choose the contrat
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
54 """
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
55 self._parent = parent
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
56 DialogBox.__init__(self, modal=False, centered=True)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
57
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
58 content = VerticalPanel()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
59 content.setWidth('100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
60 self.contrats_list = ListBox()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
61 self.contrats_list.setVisibleItemCount(5)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
62 self.contrats_list.setWidth("100%")
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
63 self.contrats_list.setStyleName('contratsChooser')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
64 for contrat in ['Passe', 'Petite', 'Garde', 'Garde Sans', 'Garde Contre']:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
65 self.contrats_list.addItem(contrat)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
66 self.contrats_list.setSelectedIndex(0)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
67 content.add(self.contrats_list)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
68 button_panel = HorizontalPanel()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
69 self.choose_button = Button("Choose", self.onChoose)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
70 button_panel.add(self.choose_button)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
71 content.add(button_panel)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
72 self.setHTML("Please select your contrat")
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
73 self.setWidget(content)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
74
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
75 def onChoose(self):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
76 self.hide()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
77 self._parent.contratSelected(self.contrats_list.getSelectedItemText()[0])
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 class CardWidget(TarotCard, Image):
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 """This class is used to represent a card, graphically and logically"""
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def __init__(self, file):
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 """@param file: path of the PNG file"""
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 Image.__init__(self,file)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 root_name = file[file.rfind("/")+1:-4]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 suit,value = root_name.split('_')
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 TarotCard.__init__(self, (suit, value))
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 print "Carte:",suit, value #, self.bout
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 def draw(self, dc, x, y):
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 """Draw the card on the device context
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 @param dc: device context
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 @param x: abscissa
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 @param y: ordinate"""
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 pass
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 #dc.DrawBitmap(self.bitmap, x, y, True)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
98 class CardPanel(DockPanel):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 def __init__(self, parent, referee, players, player_nick):
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self._parent = parent
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 self._autoplay = None #XXX: use 0 to activate fake play, None else
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 self.referee = referee
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.players = players
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.played = {}
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 for player in players:
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.played[player] = None
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.player_nick = player_nick
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 self.bottom_nick = self.player_nick
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 idx = self.players.index(self.player_nick)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.right_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.top_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.left_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 self.bottom_nick = player_nick
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 self.selected = [] #Card choosed by the player (e.g. during ecart)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.hand_size = 13 #number of cards in a hand
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self.hand = []
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 self.to_show = []
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self.state = None
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
123 DockPanel.__init__(self)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 self.setSize("%spx" % MIN_WIDTH, "%spx" % MIN_HEIGHT)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self.setStyleName("cardPanel")
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
126
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
127 _label = Label(self.top_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
128 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
129 self.add(_label, DockPanel.NORTH)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
130 self.setCellWidth(_label, '100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
131 self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_CENTER)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
132
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
133 self.hand_panel = AbsolutePanel()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
134 self.add(self.hand_panel, DockPanel.SOUTH)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
135 self.setCellWidth(self.hand_panel, '100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
136 self.setCellHorizontalAlignment(self.hand_panel, HasAlignment.ALIGN_CENTER)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
137
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
138
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
139 _label = Label(self.left_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
140 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
141 self.add(_label, DockPanel.WEST)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
142 self.setCellHeight(_label, '100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
143 self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
144
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
145 _label = Label(self.right_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
146 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
147 self.add(_label, DockPanel.EAST)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
148 self.setCellHeight(_label, '100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
149 self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_RIGHT)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
150 self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
151
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
152 self.center_panel = DockPanel()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
153 self.add(self.center_panel, DockPanel.CENTER)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
154 self.setCellWidth(self.center_panel, '100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
155
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
156
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
157 """for side in zip(['left', 'top', 'right'],
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
158 [DockPanel.WEST, DockPanel.NORTH, DockPanel.EAST]):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
159 _nick = getattr(self, "%s_nick" % side[0])
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
160 _label = Label(_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
161 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
162 self.add(_label, side[1])"""
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 self.loadCards()
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 self.mouse_over_card = None #contain the card to highlight
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def loadCards(self, dir):
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 """Load all the cards in memory
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 @param dir: directory where the PNG files are"""
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
171 def _getTarotCardsPathsCb(paths):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
172 for file in paths:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
173 card = CardWidget(file)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
174 self.cards[(card.suit, card.value)]=card
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
175 self.deck.append(card)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
176 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 self.cards={}
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.deck=[]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 self.cards["atout"]={} #As Tarot is a french game, it's more handy & logical to keep french names
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180 self.cards["pique"]={} #spade
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181 self.cards["coeur"]={} #heart
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 self.cards["carreau"]={} #diamond
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.cards["trefle"]={} #club
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
184 self._parent.host.bridge.call('getTarotCardsPaths', _getTarotCardsPathsCb)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
185
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
186 def tarotGameNew(self, hand):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
187 """Start a new game, with given hand"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
188 for suit, value in hand:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
189 self.hand.append(self.cards[(suit, value)])
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
190 self.hand.sort()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
191 self.state = "init"
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
192 self.updateHand()
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
194 def updateHand(self):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
195 """Show the cards in the hand in the hand_panel (SOUTH panel)"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
196 self.hand_panel.clear()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
197 self.hand_panel.setSize("%spx" % (self.visible_size * (len(self.hand)+1)), "%spx" % (CARD_HEIGHT + 10))
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
198 x_pos = 0
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
199 y_pos = 0
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
200 for card in self.hand:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
201 self.hand_panel.add(card, x_pos, y_pos)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
202 x_pos+=self.visible_size
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
203
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
204 def tarotGameChooseContrat(self, xml_data):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
205 """Called when the player as to select his contrat
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
206 @param xml_data: SàT xml representation of the form"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
207 #for the moment we cheat a little bit and make our own dialog box
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
208 #but XMLUI must be user ASAP, as in other frontends
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
209 contrat_chooser = ContratChooser(self)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
210 contrat_chooser.show()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
211
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
212 def contratSelected(self, contrat):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
213 """Must be called when the contrat is selected
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
214 @param contrat: one of the valid contrat value"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
215 print "Contrat choosed:", contrat
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
216 self._parent.host.bridge.call('tarotGameContratChoosed', None, self.player_nick, self.referee, contrat or 'Passe') #FIXME: must use roomID ! cf quick_card_game for same issue
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
217