Made crossword fail when an active hangman game has a solution in the answer set.

This commit is contained in:
Jeremy Fincher 2004-07-27 22:04:43 +00:00
parent 82161ee386
commit 32ba3b10b1

View File

@ -90,6 +90,10 @@ class HangmanGame:
finally: finally:
fd.close() fd.close()
def timedout(self):
elapsed = time.time() - self.timeGuess
return elapsed > self.timeout
def letterPositions(self, letter, word): def letterPositions(self, letter, word):
"""Returns a list containing the positions of letter in word.""" """Returns a list containing the positions of letter in word."""
lst = [] lst = []
@ -154,6 +158,12 @@ class Words(callbacks.Privmsg):
return return
finally: finally:
fd.close() 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: if words:
words.sort() words.sort()
irc.reply(utils.commaAndify(words)) irc.reply(utils.commaAndify(words))
@ -218,13 +228,13 @@ class Words(callbacks.Privmsg):
# we create a new one, otherwise we inform the user # we create a new one, otherwise we inform the user
else: else:
game = self.games[channel] game = self.games[channel]
secondsElapsed = time.time() - game.timeGuess if game.timedout():
if secondsElapsed > game.timeout:
self.endGame(channel) self.endGame(channel)
self.hangman(irc, msg, args) self.hangman(irc, msg, args)
else: else:
secondsElapsed = time.time() - game.timeGuess
irc.reply('Sorry, there is already a game going on. ' 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)) utils.timeElapsed(game.timeout - secondsElapsed))
def guess(self, irc, msg, args): def guess(self, irc, msg, args):