Class: Bnardy::RockPaperScissors

Inherits:
Object
  • Object
show all
Defined in:
lib/bnardy.rb

Instance Method Summary collapse

Constructor Details

#initializeRockPaperScissors

Returns a new instance of RockPaperScissors.



10
11
12
13
14
15
16
17
18
# File 'lib/bnardy.rb', line 10

def initialize


	@cpu_move = ['rock', 'paper', 'scissors'].sample
	@player_move = player_move
	run


end

Instance Method Details

#cpu_winsObject



50
51
52
53
54
# File 'lib/bnardy.rb', line 50

def cpu_wins

	puts "CPU wins! #{@cpu_move} beats #{@player_move}"

end

#outcome(player_move) ⇒ Object



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bnardy.rb', line 58

def outcome ( player_move )

	unless tie?



		if @cpu_move == "rock"

			if @player_move == "paper"

				player_wins

			elsif @player_move == "scissors"

				cpu_wins

			end




		elsif @cpu_move == "paper"

			if @player_move == "rock"

				cpu_wins

			elsif @player_move == "scissors"

				player_wins

			end



		elsif @cpu_move == "scissors"

			if @player_move == "rock"

				player_wins

			elsif @player_move == "paper"

				cpu_wins

			end

		end



	end #/.unless
end

#player_winsObject



42
43
44
45
46
# File 'lib/bnardy.rb', line 42

def player_wins

	puts "Player wins! #{@player_move} beats #{@cpu_move}"

end

#runObject



20
21
22
23
24
25
26
27
28
# File 'lib/bnardy.rb', line 20

def run

	puts "Please enter rock, paper or scissors"
   @player_move = gets.strip.downcase
   outcome( @player_move )



end

#tie?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/bnardy.rb', line 31

def tie?
	if @cpu_move == @player_move

		puts "Tie! Both players had #{@cpu_move}"

	end

end