Elegant command-parsing in an OOP-based text game

前端 未结 5 1390
情话喂你
情话喂你 2021-02-09 01:52

I\'m playing with writing a MUD/text adventure (please don\'t laugh) in Ruby. Can anyone give me any pointers towards an elegant, oop-based solution to parsing input text? <

5条回答
  •  情书的邮戳
    2021-02-09 02:35

    Sounds like you need a parser.

    Split the input string into tokens (words). Then feed the tokens, one at a time, to a state machine. I find that the push-down automata is rather intuitive and powerful way to write such an stm.

提交回复
热议问题