From 3a47cb6a49f4d1d7712408493c572f2765bb7a67 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Sun, 12 May 2013 03:57:46 +0200 Subject: [PATCH] On peut perdre --- config.py | 3 +++ hung.py | 33 +++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 3d364b9..52aa91e 100644 --- a/config.py +++ b/config.py @@ -45,3 +45,6 @@ u"B Y E, C R U E L _ O R L D!", u"B Y E, C R U E L W O R L D!", ] leave_messages=["On finira la partie plus tard :p"] + +#: Nombre de chances avant d'être pendu +lives = 7 diff --git a/hung.py b/hung.py index 4f70801..674c09e 100755 --- a/hung.py +++ b/hung.py @@ -91,6 +91,8 @@ class Hung(ircbot.SingleServerIRCBot): self.stay_channels=config.stay_channels self.play_channels=config.play_channels self.play_status={i:[None,None,None] for i in self.play_channels} + self.lives={} + self.tried_letters={} self.quiet_channels=config.quiet_channels @@ -325,6 +327,8 @@ class Hung(ircbot.SingleServerIRCBot): # ' et - sont considérés comme déjà devinés mot = [(lettre,lettre in "'-()") for lettre in list(mot)] self.play_status[canal]=[mot,definition,{}] + self.tried_letters[canal] = set () + self.lives[canal] = config.lives self.affiche_mot(serv, canal, begin="Devinez") def on_pubmsg(self, serv, ev): @@ -391,6 +395,17 @@ class Hung(ircbot.SingleServerIRCBot): self.play_status[canal][2][auteur] = nbtrouvees self.play_status[canal][0]=listeapres self.affiche_mot(serv, canal, begin="%s placé"%(giv_let)) + else: + if not giv_let in self.tried_letters[canal]: + # On perd une chance + self.lives[canal] -= 1 + if self.lives[canal] > 0: + serv.privmsg(canal, "Pas de %s. Plus que %s chances…" % (giv_let, self.lives[canal])) + if self.lives[canal] == 0: + serv.privmsg(canal, "Pas de %s." % (giv_let)) + self.perd(serv, canal) + return + self.tried_letters[canal].add(giv_let) if all([lettre[1] for lettre in listeapres]): self.gagne(serv, canal) @@ -487,17 +502,27 @@ class Hung(ircbot.SingleServerIRCBot): serv.privmsg(destinataire,"Scores by pseudo : "+" ; ".join(["%s %s"%(k,v) for (k,v) in scores]) ) def gagne(self, serv, canal, bonus=None, bonusvalue=2): - realword="".join([lettre[0] for lettre in self.play_status[canal][0]]) - definition = self.play_status[canal][1] - serv.privmsg(canal,"Bravo ! C'était %s"%(realword)) - serv.privmsg(canal,definition) + serv.privmsg(canal,"Bravo !") + realword = self.reveal_word(serv, canal) nlettre=float(len(realword.replace("'","").replace("-",""))) contribs=["%s:%s%%%s"%(pseudo,str(int(100*contrib/nlettre)),("+bonus(%s)"%(bonusvalue))*(bonus==pseudo)) for pseudo,contrib in self.play_status[canal][2].items()] contribs_score={pseudo:int(10*contrib/nlettre) for pseudo,contrib in self.play_status[canal][2].items()} self.add_score(contribs_score) serv.privmsg(canal,"Contributions : %s"%(" ".join(contribs)) ) self.play_status[canal]=[None,None,None] + + def reveal_word(self, serv, canal): + realword="".join([lettre[0] for lettre in self.play_status[canal][0]]) + serv.privmsg(canal, "C'était %s." % (realword)) + definition = self.play_status[canal][1] + serv.privmsg(canal,definition) + return realword + def perd(self, serv, canal): + serv.privmsg(canal,"Pendu !") + self.reveal_word(serv, canal) + self.play_status[canal]=[None,None,None] + def reload(self, auteur=None): reload(config) if auteur in [None, "SIGHUP"]: -- 2.39.2