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
This commit is contained in:
Goffi 2010-07-28 19:56:12 +08:00
commit ad1c81a580

View file

@ -27,6 +27,7 @@ from tools.jid import JID
class QuickCardGame():
def __init__(self, parent, referee, players, player_nick):
self.__fake_idx = 0 #gof:
self.parent = parent
self.referee = referee
self.players = players
@ -49,6 +50,13 @@ class QuickCardGame():
self.to_show = []
self.state = None
def getPlayerLocation(self, nick):
"""return player location (top,bottom,left or right)"""
for location in ['top','left','bottom','right']:
if getattr(self,'%s_nick' % location) == nick:
return location
assert(False)
def loadCards(self):
"""Load all the cards in memory
@param dir: directory where the PNG files are"""
@ -88,11 +96,24 @@ class QuickCardGame():
else:
self.state = "chien"
def MyTurn(self):
def myTurn(self):
"""Called when we have to play :)"""
if self.state == "chien":
self.to_show = []
self.state = "play"
self.__fakePlay() #gof:
def __fakePlay(self):
"""Convenience method for stupid autoplay
/!\ don't forgot to comment any interactive dialog for invalid card"""
#gof:
if self.__fake_idx >= len(self.hand):
self.__fake_idx = 0
card = self.hand[self.__fake_idx]
self.parent.host.bridge.tarotGamePlayCards(self.player_nick, self.referee, [(card.suit, card.value)], profile_key = self.parent.host.profile)
del self.hand[self.__fake_idx]
self.state = "wait"
self.__fake_idx+=1
def showScores(self, xml_data, winners, loosers):
"""Called when the player as to select hist contrat
@ -128,4 +149,5 @@ class QuickCardGame():
self.hand.append(self.cards[suit, value])
self.hand.sort()
self.__fakePlay() #gof: