Commits

Brandon Rhodes committed be26fdf

When Michael Foord playtested, I realized that noun.verb() should be possible!

  • Participants
  • Parent commits 11c8287

Comments (0)

Files changed (4)

adventure/game.py

                 self.write_message(43)
             return self.finish_turn()
 
-        if word1 == 'enter' and word2:
+        if (word1 == 'enter' or word1 == 'walk') and word2:
             #2800  'enter house' becomes simply 'house' and so forth
             word1, word2 = word2, None
 
             verb, noun = word1, None
         elif kinds == ('verb', 'noun'):
             verb, noun = word1, word2
+        elif kinds == ('noun', 'verb'):
+            noun, verb = word1, word2
         else:
             return self.dont_understand()
 

adventure/prompt.py

         words = arg.words if isinstance(arg, ReprTriggeredPhrase) else (arg,)
         return ReprTriggeredPhrase(self.game, self.words + words)
 
+    def __getattr__(self, name):
+        return ReprTriggeredPhrase(self.game, self.words + (name,))
+
 
 def install_words(game):
     # stack()[0] is this; stack()[1] is adventure.play(); so, stack()[2]

adventure/tests/syntax.txt

+>>> import adventure
+>>> adventure.play(seed=2)
+WELCOME TO ADVENTURE!!  WOULD YOU LIKE INSTRUCTIONS?
+<BLANKLINE>
+>>> no
+YOU ARE STANDING AT THE END OF A ROAD BEFORE A SMALL BRICK BUILDING.
+AROUND YOU IS A FOREST.  A SMALL STREAM FLOWS OUT OF THE BUILDING AND
+DOWN A GULLY.
+<BLANKLINE>
+>>> brief
+OKAY, FROM NOW ON I'LL ONLY DESCRIBE A PLACE IN FULL THE FIRST TIME
+YOU COME TO IT.  TO GET THE FULL DESCRIPTION, SAY "LOOK".
+<BLANKLINE>
+
+This doctest exercises all of the different ways that people try to
+invoke Adventure commands from the Python prompt.
+
+Simple movement can be invoked simply by typing the direction, but some
+players will try to call them as functions instead.
+
+>>> s
+YOU ARE IN A VALLEY IN THE FOREST BESIDE A STREAM TUMBLING ALONG A
+ROCKY BED.
+<BLANKLINE>
+>>> n()
+YOU'RE AT END OF ROAD AGAIN.
+<BLANKLINE>
+
+That pretty much exhausts the possibilities when a word is being used
+alone as a command.  But when two words are being combined, there are
+several different ways that they might be called!
+
+One word can be used as a function and the second as an argument:
+
+>>> goto(building)
+YOU ARE INSIDE A BUILDING, A WELL HOUSE FOR A LARGE SPRING.
+<BLANKLINE>
+THERE ARE SOME KEYS ON THE GROUND HERE.
+<BLANKLINE>
+THERE IS A SHINY BRASS LAMP NEARBY.
+<BLANKLINE>
+THERE IS FOOD HERE.
+<BLANKLINE>
+THERE IS A BOTTLE OF WATER HERE.
+<BLANKLINE>
+
+Or, a period can be used to separate the words.  Note that nouns and
+verbs can be in either order.
+
+>>> get.keys
+OK
+<BLANKLINE>
+>>> lamp.get
+OK
+<BLANKLINE>
+
+Why do we support putting the noun and verb in either order?  Because
+some users think of verbs as methods supported by the game's nouns, and
+will format their commands like method calls:
+
+>>> food.get()
+OK
+<BLANKLINE>

adventure/tests/test_walks.py

         os.unlink('advent.save')  # to avoid an error during README.txt
     tests.addTests(doctest.DocFileSuite(
             '../README.txt', optionflags=doctest.NORMALIZE_WHITESPACE))
+    tests.addTests(doctest.DocFileSuite('syntax.txt'))
     tests.addTests(doctest.DocFileSuite('vignettes.txt'))
     tests.addTests(doctest.DocFileSuite('walkthrough1.txt'))
     tests.addTests(doctest.DocFileSuite('walkthrough2.txt'))