Class: Rockpaperscissors::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/rockpaperscissors/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(player_id) ⇒ Player

Returns a new instance of Player.



6
7
8
# File 'lib/rockpaperscissors/player.rb', line 6

def initialize(player_id)
  @player_id = player_id
end

Instance Attribute Details

#choiceObject

Returns the value of attribute choice.



3
4
5
# File 'lib/rockpaperscissors/player.rb', line 3

def choice
  @choice
end

#player_idObject (readonly)

Returns the value of attribute player_id.



4
5
6
# File 'lib/rockpaperscissors/player.rb', line 4

def player_id
  @player_id
end

Instance Method Details

#moveObject



10
11
12
13
14
15
16
17
18
19
20
# 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