Tarot game: basic trick

- plugin xep-0045: new method getRoomNick
- plugin tarot: basic trick
- wix: played card are shown in CardPanel
This commit is contained in:
Goffi 2010-05-30 15:33:08 +09:30
commit 2e6c6142d5
2 changed files with 97 additions and 6 deletions

View file

@ -53,6 +53,7 @@ class QuickApp():
self.bridge.register("tarotGameChooseContrat", self.tarotChooseContrat)
self.bridge.register("tarotGameShowCards", self.tarotShowCards)
self.bridge.register("tarotGameYourTurn", self.tarotMyTurn)
self.bridge.register("tarotGameCardsPlayed", self.tarotCardsPlayed)
self.bridge.register("subscribe", self.subscribe)
self.bridge.register("paramUpdate", self.paramUpdate)
self.bridge.register("contactDeleted", self.contactDeleted)
@ -306,7 +307,14 @@ class QuickApp():
debug (_("My turn to play"))
if self.chat_wins.has_key(room_jid):
self.chat_wins[room_jid].getGame("Tarot").MyTurn()
def tarotCardsPlayed(self, room_jid, player, cards, profile):
if not self.__check_profile(profile):
return
debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards})
if self.chat_wins.has_key(room_jid):
self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards)
def subscribe(self, type, raw_jid, profile):
"""Called when a subsciption management signal is received"""
if not self.__check_profile(profile):

View file

@ -87,6 +87,9 @@ class CardPanel(wx.Panel):
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 @@ class CardPanel(wx.Panel):
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 @@ class CardPanel(wx.Panel):
"""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 @@ class CardPanel(wx.Panel):
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 @@ class CardPanel(wx.Panel):
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()