Skip to content

Latest commit

 

History

History
137 lines (107 loc) · 4.94 KB

games_supervised_score_tracker.livemd

File metadata and controls

137 lines (107 loc) · 4.94 KB

Games: Supervised Score Tracker

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

Navigation

Games: Supervised Score Tracker

You're going to setup your Games project as a supervised mix project.

Then, create a Games.ScoreTracker GenServer which will track a player score as they play different games.

Decide on point rewards for winning a game such as:

  • guessing game: 5 points
  • rock paper scissors: 10 points
  • wordle: 25 points

Increase the ScoreTracker's score whenever a user wins the game.

Requirements

  • The initial score tracker state should be 0.
  • Handle an asynchronous {:add_points, points} message to increment the score state.
  • Handle a synchronous :get_score message to retrieve the current score.
  • Games.ScoreTracker should be started as a named process by the supervisor.
  • Create the start_link/1, add_points/1, and current_score/1 functions as documented below.
  • Write a full suite of tests including at least the following cases:
    • "current_score/1 retrieves the current score"
    • "add_points/1 adds points to the score"
# Games.ScoreTracker should be a named process, so we don't need to provide the pid.
{:ok, _pid} = Games.ScoreTracker.start_link()
:ok = Games.ScoreTracker.add_points(10)
:ok = Games.ScoreTracker.add_points(10)
20 = Games.ScoreTracker.current_score()

Score Menu

Create a "score" command for the game menu that displays the user's current score. For example:

$ ./games
What game would you like to play?
1. Guessing Game
2. Rock Paper Scissors
3. Wordle

enter "stop" to exit
enter "score" to view your current score
score

==================================================
Your score is 0
==================================================

What game would you like to play?
1. Guessing Game
2. Rock Paper Scissors
3. Wordle

enter "stop" to exit
enter "score" to view your current score

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: Supervised Score Tracker 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