Commits

Anonymous committed 9e077b9

branching story: code made more readable.

Comments (0)

Files changed (1)

branching_story.py

         self.story = story
         #: The function to use for talking to the user. 
         self.ask = ask
+
     def pos_to_name(self, pos=(2, 2)):
         """return the location name for a position."""
         return self.maze[pos[1]][pos[0]]
+
     def describe(self, name):
         """Get the text for each locations name"""
         if self.description_type == "text": 
                 return 
         # If we find no descriptions, just return the name. 
         self.story(name)
+
     def move(self):
         x, y = self.position
         # specify possible movement. 
         question = _('Where do you want to go?') + ' ('
         answers = []
         # get all possible answers by checking if the ways are possible. 
+
         for i, j in directions.items():
             if self.maze[j[1]][j[0]]:
                 answers.append(i)
+
         question = " ".join([question] + answers + [")"])
         description = "\n".join(['to the ' + i + ' you see ' + 
 self.pos_to_name(directions[i]) for i in answers])
         self.story(description)
+
         target = ""
         # Ask the user until he/she supplies a valid answer. 
+
         while not target:  
             self.story("", autoscroll=True)
             ans = self.ask(question).strip() # removing any whitespace before the first letter
                 name = self.maze[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
         self.story("""You go to """ + self.pos_to_name(self.position))
         self.describe(self.pos_to_name(self.position))
 if __name__ == "__main__": 
 # Get the path to move in. 
     path = Path(    start=(2,2), # Where we begin. 
-                    target=(0,0), # Where the maze ends. 
+                    target=(0,0), # Where the maze ends. TODO: target-list
                     maze=wood, # The maze in which we move
                     descriptions=location_descriptions, # Descriptions for the named locations in the maze. 
                     description_type = "text", # The maze descriptions are simple text strings.