Let's play hangman
Game Interactions |
Word Display |
Scaffold Display |
Computer displays a word for the user to guess and an "empty" scaffold. | _ _ _ _ _ | Scaffold with no body parts. |
User guesses 'X': | ||
Computer displays: | _ _ _ _ _ | Scaffold with a head |
User guesses 'E': | ||
Computer displays: | _ _ _ _ _ | Scaffold with a head and a torso |
User guesses 'A' | ||
Computer displays: | _ _ _ _ A | Scaffold with a head, and a torso |
User guesses 'R' | ||
Computer displays: | _ _ _ _ A | Scaffold with a head, a torso, and a right arm |
etc... | ||
We are to write a program that plays hangman as shown. What are the components of such a program?
At a very high level, the program
accepts a user's input,
performs some internal computations based on the input, and
displays the results in some useful forms.
The above functionalities of the program must be delineated and encapsulated in separate components in order to achieve a high degree of flexibility and extensibility. A tried-and-true design pattern, called Model-View-Controller (MVC), is best suited for programs like the above.
The MVC design pattern calls for breaking up programs that interact with the users and display the results based on the users' inputs into three major components.
The Model: the data structures and algorithms on the structures.
The View: the display, which may be a GUI or non-GUI.
The Controller: the "wiring" between the Model and the View.
What data structures do we need for Hangman?