Class: Rpsshoot::Player

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

Direct Known Subclasses

Computer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, name) ⇒ Player

Returns a new instance of Player.



8
9
10
11
# File 'lib/rpsshoot/player.rb', line 8

def initialize(symbol, name)
  @symbol = symbol
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#symbolObject (readonly)

Returns the value of attribute symbol.



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

def symbol
  @symbol
end

Instance Method Details

#shootObject

Each player takes a turn



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rpsshoot/player.rb', line 14

def shoot
  options = ["rock", "paper", "scissors"]
  puts "#{@name} please enter rock, paper or scissors: (or 'quit' to exit)"
  selection = STDIN.noecho(&:gets).chomp
  if options.include?(selection)
    selection
  elsif selection.downcase == "quit"
    exit
  else
    puts "I'm sorry, that wasn't a valid selection."
    shoot
  end
end