class Game

Rock, Paper, Scissors

Public Instance Methods

get_comp_select() click to toggle source
# File lib/paper_rocks_scissors/game.rb, line 14
def get_comp_select
    selection = rand(3)
    selection
end
get_player_select(input) click to toggle source
# File lib/paper_rocks_scissors/game.rb, line 19
def get_player_select(input)
  if input.downcase == "scissors"
      value = 0
  elsif input.downcase == "paper"
      value = 1
  elsif input.downcase == "rock"
      value = 2
  end
  value
end
initiliaze() click to toggle source
# File lib/paper_rocks_scissors/game.rb, line 3
def initiliaze
end
play() click to toggle source
# File lib/paper_rocks_scissors/game.rb, line 30
def play
  puts "Please choose between Rock, Paper, or Scissors"
  input = gets.chomp
  if valid_input(input)
    comp_select = get_comp_select
    player_select = get_player_select(input)
    action, msg = "", ""
    if comp_select + player_select == 1
        action = "Scissors cut Paper!"
    elsif comp_select + player_select == 2
        action = "Rock crushes Scissors!"
    elsif comp_select + player_select == 3
        action = "Paper covers Rock!"
    end
    if player_select - comp_select == -1 or player_select - comp_select == 2
        msg = "Player Wins"
    elsif comp_select == player_select
        msg = "It's a tie"
    else
        msg = "The Computer Wins"
    end
    comp_str = ["scissors", "paper", "rock"][comp_select]
    player_str = ["scissors", "paper", "rock"][player_select]
    puts "Player chooses #{player_str}, the Computer chooses #{comp_str}"
    puts action
    puts msg
    puts
  else
    Game.new.play
  end
end
valid_input(input="") click to toggle source
# File lib/paper_rocks_scissors/game.rb, line 6
def valid_input(input="")
  options = ["scissors", "paper", "rock"]
  if input == "q"
    exit
  end
    options.include? input.downcase
end