class SchoetlrGem::Game
Attributes
choice[RW]
opponent[RW]
player[RW]
Public Class Methods
new()
click to toggle source
# File lib/schoetlr_gem.rb, line 32 def initialize puts "We're gonna play rock, paper, scissors." puts "Do you want to play another person or the computer? (person/computer)" @opponent = gets.chomp @player1 = Player.new if @opponent == "person" @player2 = Player.new elsif @opponent == "computer" @player2 = Computer.new end end
Public Instance Methods
check_round(choice1, choice2)
click to toggle source
# File lib/schoetlr_gem.rb, line 56 def check_round(choice1, choice2) if choice1 == "rock" && choice2 == "paper" puts "#{choice2} wins!" return true elsif choice1 == "paper" && choice2 == "rock" puts "#{choice1} wins!" return true elsif choice1 == "rock" && choice2 == "scissors" puts "#{choice1} wins!" return true elsif choice1 == "scissors" && choice2 == "rock" puts "#{choice1} wins!" return true elsif choice1 == "rock" && choice2 == "rock" puts "No one won :(" return true elsif choice1 == "paper" && choice2 == "scissors" puts "#{choice2} wins!" return true elsif choice1 == "scissors" && choice2 == "paper" puts "#{choice1} wins!" return true elsif choice1 == "paper" && choice2 == "paper" puts "No one wins :(" return true elsif choice1 == "scissors" && choice2 == "scissors" puts "No one wins :(" return true end end
get_hand()
click to toggle source
# File lib/schoetlr_gem.rb, line 45 def get_hand puts "What do you want to choose Player 1?" @player1.hand = gets.chomp.downcase end
opp_get_hand()
click to toggle source
# File lib/schoetlr_gem.rb, line 50 def opp_get_hand 100.times {puts "\n"} puts "What do you want to choose Player 2?" @player2.hand = gets.chomp.downcase end
play()
click to toggle source
# File lib/schoetlr_gem.rb, line 87 def play self.get_hand self.opp_get_hand if @opponent == "person" self.check_round(@player1.hand, @player2.hand) end