The classic game brought to life with Ruby, Sinatra, and Bootstrap 3.
Play the game here on Heroku.
- Words
- The game uses a library of words provided in
/resources/enable.txt
- This word list is used to populate an array
$words
in/resources/words.rb
- This file and array are built using a small ruby script in
/resources/build.rb
- $words is an array of child arrays that contain words with string lengths equal to the value of the index of the child array in $words
- The game uses a library of words provided in
- Difficulty
- The difficulty selection is enabled and populated only with the index of child arrays that are not empty
- When the user selects a difficulty, the Game object uses this integer to select a child array from $words
- Word
- The word choosen for each game is selected randomly by a 2 fold method:
- Generating a random index using
rand()
with the size of the array as the argument - Shuffling the word array before retrieving a word from it with the above random index
- Generating a random index using
- The word choosen for each game is selected randomly by a 2 fold method:
- State
- The
Game
class in/lib/game.rb
uses the Sinatraparams
object to determine the state of the game - The state keeps track of:
- The last guessed letter
- All other letter guesses
- Difficulty selected
- The
- Scoring
- Player lives are set directly equal to
5 - ${INCORRECT_GUESSES}
- The game is lost after 5 incorrect guesses are made
- The game is won when all letters have been correctly guessed
- Player lives are set directly equal to
- Art
- Art work is completely ASCII and output in a
<pre>
tag to preserve white-space - The art work changes color from green to red with each lost life
- Art work is completely ASCII and output in a
- Hidden Cheat
- The game is equipped with a hidden cheat to view the current word for debugging and fun of course
- Routes
- There is only 1
GET
route used:'/'
- The game is completely reliant on form input parameters being preserved in the URL
- While
POST
would be more secure from tampering, I wanted to useGET
as an exercise
- There is only 1
- Ruby
- While JavaScript could provide more interaction and indeed be used to run this game entirely, I chose specifically to not use it
- The logic and calculations for this game are all delibrately written in Ruby