class RckPprScssrs::RockPaperScissors

Constants

OPTIONS

Public Instance Methods

computer_input() click to toggle source
# File lib/rck_ppr_scssrs.rb, line 49
def computer_input
  @computer = ["rock", "paper", "scissors"].sample
  puts "Computer: #{@computer}"
end
game_type() click to toggle source
# File lib/rck_ppr_scssrs.rb, line 32
def game_type
  puts "Do you want to play against the computer(c) or another player(p)?"
  type = gets.chomp
end
match(player, computer) click to toggle source
# File lib/rck_ppr_scssrs.rb, line 56
def match(player, computer)
  if player == computer
    puts "It's a tie"
  elsif player == "rock"
    if computer == "scissors"
      puts "Rock beats Scissors!"
    else
      puts "Paper beats Rock!"
    end
  elsif player == "scissors"
    if computer == "rock"
      puts "Rock beats Scissors!"
    else
      puts "Scissors beats Paper!"
    end
  elsif player == "paper"
    if computer == "rock"
      puts "Paper beats Rock!"
    else
      puts "Scissors beats Paper!"
    end
  end     
end
play_game() click to toggle source
# File lib/rck_ppr_scssrs.rb, line 11
def play_game
  start
  type = game_type
  if type == 'c'
    player_input
    computer_input
    match(@player, @computer)
  else
    player1 = player_input
    player2 = player_input
    match(player1, player2)
  end
end
player_input() click to toggle source
# File lib/rck_ppr_scssrs.rb, line 38
def player_input
  puts "What is your choice?"
  @player = gets.chomp

  until OPTIONS.include? @player
    puts "Please enter one of the following: rock, paper, scissors"
    @player = gets.chomp
  end
end
start() click to toggle source
# File lib/rck_ppr_scssrs.rb, line 26
def start
  puts "Welcome to Rock, Paper, Scissors!"
  puts "Rock beats Scissors, Scissors beats Paper, and Paper beats Rock"
end