Last active
March 25, 2017 18:50
-
-
Save ZebTheWizard/3c84d89e0bfc4e412a1855838e31206e to your computer and use it in GitHub Desktop.
Ruby | Rock Paper Scissors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gameIsRunning = true | |
$score_computer = 0 | |
$score_player = 0 | |
$score_ties = 0 | |
showScore = false | |
choices = ["rock", "paper", "scissors"] | |
def start | |
puts "--------------------------------------------------------" | |
puts " R O C K P A P E R S C I S S O R S " | |
puts "--------------------------------------------------------" | |
puts " - CREATED BY CRITICAL" | |
puts " " | |
puts "There once was a young boy who lived peacfully with his | |
\rfamily. His family always struggled with money, but one | |
\rday that all changed. He was challenged by a robot to | |
\rplay the classic game \"Rock Paper Scissors\". If the boy | |
\rone the robot would print him $100,000,000, so he | |
\raccepted challenge. | |
" | |
end | |
def menu(x=nil) | |
system "clear" or system "cls" | |
start() if x == "start" | |
puts "--------------------------------------------------------" | |
puts " H E L P M E N U " | |
puts "--------------------------------------------------------" | |
puts " - H, HELP Show the help screen" | |
puts " - P, PAPER Choose paper " | |
puts " - Q, QUIT Quit the game " | |
puts " - R, ROCK Choose rock " | |
puts " - S, SCISSORS Choose scissors " | |
puts "" | |
end | |
def score() | |
system "clear" or system "cls" | |
puts "--------------------------------------------------------" | |
puts " S C O R E B O A R D " | |
puts "--------------------------------------------------------" | |
puts " - PLAYER #{$score_player} " | |
puts " - COMPUTER #{$score_computer} " | |
puts " - TIES #{$score_ties} " | |
puts "" | |
end | |
# determine who the winner is. | |
# winner = what the computer needs to be to win. | |
# tie = what the computer needs to be to tie. | |
def winner?(winner, tie) | |
if $computer == winner | |
$score_computer +=1 | |
else | |
$computer == tie ? $score_ties +=1 : $score_player +=1 | |
end | |
end | |
menu("start") | |
while gameIsRunning do | |
score() if showScore | |
print "> " | |
$player = gets.chomp.downcase | |
$computer = choices[Random.rand(3)] | |
case $player | |
when "rock", "paper", "scissors", "r", "p", "s" | |
system "clear" or system "cls" | |
showScore = true | |
winner?("paper", "rock") if $player == "rock" || $player == "r" | |
winner?("scissors", "paper") if $player == "paper" || $player == "p" | |
winner?("rock", "scissors") if $player == "scissors" || $player == "s" | |
when "quit", "q" | |
showScore = false | |
gameIsRunning = false | |
when "help", "h" | |
showScore = false | |
menu() | |
else | |
puts "THIS IS NOT AN OPTION.\nUse 'H' or 'HELP' to get help.\n" | |
end | |
end | |
system "clear" or system "cls" | |
puts "--------------------------------------------------------" | |
puts " S E E Y O U S O O N " | |
puts "--------------------------------------------------------" | |
puts "" | |
sleep 1 | |
system "clear" or system "cls" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment