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
# ' 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):
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)
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"]: