Elegant command-parsing in an OOP-based text game

前端 未结 5 1386
情话喂你
情话喂你 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:19

    Split it into tokens as the format will always be:
    [command] [object1] ([refering] [object2])

    You could call method [command] on the [object1] in your room and pass it the [object2] if applicable.

提交回复
热议问题