From 0272d06a3c46fb569455bfd34aa65fadc7fa9300 Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 01:39:21 -0800 Subject: Added e2 tile containing a wizard's challenge for a flaming torch. --- weatbag/tiles/e2.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 weatbag/tiles/e2.py (limited to 'weatbag') diff --git a/weatbag/tiles/e2.py b/weatbag/tiles/e2.py new file mode 100644 index 0000000..b71bc5e --- /dev/null +++ b/weatbag/tiles/e2.py @@ -0,0 +1,36 @@ +from weatbag import words +import random + +class Tile: + def __init__(self): + self.contents = {'flaming torch': 1} + self.lucky_number = random.randrange(1,100) + + def describe(self): + if self.contents['flaming torch']: + self.challenge() + else: + print("You see a pile of dust on the ground.") + + def challenge(self): + print("A wizard suddenly appears and says 'If you guess my " + "lucky number, I might give you a reward!'") + print("Say 'guess' followed by a number between 1-100 to guess.") + + def action(self, player, do): + if do[0] == "guess" and self.contents['flaming torch']: + guess = int(do[1]) + if guess > self.lucky_number: + print("Too high! Guess again!") + elif guess < self.lucky_number: + print("Too low! Guess again!") + else: + print("You guessed my lucky number!") + print("The wizard hands you a flaming torch! " + "He then suddenly vanishes, leaving behind a pile of dust.") + self.contents['flaming torch'] -= 1 + player.give('flaming torch') + elif (do[0] in words.take): + print("You can't have my prize, you have to guess the lucky number!") + else: + print("Sorry, I don't understand.") -- cgit v1.3 From d2c76307481938fe10cdec93a833b5b9f0577b13 Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 02:35:32 -0800 Subject: Error handling for invalid guesses in wizard's challenge. --- weatbag/tiles/e2.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'weatbag') diff --git a/weatbag/tiles/e2.py b/weatbag/tiles/e2.py index b71bc5e..a501985 100644 --- a/weatbag/tiles/e2.py +++ b/weatbag/tiles/e2.py @@ -19,17 +19,20 @@ class Tile: def action(self, player, do): if do[0] == "guess" and self.contents['flaming torch']: - guess = int(do[1]) - if guess > self.lucky_number: - print("Too high! Guess again!") - elif guess < self.lucky_number: - print("Too low! Guess again!") - else: - print("You guessed my lucky number!") - print("The wizard hands you a flaming torch! " - "He then suddenly vanishes, leaving behind a pile of dust.") - self.contents['flaming torch'] -= 1 - player.give('flaming torch') + try: + guess = int(do[1]) + if guess > self.lucky_number: + print("Too high! Guess again!") + elif guess < self.lucky_number: + print("Too low! Guess again!") + else: + print("You guessed my lucky number!") + print("The wizard hands you a flaming torch! " + "He then suddenly vanishes, leaving behind a pile of dust.") + self.contents['flaming torch'] -= 1 + player.give('flaming torch') + except: + print("Please try guessing a number, like 'guess 7'.") elif (do[0] in words.take): print("You can't have my prize, you have to guess the lucky number!") else: -- cgit v1.3