-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtutorial5.py
More file actions
88 lines (70 loc) · 2.09 KB
/
Copy pathtutorial5.py
File metadata and controls
88 lines (70 loc) · 2.09 KB
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
84
85
86
87
88
#!/usr/bin/python
#
# Tutorial 5 shows how to add containers like cabinets to your game.
#
from advent import *
# import advent_devtools for helpers you can use when running locally (not in trinket.io)
import advent_devtools
# import random module for random numbers
import random
# We'll start out with our familiar brightworks entryway:
game = Game("Brightworks Adventure")
sidewalk = game.new_location(
"Sidewalk",
"There is a large glass door to the east. The sign says 'Come In!'")
vestibule = game.new_location(
"Vestibule",
"""A small area at the bottom of a flight of stairs.
There is a glass door to the west and door to the south.""")
office = game.new_location(
"Office",
"""A nicely organized office.
There is a door to the north.""")
game.new_connection("Glass Door", sidewalk, vestibule, [IN, EAST], [OUT, WEST])
game.new_connection("Office Door", vestibule, office, [IN, SOUTH], [OUT, NORTH])
key = sidewalk.new_object("key", "a small tarnished key")
player = game.new_player(sidewalk)
#
# Containers are objects that can hold other objects inside.
#
file_cabinet = office.add_object(Container("file cabinet",
"a rusty old metal file cabinet"))
#
# Let's put something into the Container
#
file_cabinet.new_object("secret plan",
"""secret plans to convert Brightworks into a
military academy for cyber-warfare specialists""")
#
# Containers can also be locked. Once they are unlocked they
# can be opened and the objects inside can be examined and taken.
# Locking Containers works the same as locking Locations or
# Connections. You can use add_requirement([objects]) or can lock
# it explicitly and unlock with a custom verb.
#
file_cabinet.make_requirement(key)
# add our player to the game
game.add_actor(player)
# and let's add a test to check the code we wrote above:
test_script = Script("test",
"""
> go in
> s
> look
> open file cabinet
> n
> out
> take key
> in
> s
> examine file cabinet
> open file cabinet
> examine file cabinet
> examine secret plan
> take secret plan
> inventory
> look
> end
""")
player.add_script(test_script)
game.run()