Class: Codebreaker::Game
- Inherits:
-
Object
- Object
- Codebreaker::Game
- Defined in:
- lib/codebreaker/game.rb
Constant Summary collapse
- ATTEMPTS =
7- HINT =
1- CODE_SIZE =
4- RANGE =
1..6
Instance Attribute Summary collapse
-
#attempts ⇒ Object
Returns the value of attribute attempts.
-
#hint ⇒ Object
Returns the value of attribute hint.
-
#player ⇒ Object
Returns the value of attribute player.
-
#secret_code ⇒ Object
Returns the value of attribute secret_code.
Instance Method Summary collapse
-
#initialize(player = Player.new) ⇒ Game
constructor
A new instance of Game.
- #start ⇒ Object
Methods included from Score
Methods included from Engine
Constructor Details
#initialize(player = Player.new) ⇒ Game
12 13 14 15 16 17 18 19 |
# File 'lib/codebreaker/game.rb', line 12 def initialize(player = Player.new) @secret_code = Array.new(CODE_SIZE) { rand(RANGE) }.join @player = player @hint = HINT @attempts = ATTEMPTS start end |
Instance Attribute Details
#attempts ⇒ Object
Returns the value of attribute attempts.
11 12 13 |
# File 'lib/codebreaker/game.rb', line 11 def attempts @attempts end |
#hint ⇒ Object
Returns the value of attribute hint.
11 12 13 |
# File 'lib/codebreaker/game.rb', line 11 def hint @hint end |
#player ⇒ Object
Returns the value of attribute player.
11 12 13 |
# File 'lib/codebreaker/game.rb', line 11 def player @player end |
#secret_code ⇒ Object
Returns the value of attribute secret_code.
11 12 13 |
# File 'lib/codebreaker/game.rb', line 11 def secret_code @secret_code end |
Instance Method Details
#start ⇒ Object
21 22 23 24 25 26 |
# File 'lib/codebreaker/game.rb', line 21 def start puts "You have #{@attempts} attempts and #{@hint} hint." check_guess score new_game? ? start : save_score? end |