diff frontends/wix/card_game.py @ 93:2f87651a5ad8

Tarot game: basic trick - plugin xep-0045: new method getRoomNick - plugin tarot: basic trick - wix: played card are shown in CardPanel
author Goffi <goffi@goffi.org>
date Sun, 30 May 2010 15:33:08 +0930
parents 2503de7fb4c7
children 1eb5ccead43c
line wrap: on
line diff
--- a/frontends/wix/card_game.py	Sat May 29 20:53:03 2010 +0930
+++ b/frontends/wix/card_game.py	Sun May 30 15:33:08 2010 +0930
@@ -87,6 +87,9 @@
         self.parent = parent
         self.referee = referee
         self.players = players
+        self.played = {}
+        for player in players:
+            self.played[player] = None
         self.player_nick = player_nick
         self.bottom_nick = self.player_nick
         idx = self.players.index(self.player_nick)
@@ -96,6 +99,7 @@
         self.top_nick = self.players[idx]
         idx = (idx + 1) % len(self.players)
         self.left_nick = self.players[idx]
+        self.bottom_nick = player_nick
         self.SetMinSize(wx.Size(MIN_WIDTH, MIN_HEIGHT))
         self.load_cards("/home/goffi/dev/divers/images/cards/")
         self.mouse_over_card = None #contain the card to highlight
@@ -169,7 +173,21 @@
         """Called when we have to play :)"""
         if self.state == "chien":
             self.to_show = []
-        self.state="play"
+        self.state = "play"
+    
+    def cardsPlayed(self, player, cards):
+        """A card has been played by player"""
+        if self.to_show:
+            self.to_show = []
+        pl_cards = []
+        if self.played[player] != None: #gof: à supprimer
+            for pl in self.played:
+                self.played[pl] = None
+        for suit, value in cards:
+            pl_cards.append(self.cards[suit, value])
+        self.played[player] = pl_cards[0]
+        self.Refresh()
+
 
     def _is_on_hand(self, pos_x, pos_y):
         """Return True if the coordinate are on the hand cards"""
@@ -205,6 +223,19 @@
         dc.DrawText(self.top_nick, top_x, top_y)
         dc.DrawText(self.left_nick, left_x, left_y)
 
+        #We draw the played cards:
+        center_y = 200 #ordinate used as center point
+        left_x = (max_x - CARD_WIDTH)/2 - CARD_WIDTH - 5
+        right_x = (max_x/2) + (CARD_WIDTH/2) + 5
+        left_y = right_y = center_y - CARD_HEIGHT/2
+        top_x = bottom_x = (max_x - CARD_WIDTH)/2
+        top_y = center_y - CARD_HEIGHT - 5
+        bottom_y = center_y + 5
+        for side in ['left', 'top', 'right', 'bottom']:
+            card = self.played[getattr(self, side+'_nick')]
+            if card != None:
+                card.draw(dc,locals()[side+'_x'], locals()[side+'_y'])
+
         x=self.orig_x
         for card in self.hand:
             if (self.state == "play" or self.state == "ecart") and card == self.mouse_over_card \
@@ -278,3 +309,12 @@
 
                    self._recalc_ori()
                    self.Refresh()
+               if self.state == "play":
+                   card = self.hand[idx]
+                   self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, [(card.suit, card.value)], profile_key = self.parent.host.profile)
+                   del self.hand[idx]
+                   self.state = "wait"
+                   self._recalc_ori()
+                   self.Refresh()
+
+