Mercurial > libervia-backend
diff src/plugins/plugin_misc_tarot.py @ 328:809733b8d9be
Tarot game:
- draw game managed
- we can now play continuously \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 23 May 2011 00:46:51 +0200 |
parents | 5fc5e6a7e5c3 |
children | 141eeb7cd9e6 |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_tarot.py Sun May 22 12:59:25 2011 +0200 +++ b/src/plugins/plugin_misc_tarot.py Mon May 23 00:46:51 2011 +0200 @@ -205,7 +205,6 @@ @param played: cards currently on the table @param winner: nick of the trick winner""" #TODO: manage the case where excuse is played on the last trick (and lost) - #TODO: gof: manage excuse (fool) players_data = game_data['players_data'] excuse = TarotCard(("atout","excuse")) @@ -260,6 +259,20 @@ debug(_("%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one") % {'excuse_owner':excuse_player, 'winner':winner}) + def __draw_game(self, game_data): + """The game is draw, no score change + @param game_data: data of the game + @return: tuple with (string victory message, list of winners, list of loosers)""" + players_data = game_data['players_data'] + scores_str = _('Draw game') + scores_str+='\n' + for player in game_data['players']: + scores_str+=_("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player':player, 'score_game':0, 'total_score': players_data[player]['score']} + debug(scores_str) + + return (scores_str, [], []) + + def __calculate_scores(self, game_data): """The game is finished, time to know who won :) @param game_data: data of the game @@ -547,7 +560,7 @@ hand = game_data['hand'] = {} hand_size = game_data['hand_size'] chien = game_data['chien'] = [] - for i in range(4): #TODO: distribute according to real Tarot rules (3 by 3 counter-clockwise, 1 card at once to chien) + for i in range(4): hand[players[i]] = deck[0:hand_size] del deck[0:hand_size] chien.extend(deck) @@ -617,7 +630,6 @@ mess.firstChildElement().addChild(self.__ask_contrat()) self.host.profiles[profile].xmlstream.send(mess) else: - #TODO: gof: manage "everybody pass" case best_contrat = [None, "Passe"] for player in game_data['players']: contrat = players_data[player]['contrat'] @@ -626,6 +638,16 @@ if idx_pl > idx_best: best_contrat[0] = player best_contrat[1] = contrat + if best_contrat[1] == "Passe": + debug(_("Everybody is passing, round ended")) + to_jid = jid.JID(room_jid.userhost()) + mess = self.createGameElt(to_jid) + mess.firstChildElement().addChild(self.__give_scores(*self.__draw_game(game_data))) + self.host.profiles[profile].xmlstream.send(mess) + game_data['init_player'] = (game_data['init_player'] + 1) % len(game_data['players']) #we change the dealer + for player in game_data['players']: + game_data['status'][player] = "init" + return debug (_("%(player)s win the bid with %(contrat)s") % {'player':best_contrat[0],'contrat':best_contrat[1]}) game_data['contrat'] = best_contrat[1] @@ -718,6 +740,9 @@ mess = self.createGameElt(to_jid) chien_elt = mess.firstChildElement().addChild(self.__give_scores(*self.__calculate_scores(game_data))) self.host.profiles[profile].xmlstream.send(mess) + game_data['init_player'] = (game_data['init_player'] + 1) % len(game_data['players']) #we change the dealer + for player in game_data['players']: + game_data['status'][player] = "init" return #next player is the winner next_player = game_data['first_player'] = self.__next_player(game_data, winner)