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

Games Project

games_rock_paper_scissors.livemd

Games Project

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

Create A New Mix Project

Using the command line, create a new project in the projects folder called games.

mix new games

Create A Rock Paper Scissors Game

You’re going to create a rock paper scissors game where players will play against an AI which randomly chooses rock, paper, or scissors.

You should be able to start your project by running the following from the game folder in the command line.

iex -S mix

Then you can play the game in a Games.RockPaperScissors module. Each time the player plays the game, it should generate a random choice for the opponent, and display a custom message of your choosing to let the player know they won or lost.

# randomly generated :scissors for the opponent
iex> Games.RockPaperScissors.play(:rock)
"You win! :rock beats :scissors."

# randomly generated :paper for the opponent
iex> Games.RockPaperScissors.play(:rock)
"You lose! :paper beats :rock."

# randomly generated :rock for the opponent
iex> Games.RockPaperScissors.play(:rock)
"It's a tie!"

(Bonus) Save Score

Ever time you play, you should save a running total of your wins, loses, and draws. You should be able to retrieve the current tally like so:

Game.RockPaperScissors.score()
%{wins: 1, loses: 1, draws: 0}

You may choose to persist the score between sessions (using the file system), or keep a running tally in memory (using a process).

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 games rock paper scissors exercise"

Up Next

Previous Next
Journal Cli Exunit