1616
1717
1818############################
19- # Game Data (Doesn't Change)
19+ # Game Data
2020
2121locations = {
2222 "The Town Square" : {
2323 "description" : ("The centre of your home town, there is a fountain in "
2424 "the middle and you're surrounded by trees!" ),
2525 "neighbors" : {
2626 "S" : "The Town South Gate" ,
27- "N" : "The Town Hall Entrance"
27+ "N" : "The Town Hall Entrance" ,
28+ "E" : "The Town Jail"
2829 }
2930 },
3031 "The Town South Gate" : {
4344 "The Town Hall" : {
4445 "description" : "Nothing interesting going on in here..." ,
4546 "neighbors" : {
46- "S" : "The Town Hall Entrance" ,
47+ "S" : "The Town Hall Entrance"
48+ }
49+ },
50+ "The Town Jail" : {
51+ "description" : "There's some nasty people in here." ,
52+ "neighbors" : {
53+ "W" : "The Town Square" ,
54+ "E" : "Jail Cell"
55+ }
56+ },
57+ "Jail Cell" : {
58+ "description" : "..." ,
59+ "neighbors" : {
60+ "W" : "The Town Jail"
4761 }
4862 }
4963}
5771 'W' : 'West'
5872}
5973
60-
61- ##########################
62- # Game State (Does Change)
63-
6474player = {
6575 "location" : "The Town Square"
6676}
@@ -73,7 +83,8 @@ def cmd_help():
7383 "help" : "Show this help Page" ,
7484 "quit" : "Quit the game" ,
7585 "go" : "Walk either N, E, S or W, e.g: 'go N'" ,
76- "describe" : "Descript the current location"
86+ "describe" : "Descript the current location" ,
87+ "look" : "Take a look at what's around you"
7788 }
7889
7990 print "Available Commands:"
@@ -123,6 +134,22 @@ def cmd_go(cmd):
123134 cmd_describe ()
124135
125136
137+ def cmd_look ():
138+
139+ # Current Location
140+ cmd_describe ()
141+
142+ # The dictionary of neighbors for our current location
143+ neighbors = locations [player ["location" ]]['neighbors' ]
144+
145+ if len (neighbors ) == 0 :
146+ print "You can't go anywhere from here!"
147+ else :
148+ print "Where you can go from here:"
149+ for direction , location in neighbors .items ():
150+ print " " + direction + ": " + location
151+
152+
126153############
127154# Start Game
128155
@@ -154,6 +181,8 @@ def cmd_go(cmd):
154181 cmd_go (cmd )
155182 elif cmd [0 ] == 'describe' :
156183 cmd_describe ()
184+ elif cmd [0 ] == 'look' :
185+ cmd_look ()
157186 else :
158187 print "Unknown Command: '" + cmd [0 ] + "'"
159188 cmd_help ()
0 commit comments