-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
48 lines (41 loc) · 1.13 KB
/
app.rb
File metadata and controls
48 lines (41 loc) · 1.13 KB
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
ROCK = 0
PAPER = 1
SCISSORS = 2
QUIT = 'Q'
CONVERSION = {
'R' => ROCK,
'P' => PAPER,
'S' => SCISSORS
}.freeze
NUMBER_CONVERSION = {
ROCK => 'Rock',
PAPER => 'Paper',
SCISSORS => 'Scissors'
}.freeze
NUM_CHOICES = 3
loop do
computer_choice = rand(3) # 0, 1, or 2
puts "Let's play Rock, Paper, Scissors!"
puts 'Enter your choice: (R)ock, (P)aper, (S)cissors, or (Q)uit'
puts 'If you enter a wrong option, we will play Rock for you!'
user_choice = gets.chomp
break if user_choice == QUIT
choice = CONVERSION[user_choice] || ROCK
puts "You chose #{NUMBER_CONVERSION[choice]} and the computer chose #{NUMBER_CONVERSION[computer_choice]}"
case computer_choice
when ROCK
puts 'You win!' if choice == PAPER
puts 'You lose!' if choice == SCISSORS
puts "It's a tie!" if choice == ROCK
when PAPER
puts 'You win!' if choice == SCISSORS
puts 'You lose!' if choice == ROCK
puts "It's a tie!" if choice == PAPER
when SCISSORS
puts 'You win!' if choice == ROCK
puts 'You lose!' if choice == PAPER
puts "It's a tie!" if choice == SCISSORS
end
puts '==================='
puts "\n" * 10
end