Class: Codebreaker::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(score = 0) ⇒ Player

Returns a new instance of Player.



4
5
6
7
8
# File 'lib/codebreaker/player.rb', line 4

def initialize(score = 0)
  @name = input_name
  @player_code = ''
  @score = score
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#player_codeObject

Returns the value of attribute player_code.



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

def player_code
  @player_code
end

#scoreObject

Returns the value of attribute score.



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

def score
  @score
end

Instance Method Details

#agree?Boolean

Returns:



15
16
17
# File 'lib/codebreaker/player.rb', line 15

def agree?
  input =~ /^yes|y/i ? true : false
end

#guessObject



10
11
12
13
# File 'lib/codebreaker/player.rb', line 10

def guess
  print 'Type your secret code or "hint": '
  @player_code = input_code
end