Anonymous avatar Anonymous committed 7c94d66

The branching story now works.

Comments (0)

Files changed (1)

branching_story.py

 """)
 
 wood = [
-['you car', 	'withered leaves', 	0,			0, 	0], 
-[0, 		'the rabbit hill', 	'dark underbrush', 	0, 	0], 
+['your car', 	'withered leaves', 	0,			0, 	0], 
+[0, 		'the rabbit hill', 	'the dark underbrush', 	0, 	0], 
 [0, 		'the angry boar', 	'the campsite', 	0, 	0], 
 [0, 		0, 			0, 			0, 	0], 
 [0, 		0, 			0, 			0, 	0]
 ]
 
-def get_text(name):
+location_descriptions = {
+'your car': """
+You reach your car and leave the woods, 
+but a memory of old trees, dark shadows and wonder remains.
+""", 
+'the angry boar': """
+As you enter a darker region of the woods, you hear the rustling of leaves behind you. 
+Minutes later, you still don't quite know, how you escaped, 
+but the boar doesn't follow you anymore. 
+"""
+}
+# TODO: Write text for all locations. 
+
+def get_description(name):
     """Get the text for each locations name"""
-    return name # TODO: Get the text from a dict. 
+    if name in location_descriptions: 
+        return location_descriptions[name]
+    else: 
+        return name 
 
 class Path(object):
     def __init__(self):
-        self.position = [3, 3]
-        self.target = [1, 1]
-    def pos_to_name(self, pos=[3, 3]):
+        self.position = (2, 2)
+        self.target = (0, 0)
+    def pos_to_name(self, pos=(2, 2)):
         """return the location name for a position."""
-        return wood[pos[0]][pos[1]]
+        return wood[pos[1]][pos[0]]
     def move(self):
         x, y = self.position
         # specify possible movement. 
-        move = {
-        'north': (x, y + 1), # up
-        'south': (x, y - 1), # down
+        directions = {
+        'north': (x, y - 1), # up
+        'south': (x, y + 1), # down
         'west': (x - 1, y),  # left
         'east': (x + 1, y)  # right
         }
-        question = 'Where do you want to go? '
+        question = 'Where do you want to go? ('
         answers = []
         # get all possible answers by checking if the ways are possible. 
-        for i, j in move.items():
-            print i, j
-            if wood[j[0]][j[1]]:
+        for i, j in directions.items():
+            if wood[j[1]][j[0]]:
                 answers.append(i)
-        question = " ".join([question] + answers + [":"])
+        question = " ".join([question] + answers + [")"])
         description = "\n".join(['to the ' + i + ' you see ' + 
-self.pos_to_name(move[i]) for i in answers])
+self.pos_to_name(directions[i]) for i in answers])
         story(description)
         target = ""
-        while not target:   
+        while not target:  
+            story("", autoscroll=True)
             ans = ask(question)
             for i in answers: 
-                if ans in [i.lower(), i.lower[0]]: 
-                    target = move[i]
+                name = wood[directions[i][1]][directions[i][0]]
+                if ans.lower() in [i.lower(), i.lower()[0], name, " ".join(name.split()[1:])]: 
+                    target = directions[i]
         self.position = target
         story("""You go to """ + self.pos_to_name(self.position))
-        story(get_text(self.pos_to_name(self.position)))
+        story(get_description(self.pos_to_name(self.position)))
 
 path = Path()
 while not path.position == path.target:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.