class PaperRockScissors::Game

Constants

SYMBOLS

Public Class Methods

new(players=1) click to toggle source
# File lib/paper_rock_scissors/game.rb, line 7
def initialize(players=1)
  @player1 = Human.new
  if players == 1
    @player2 = Computer.new
  else
    @player2 = Human.new
  end
end

Public Instance Methods

check_winner(move1, move2) click to toggle source
# File lib/paper_rock_scissors/game.rb, line 33
def check_winner(move1, move2)
  if SYMBOLS[move1] == move2
    puts "Player 1 is the winner!"
  else
    puts "Player 2 is the winner!"
  end
end
play() click to toggle source
# File lib/paper_rock_scissors/game.rb, line 16
def play
  loop do
    move1 = @player1.get_move

    move2 = @player2.get_move

    if move1 == move2
      puts "Tie! Try again!"
      next
    else
      check_winner(move1, move2)
    end

    break
  end
end