Skip to content

Instantly share code, notes, and snippets.

@logankilpatrick
Created January 2, 2022 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logankilpatrick/e6bccf4a413ba6303533895d1246e768 to your computer and use it in GitHub Desktop.
Save logankilpatrick/e6bccf4a413ba6303533895d1246e768 to your computer and use it in GitHub Desktop.
# Rock πŸ—Ώ, Paper πŸ“ƒ, Scissors βœ‚οΈ Game in Julia
function play_rock_paper_scissors()
moves = ["πŸ—Ώ", "πŸ“ƒ", "βœ‚οΈ"]
computer_move = moves[rand(1:3)]
# Base.prompt is similar to readline which we used before
human_move = Base.prompt("Please enter πŸ—Ώ, πŸ“ƒ, or βœ‚οΈ")
# Appends a ": " to the end of the line by default
print("Rock...")
sleep(0.8)
print("Paper...")
sleep(0.8)
print("Scissors...")
sleep(0.8)
print("Shoot!\n")
if computer_move == human_move
print("You tied, please try again")
elseif computer_move == "πŸ—Ώ" && human_move == "βœ‚οΈ"
print("You lose, the computer won with πŸ—Ώ, please try again")
elseif computer_move == "πŸ“ƒ" && human_move == "πŸ—Ώ"
print("You lose, the computer won with πŸ“ƒ, please try again")
elseif computer_move == "βœ‚οΈ" && human_move == "πŸ“ƒ"
print("You lose, the computer won with βœ‚οΈ, please try again")
else
print("You won, the computer lost with $computer_move, nice work!")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment