]> gitweb.pimeys.fr Git - bots/hung.git/commitdiff
On peut perdre
authorVincent Le Gallic <legallic@crans.org>
Sun, 12 May 2013 01:57:46 +0000 (03:57 +0200)
committerVincent Le Gallic <legallic@crans.org>
Sun, 12 May 2013 01:57:46 +0000 (03:57 +0200)
config.py
hung.py

index 3d364b9f294e263d40d051899a25f9fb2ec72d37..52aa91eae4acb7313f0a46ef68bc2c36f7188a76 100644 (file)
--- 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 4f70801ad66d6402fe49d16904a2f492a35e923d..674c09ebb04888cd963a64b1004cf61c5325ccfa 100755 (executable)
--- 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"]: