Mercurial > libervia-backend
changeset 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 | dc692acde155 |
children | 3c3f70c01333 |
files | frontends/quick_frontend/quick_card_game.py |
diffstat | 1 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_card_game.py Wed Jul 28 19:53:19 2010 +0800 +++ b/frontends/quick_frontend/quick_card_game.py Wed Jul 28 19:56:12 2010 +0800 @@ -27,6 +27,7 @@ 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 @@ 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 @@ 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 @@ self.hand.append(self.cards[suit, value]) self.hand.sort() + self.__fakePlay() #gof: