Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Typing Game

exercises/typing_game.livemd

Typing Game

Mix.install([
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"},
  {:tested_cell, github: "brooklinjazz/tested_cell"},
  {:utils, path: "#{__DIR__}/../utils"}
])

Navigation

Return Home Report An Issue

Setup

Ensure you type the ea keyboard shortcut to evaluate all Elixir cells before starting. Alternatively you can evaluate the Elixir cells as you read.

Typing Game

You’re going to create a typing game which helps players practice their typing speed. If a player does not type a word in time, the game will end and restart.

A process will prompt the user for input every five seconds. They must enter the prompted word. If they do not enter the word within five seconds, or if they enter the word incorrectly then the game will crash and restart.

You may use any random list of words. For example: ["red", "blue", "green", "orange", "yellow", "pink"]. Remember that you can retrieve input from the console using IO.get/2.

The player should be able to load your game into the IEx shell, and enter the prompted word.

$ mix run --no-halt
Your word: red
red
Your word: blue
bluw
Your word: red

Create a mix project with a supervisor in your projects folder and create your game.

$ mix new typing_game --sup

Bonus: Terminate

Use the GenServer.terminate/2 callback to print a message in the console when the game crashes.

$ mix run --no-halt
Your word: red
rad
You lose!
Your word: blue

Bonus: Score

For each successful word store a score in memory. When the game crashes, use the GenServer.terminate/2 callback to print the score to the player.

$ mix run --no-halt
Your word: red
5
4
2
red
Your word: blue
5
4
3
2
1
Score: 1
Your word: yellow

Bonus: Countdown

Count down from five in the console as the player enters their word.

$ mix run --no-halt
Your word: red
5
4
2
red
Your word: red
5
4
3
2
1
You lose!
Your word: blue

Commit Your Progress

Run the following in your command line from the beta_curriculum folder to track and save your progress in a Git commit.

$ git add .
$ git commit -m "finish typing game exercise"

Up Next

Previous Next
Creature Spawner Rdbms