Search⌘ K

Draw the Gallows

Explore how to programmatically draw the gallows and stick figure in a Ruby hangman game. Understand how to update the drawing according to the number of player errors, using Ruby's syntax for conditional visual elements. This lesson helps you improve game presentation by incrementally displaying the hangman's parts as mistakes increase.

We'll cover the following...

A hangman game without a drawing of the gallows is not that great. Let’s now draw the traditional image that is drawn when we play hangman, which is that of a gallows with a stick figure. Part of this image is drawn every time a player gives a wrong answer until the figure is complete, at which point the player loses.

Our drawing is going to be pretty simple, as shown below:

 _____
|/   |
|    O
|   /|\   
|    |
|   / \ 
|___________
...