-
Notifications
You must be signed in to change notification settings - Fork 32
/
Rock_Paper_Scissor.rb
49 lines (42 loc) · 1.36 KB
/
Rock_Paper_Scissor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def game
print "Please choose one - rock, paper or scissors: "
$input = gets.chomp
$user_input = $input.downcase
puts "You chose #{$user_input}."
#defining which choice computer makes
def computer_choice
cc = (1 + rand(3))
case cc
when 1
$choice = "rock"
when 2
$choice = "paper"
when 3
$choice = "scissors"
end
end
computer_choice
#comparing computer choice against user choice
if $user_input == $choice
puts "I chose #{$choice} too. It's a tie. Let's try again."
game
else
if $user_input == "rock" && $choice == "paper"
puts "I chose paper. Paper wraps rock. I win."
elsif $user_input == "rock" && $choice == "scissors"
puts "I chose scissors. Rock destroys scissors. You win."
elsif $user_input == "paper" && $choice == "rock"
puts "I chose rock. Paper wraps rock. You win."
elsif $user_input == "paper" && $choice == "scissors"
puts "I chose scissors. Scissors cut paper. I win."
elsif $user_input == "scissors" && $choice == "rock"
puts "I chose rock. Rock destroys scissors. I win."
elsif $user_input == "scissors" && $choice == "paper"
puts "I chose paper. Scissors cut paper. You win."
else
puts "I didn't understand you. Please try again."
game
end #end nested if statement
end #end if statement
end #end game def
game