Powered by AppSignal & Oban Pro

Games: Menu

exercises/games_menu.livemd

Games: Menu

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue ExecutablesAdvanced Pattern Matching

Games: Menu

In your existing Games project, you’re going to create a Games.Menu module which allows players to select which game they would like to play.

$ iex -S mix
iex> Games.Menu.display()
Select a game:
1. Guessing Game
2. Rock Paper Scissors
3. Wordle
Select: 

Depending on their choice, this let the player play either the Guessing Game, Rock Paper Scissors, or Wordle games you have already created.

Select a game:
1. Guessing Game
2. Rock Paper Scissors
3. Wordle
Select: 3
Enter a five letter word:  

Games: Escript

Configure your game as an Escript. You’ll need to create a Games.CLI module with a main/1 function to display the Games.Menu.

defmodule Games.CLI do
  def main(args) do
    Games.Menu.display()
  end
end

And configure the Games.CLI module using the :escript option inside of the Games.MixProject.project/0 function.

  def project do
    [
      ...
      escript: [main_module: Games.CLI]
    ]
  end

You should be able to build and start the games project as an escript.

$ mix escript.build
$ ./games
Select a game:
1. Guessing Game
2. Rock Paper Scissors
3. Wordle
Select: 

Bonus: Finish Game

Allow the user to type "stop" to end any game. They should then be re-prompted with the menu to select the game they want to play.

Select a game:
1. Guessing Game
2. Rock Paper Scissors
3. Wordle
Select: 1
Enter your guess:
stop
Select a game:
1. Guessing Game
2. Rock Paper Scissors
3. Wordle
Select: 

This may require custom stop logic in each existing game.

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Games: Menu exercise"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue ExecutablesAdvanced Pattern Matching