-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockpaper.rb
86 lines (75 loc) · 1.96 KB
/
rockpaper.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class RockPaperEnemy
attr_accessor :chosen_one
def initialize
@choices = %w[rock paper scissors]
@chosen_one = @choices[rand(0..2)]
puts "You chose #{@chosen_one}"
end
def compare(other_choice)
case other_choice
when "rock"
if @chosen_one == "paper"
puts "You Lost, paper beats rock"
elsif @chosen_one == "rock"
puts "Tie! rock and rock"
else
puts "You win, rock beats scissors"
end
when "paper"
if @chosen_one == "paper"
puts "Tie! paper and paper"
elsif @chosen_one == "rock"
puts "You win, paper beats rock"
else
puts "You lose, scissors beats paper"
end
when "scissors"
if @chosen_one == "paper"
puts "You win, scissors beats paper"
elsif @chosen_one == "rock"
puts "You lose, rock beats scissors"
else
puts "Tie! scissors and scissors"
end
end
end
end
class RockPaperSelf
attr_accessor :chosen_one
def initialize
@choices = %w[rock paper scissors]
@chosen_one = @choices[rand(0..2)]
puts "They chose #{@chosen_one}"
end
def compare(other_choice)
case other_choice
when "rock"
if @chosen_one == "paper"
puts "You Lost, paper beats rock"
elsif @chosen_one == "rock"
puts "Tie! rock and rock"
else
puts "You win, rock beats scissors"
end
when "paper"
if @chosen_one == "paper"
puts "Tie! paper and paper"
elsif @chosen_one == "rock"
puts "You win, paper beats rock"
else
puts "You lose, scissors beats paper"
end
when "scissors"
if @chosen_one == "paper"
puts "You win, scissors beats paper"
elsif @chosen_one == "rock"
puts "You lose, rock beats scissors"
else
puts "Tie! scissors and scissors"
end
end
end
end
their_choice = RockPaperEnemy.new
your_choice = RockPaperSelf.new
your_choice.compare(their_choice.chosen_one)