class RockPapScissors::Game
Attributes
computer[RW]
human[RW]
Public Class Methods
new()
click to toggle source
# File lib/rock_pap_scissors.rb, line 9 def initialize @human = Human.new @computer = Computer.new end
Public Instance Methods
display_winner()
click to toggle source
# File lib/rock_pap_scissors.rb, line 18 def display_winner if human.move > computer.move puts "#{human} won!" elsif computer.move > human.move puts "#{computer} won!" else puts "It's a tie!" end end
play()
click to toggle source
To kickstart the game - Game.new
.play
# File lib/rock_pap_scissors.rb, line 35 def play welcome_msg loop do human.choose computer.choose display_winner break if play_again? != true end end
play_again?()
click to toggle source
# File lib/rock_pap_scissors.rb, line 28 def play_again? puts "Do you want to play again ? (y/n)" ret = gets.chomp return true if ret == 'y' end
welcome_msg()
click to toggle source
# File lib/rock_pap_scissors.rb, line 14 def welcome_msg puts 'Welcome to Rock/Paper/Scissors' end