Class: Codebreaker::Player
- Inherits:
-
Object
- Object
- Codebreaker::Player
- Defined in:
- lib/codebreaker/player.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#player_code ⇒ Object
Returns the value of attribute player_code.
-
#score ⇒ Object
Returns the value of attribute score.
Instance Method Summary collapse
- #agree? ⇒ Boolean
- #guess ⇒ Object
-
#initialize(score = 0) ⇒ Player
constructor
A new instance of Player.
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
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/codebreaker/player.rb', line 3 def name @name end |
#player_code ⇒ Object
Returns the value of attribute player_code.
3 4 5 |
# File 'lib/codebreaker/player.rb', line 3 def player_code @player_code end |
#score ⇒ Object
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
15 16 17 |
# File 'lib/codebreaker/player.rb', line 15 def agree? input =~ /^yes|y/i ? true : false end |
#guess ⇒ Object
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 |