summaryrefslogtreecommitdiffstats
path: root/weatbag/tiles/e2.py
blob: 68798b31356ba92addfdd09f41cf16839490471c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from weatbag import words
import random

class Tile:
    def __init__(self):
        self.contents = {'unlit torch': 1}
        self.lucky_number = random.randrange(1,100)
        self.guess_count = 0
    
    def describe(self):
        if self.contents['unlit torch']:
            self.challenge()
        else: 
            print("You see a pile of dust on the ground.")

    def challenge(self): 
        print("A dwarf suddenly appears and says 'If you guess my "
            "lucky number, I might give you a reward!'")
        print("To make a guess, type 'guess' followed by a number "
            "between 1-100.")
    
    def action(self, player, do):
        if do[0] == "guess" and self.contents['unlit torch']: 
            try: 
                if do[1] == "correctly": 
                    print("You sly dog, you!")
                    print("The dwarf hands you a torch! "
                        "He then suddenly vanishes, "
                        "leaving behind a pile of dust.")
                    self.contents['unlit torch'] -= 1
                    player.give('unlit torch')
                    return

                guess = int(do[1])
                self.guess_count += 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 in %d guesses!" % 
                        (self.guess_count))
                    print("The dwarf hands you a torch! "
                        "He then suddenly vanishes, "
                        "leaving behind a pile of dust.")
                    self.contents['unlit torch'] -= 1
                    player.give('unlit torch')
            except: 
                print("Please try guessing a number, like 'guess 7'.")

        #if action is "take" AND there is still a dwarf around to complain,
        #then complain.
        elif (do[0] in words.take) and (self.contents['unlit torch'] == 1):
            print("You can't have my prize, "
                "you have to guess the lucky number!")
        else:
            print("Sorry, I don't understand.")