Class: RpsGameDavidxin::Player

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Player

Returns a new instance of Player.



92
93
94
# File 'lib/rps_game_davidxin.rb', line 92

def initialize(name)
  @name = name
end

Instance Method Details

#is_input_valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/rps_game_davidxin.rb', line 107

def is_input_valid?(input)
  ["r", "p", "s"].include?(input)
end

#turnObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/rps_game_davidxin.rb', line 96

def turn
  is_valid = false
  until is_valid
    print "#{@name} - Enter your move ([R]ock, [P]aper, or [S]cissors): "
    input = gets.chomp.downcase
    is_valid = is_input_valid?(input)
    puts "Please enter 'r' 'p' or 's' to play" unless is_valid
  end
  return input
end