class MAndMRps::Code

Public Class Methods

new() click to toggle source
# File lib/code.rb, line 14
def initialize
  @options = ["rock", "paper", "scissors"]
  @player1 = Human.new
end

Public Instance Methods

compare() click to toggle source
# File lib/code.rb, line 31
  def compare

    if @choice1 == @choice2
      puts "Tie. Try Again"

    elsif @choice1 == "rock"
      if @choice2 == "paper"
        outcome(2)
      else
        outcome(1)
      end

    elsif @choice1 == "paper"
      if @choice2 == "scissors"
        outcome(2)
      else
        outcome(1)
      end

    elsif @choice1 == "scissors"
      if @choice2 == "rock"
        outcome(2)
      else
        outcome(1)
      end

  end

end
outcome(val) click to toggle source
# File lib/code.rb, line 61
def outcome(val)

  if val == 1
    puts "Player 1 wins"
  else
    puts "Player 2 wins"
  end

end
play() click to toggle source
# File lib/code.rb, line 19
def play
 select_opponent

 @choice1 = @player1.choice(@options)
 p @choice1
 @choice2 = @player2.choice(@options)
 p @choice2

 compare

end
select_opponent() click to toggle source
# File lib/code.rb, line 71
def select_opponent
  puts "Is your opponent human (h) or computer?"
  choice = gets.chomp

  if choice == "h"
    @player2 = Human.new
  else
    @player2 = Computer.new
  end

end