From 32ba3b10b14df6eea2ec42bf3be2827c5e561bf6 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Tue, 27 Jul 2004 22:04:43 +0000 Subject: [PATCH] Made crossword fail when an active hangman game has a solution in the answer set. --- plugins/Words.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/Words.py b/plugins/Words.py index 152ae98ef..aa28e5d8f 100644 --- a/plugins/Words.py +++ b/plugins/Words.py @@ -90,6 +90,10 @@ class HangmanGame: finally: fd.close() + def timedout(self): + elapsed = time.time() - self.timeGuess + return elapsed > self.timeout + def letterPositions(self, letter, word): """Returns a list containing the positions of letter in word.""" lst = [] @@ -154,6 +158,12 @@ class Words(callbacks.Privmsg): return finally: fd.close() + hiddens = [game.hidden for game in self.games.itervalues() + if not game.timedout()] + if hiddens and any(hiddens.__contains__, words): + irc.error('Sorry, one of the responses would\'ve been an answer ' + 'in a currently active hangman game.') + return if words: words.sort() irc.reply(utils.commaAndify(words)) @@ -218,13 +228,13 @@ class Words(callbacks.Privmsg): # we create a new one, otherwise we inform the user else: game = self.games[channel] - secondsElapsed = time.time() - game.timeGuess - if secondsElapsed > game.timeout: + if game.timedout(): self.endGame(channel) self.hangman(irc, msg, args) else: + secondsElapsed = time.time() - game.timeGuess irc.reply('Sorry, there is already a game going on. ' - '%s left before the game times out.' % \ + '%s left before the game times out.' % utils.timeElapsed(game.timeout - secondsElapsed)) def guess(self, irc, msg, args):