class Rockpaperscissors::Player

Attributes

choice[RW]
player_id[R]

Public Class Methods

new(player_id) click to toggle source
# File lib/rockpaperscissors/player.rb, line 6
def initialize(player_id)
  @player_id = player_id
end

Public Instance Methods

move() click to toggle source
# File lib/rockpaperscissors/player.rb, line 10
def move
  self.choice = nil
  until valid_input?
    print "Player #{player_id}, choose rock ('R'), paper ('P') or scissors ('S')\n > "
    self.choice = gets.chomp.upcase
    unless valid_input?
      print "That's not an allowed move!\n"
    end
  end
  self.choice
end

Private Instance Methods

valid_input?() click to toggle source
# File lib/rockpaperscissors/player.rb, line 24
def valid_input?
  ["R","P","S"].include? self.choice
end