mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-07 19:49:23 +01:00
Changed the HangmanGame class a little and how a game works.
This commit is contained in:
parent
eee9b5aaf2
commit
80da030351
@ -100,7 +100,6 @@ def addWord(db, word, commit=False):
|
|||||||
|
|
||||||
class HangmanGame:
|
class HangmanGame:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.gameOn = False
|
|
||||||
self.timeout = 0
|
self.timeout = 0
|
||||||
self.timeGuess = 0
|
self.timeGuess = 0
|
||||||
self.tries = 0
|
self.tries = 0
|
||||||
@ -168,7 +167,6 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||||||
self.gotDictFile = True
|
self.gotDictFile = True
|
||||||
except IOError:
|
except IOError:
|
||||||
self.gotDictFile = False
|
self.gotDictFile = False
|
||||||
self.gameon = False
|
|
||||||
|
|
||||||
def add(self, irc, msg, args):
|
def add(self, irc, msg, args):
|
||||||
"""<word> [<word>]
|
"""<word> [<word>]
|
||||||
@ -245,7 +243,7 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||||||
validLetters = [chr(c) for c in range(ord('a'), ord('z')+1)]
|
validLetters = [chr(c) for c in range(ord('a'), ord('z')+1)]
|
||||||
|
|
||||||
def endGame(self, channel):
|
def endGame(self, channel):
|
||||||
self.games[channel].gameOn = False
|
self.games[channel] = None
|
||||||
|
|
||||||
def letters(self, irc, msg, args):
|
def letters(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
@ -255,7 +253,7 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if channel in self.games:
|
if channel in self.games:
|
||||||
game = self.games[channel]
|
game = self.games[channel]
|
||||||
if game.gameOn:
|
if game is not None:
|
||||||
irc.reply('%s%s' % (game.prefix, ' '.join(game.unused)))
|
irc.reply('%s%s' % (game.prefix, ' '.join(game.unused)))
|
||||||
return
|
return
|
||||||
irc.error('There is no hangman game going on right now.')
|
irc.error('There is no hangman game going on right now.')
|
||||||
@ -268,11 +266,11 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
# Fill our dictionary of games
|
# Fill our dictionary of games
|
||||||
if channel not in self.games:
|
if channel not in self.games:
|
||||||
|
self.games[channel] = None
|
||||||
|
# We only start a new game if no other game is going on right now
|
||||||
|
if self.games[channel] is None:
|
||||||
self.games[channel] = HangmanGame()
|
self.games[channel] = HangmanGame()
|
||||||
game = self.games[channel]
|
game = self.games[channel]
|
||||||
# We only start a new game if no other game is going on right now
|
|
||||||
if not game.gameOn:
|
|
||||||
game.gameOn = True
|
|
||||||
game.timeout = self.configurables.get('timeout', channel)
|
game.timeout = self.configurables.get('timeout', channel)
|
||||||
game.timeGuess = time.time()
|
game.timeGuess = time.time()
|
||||||
game.tries = self.configurables.get('tries', channel)
|
game.tries = self.configurables.get('tries', channel)
|
||||||
@ -288,6 +286,7 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||||||
# So, a game is going on, but let's see if it's timed out. If it is
|
# So, a game is going on, but let's see if it's timed out. If it is
|
||||||
# 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]
|
||||||
secondsEllapsed = time.time() - game.timeGuess
|
secondsEllapsed = time.time() - game.timeGuess
|
||||||
if secondsEllapsed > game.timeout:
|
if secondsEllapsed > game.timeout:
|
||||||
self.endGame(channel)
|
self.endGame(channel)
|
||||||
@ -309,7 +308,7 @@ class Words(callbacks.Privmsg, configurable.Mixin):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
irc.error('There is no hangman game going on right now.')
|
irc.error('There is no hangman game going on right now.')
|
||||||
return
|
return
|
||||||
if not game.gameOn:
|
if game is None:
|
||||||
irc.error('There is no hangman game going on right now.')
|
irc.error('There is no hangman game going on right now.')
|
||||||
return
|
return
|
||||||
letter = privmsgs.getArgs(args)
|
letter = privmsgs.getArgs(args)
|
||||||
|
Loading…
Reference in New Issue
Block a user