Module: Rpss

Defined in:
lib/rpss.rb,
lib/rpss/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.compare_to_paperObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rpss.rb', line 65

def self.compare_to_paper
	cmove = computer_move

	if cmove == "scissors"
		puts "Scissors cuts paper. You Lose :( "
	elsif cmove == "rock"
		puts "Paper covers rock. You Win!! "
	else 
		puts "Its a tie "
	end
end

.compare_to_rockObject

Then we see who wins by comparing the player selection to the computer selection!



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rpss.rb', line 53

def self.compare_to_rock 
	cmove = computer_move

	if cmove == "scissors"
		puts "Rock smashes scissors. You Win!! "
	elsif cmove == "paper"
		puts "Paper covers rock. You Lose :( "
	else 
		puts "Its a tie "
	end
end

.compare_to_scissorsObject



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rpss.rb', line 77

def self.compare_to_scissors
	cmove = computer_move

	if cmove == "rock"
		puts "Rock smashes scissors. You Lose :( "
	elsif cmove == "paper"
		puts "Scissors cut paper. You Win!! "
	else 
		puts "Its a tie "
	end
end

.computer_moveObject

The computer will then also randomly select an option.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rpss.rb', line 36

def self.computer_move
	random_number = rand(9)

	if random_number < 3
		cmove = "rock"
		elsif random_number > 5
			cmove = "scissors"
		else 
			cmove = "paper"
	end 

	puts "The computer threw: #{cmove}" 
	return cmove
end

.start_gameObject

Welcome to Rock Paper Scissors Shoot! Start by picking rock, paper or scissors



6
7
8
9
# File 'lib/rpss.rb', line 6

def self.start_game 
	puts "Welcome to Rock, Paper, Scissors!"
	take_turn
end

.take_turnObject



16
17
18
19
20
# File 'lib/rpss.rb', line 16

def self.take_turn
	print "Enter your move:  "
	move = gets.strip.to_s.downcase
	validate_move(move)
end

.validate_move(move) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rpss.rb', line 22

def self.validate_move(move)
	if move == "rock" 
		compare_to_rock
	elsif move == "scissors"
		compare_to_scissors
	elsif move == "paper"
		compare_to_paper
	else 
		print "invalid entry. Please enter 'rock', 'paper', or 'scissors'.  "
	end 
end