class DjmhRockPaperScissors::Game

Constants

KEY

Human and Computer classes inherit from Player both need their own get_move methods

Public Class Methods

new() click to toggle source

keys defeat values

# File lib/djmh_rock_paper_scissors/game.rb, line 20
def initialize 
  welcome_message
  initialize_players
end

Public Instance Methods

compare(player_1_move,player_2_move) click to toggle source
# File lib/djmh_rock_paper_scissors/game.rb, line 47
def compare(player_1_move,player_2_move)
  if KEY[player_1_move]==player_2_move
    victory_message(@player_1)
  elsif KEY[player_2_move]==player_1_move
    victory_message(@player_2)
  else
    tie_message
  end
end
initialize_players() click to toggle source
# File lib/djmh_rock_paper_scissors/game.rb, line 29
def initialize_players
  num_players = gets.chomp
  if num_players=="1"
    @player_1=Human.new(1)
    @player_2=Computer.new(2)
  elsif num_players == "2"
    @player_1=Human.new(1)
    @player_2=Human.new(2)
  end
end
play() click to toggle source
# File lib/djmh_rock_paper_scissors/game.rb, line 40
def play
  @player_1.turn
  @player_2.turn
  compare(@player_1.move,@player_2.move)
end
tie_message() click to toggle source
# File lib/djmh_rock_paper_scissors/game.rb, line 61
def tie_message
  puts "It's a tie!"
end
victory_message(player) click to toggle source
# File lib/djmh_rock_paper_scissors/game.rb, line 57
def victory_message(player)
  puts "Player #{player.player_number} wins!"
end
welcome_message() click to toggle source
# File lib/djmh_rock_paper_scissors/game.rb, line 25
def welcome_message 
  puts "Welcome to the game! How many players?"
end