class VcsBkTdrRps::Player

Constants

CHOICES

Attributes

hand[RW]
name[R]

Public Class Methods

new(name, comp = false) click to toggle source
# File lib/vcs_bk_tdr_rps/player.rb, line 7
def initialize(name, comp = false)
  @name = name
  @hand = false
  @comp = comp
end

Public Instance Methods

display_choices() click to toggle source
# File lib/vcs_bk_tdr_rps/player.rb, line 13
def display_choices
  CHOICES.each_with_index { |choice, i| puts "#{i}: #{choice}" }
end
set_hand() click to toggle source
# File lib/vcs_bk_tdr_rps/player.rb, line 17
def set_hand
  @comp ? @hand = CHOICES.sample : @hand = throw_hand
end

Private Instance Methods

throw_hand() click to toggle source
# File lib/vcs_bk_tdr_rps/player.rb, line 27
def throw_hand
  hand = 'wrong'
  until valid_hand?(hand)
    puts "Please choose the hand you want to throw..."
    display_choices
    hand = gets.chomp
  end
  hand
end
valid_hand?(hand) click to toggle source
# File lib/vcs_bk_tdr_rps/player.rb, line 23
def valid_hand?(hand)
  CHOICES.include? hand.downcase
end