O'Reilly logo

Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 48. Advanced User Input

In past games you handled the user’s input by simply expecting set strings. If the user typed “run” and exactly “run,” then the game worked. If they typed in a similar phrase like “run fast,” it would fail. What we need is a device that lets users type phrases in various ways and then converts that input into something the computer understands. For example, we’d like to have all of these phrases work the same way:

• open door

• open the door

• go THROUGH the door

• punch bear

• Punch The Bear in the FACE

It should be alright for a user to write something a lot like English for your game, and have your game figure out what it means. In this exercise, we’re going to write a module that does just that. This module ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required