forked from lordmauve/adventurelib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_game.py
83 lines (65 loc) · 1.75 KB
/
demo_game.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from adventurelib import *
Room.items = Bag()
current_room = starting_room = Room("""
You are in a dark room.
""")
valley = starting_room.north = Room("""
You are in a beautiful valley.
""")
magic_forest = valley.north = Room("""
You are in a enchanted forest where magic grows wildly.
""")
mallet = Item('rusty mallet', 'mallet')
valley.items = Bag({mallet,})
inventory = Bag()
@when('north', direction='north')
@when('south', direction='south')
@when('east', direction='east')
@when('west', direction='west')
def go(direction):
global current_room
room = current_room.exit(direction)
if room:
current_room = room
say('You go %s.' % direction)
look()
if room == magic_forest:
set_context('magic_aura')
else:
set_context('default')
@when('take ITEM')
def take(item):
obj = current_room.items.take(item)
if obj:
say('You pick up the %s.' % obj)
inventory.add(obj)
else:
say('There is no %s here.' % item)
@when('drop THING')
def drop(thing):
obj = inventory.take(thing)
if not obj:
say('You do not have a %s.' % thing)
else:
say('You drop the %s.' % obj)
current_room.items.add(obj)
@when('look')
def look():
say(current_room)
if current_room.items:
for i in current_room.items:
say('A %s is here.' % i)
@when('inventory')
def show_inventory():
say('You have:')
for thing in inventory:
say(thing)
@when('cast', context='magic_aura', magic=None)
@when('cast MAGIC', context='magic_aura')
def cast(magic):
if magic == None:
say("Which magic you would like to spell?")
elif magic == 'fireball':
say("A flaming Fireball shoots form your hands!")
look()
start()