comparison frontends/quick_frontend/quick_card_game.py @ 148:1d74c59a36a9

Quick Frontend: quick card game: added convenience method getPlayerLocation & __fakePlay getPlayerLocation give the place of the player (top, left, bottom or right) __fakePlay try to play every card, usefull for autoplay when debugging
author Goffi <goffi@goffi.org>
date Wed, 28 Jul 2010 19:56:12 +0800
parents 80661755ea8d
children 74aaf230a7c3
comparison
equal deleted inserted replaced
147:dc692acde155 148:1d74c59a36a9
25 25
26 26
27 class QuickCardGame(): 27 class QuickCardGame():
28 28
29 def __init__(self, parent, referee, players, player_nick): 29 def __init__(self, parent, referee, players, player_nick):
30 self.__fake_idx = 0 #gof:
30 self.parent = parent 31 self.parent = parent
31 self.referee = referee 32 self.referee = referee
32 self.players = players 33 self.players = players
33 self.played = {} 34 self.played = {}
34 for player in players: 35 for player in players:
46 self.selected = [] #Card choosed by the player (e.g. during ecart) 47 self.selected = [] #Card choosed by the player (e.g. during ecart)
47 self.hand_size = 13 #number of cards in a hand 48 self.hand_size = 13 #number of cards in a hand
48 self.hand = [] 49 self.hand = []
49 self.to_show = [] 50 self.to_show = []
50 self.state = None 51 self.state = None
52
53 def getPlayerLocation(self, nick):
54 """return player location (top,bottom,left or right)"""
55 for location in ['top','left','bottom','right']:
56 if getattr(self,'%s_nick' % location) == nick:
57 return location
58 assert(False)
51 59
52 def loadCards(self): 60 def loadCards(self):
53 """Load all the cards in memory 61 """Load all the cards in memory
54 @param dir: directory where the PNG files are""" 62 @param dir: directory where the PNG files are"""
55 self.cards={} 63 self.cards={}
86 if game_stage == "chien" and data['attaquant'] == self.player_nick: 94 if game_stage == "chien" and data['attaquant'] == self.player_nick:
87 self.state = "wait_for_ecart" 95 self.state = "wait_for_ecart"
88 else: 96 else:
89 self.state = "chien" 97 self.state = "chien"
90 98
91 def MyTurn(self): 99 def myTurn(self):
92 """Called when we have to play :)""" 100 """Called when we have to play :)"""
93 if self.state == "chien": 101 if self.state == "chien":
94 self.to_show = [] 102 self.to_show = []
95 self.state = "play" 103 self.state = "play"
104 self.__fakePlay() #gof:
105
106 def __fakePlay(self):
107 """Convenience method for stupid autoplay
108 /!\ don't forgot to comment any interactive dialog for invalid card"""
109 #gof:
110 if self.__fake_idx >= len(self.hand):
111 self.__fake_idx = 0
112 card = self.hand[self.__fake_idx]
113 self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, [(card.suit, card.value)], profile_key = self.parent.host.profile)
114 del self.hand[self.__fake_idx]
115 self.state = "wait"
116 self.__fake_idx+=1
96 117
97 def showScores(self, xml_data, winners, loosers): 118 def showScores(self, xml_data, winners, loosers):
98 """Called when the player as to select hist contrat 119 """Called when the player as to select hist contrat
99 @param xml_data: SàT xml representation of the form""" 120 @param xml_data: SàT xml representation of the form"""
100 raise NotImplementedError 121 raise NotImplementedError
126 147
127 for suit, value in played_cards: 148 for suit, value in played_cards:
128 self.hand.append(self.cards[suit, value]) 149 self.hand.append(self.cards[suit, value])
129 150
130 self.hand.sort() 151 self.hand.sort()
152 self.__fakePlay() #gof:
131 153