Class: MastermindRuby::Game
- Inherits:
-
Object
- Object
- MastermindRuby::Game
- Defined in:
- lib/mastermind_ruby/game.rb
Instance Attribute Summary collapse
-
#try_count ⇒ Object
readonly
Returns the value of attribute try_count.
Instance Method Summary collapse
-
#initialize(ui, solution: nil) ⇒ Game
constructor
A new instance of Game.
-
#start ⇒ Object
Method to start a game Requests by calling :read_playername on the UI for the playername Requests by calling :read_code_length on the UI for the code_length Requests by calling :display_welcome_message on the UI for displaying the welcome message.
Constructor Details
#initialize(ui, solution: nil) ⇒ Game
Returns a new instance of Game.
5 6 7 8 9 10 |
# File 'lib/mastermind_ruby/game.rb', line 5 def initialize(ui, solution: nil) @solution_code = solution @ui = ui @try_count = 1 @started = false end |
Instance Attribute Details
#try_count ⇒ Object (readonly)
Returns the value of attribute try_count.
3 4 5 |
# File 'lib/mastermind_ruby/game.rb', line 3 def try_count @try_count end |
Instance Method Details
#start ⇒ Object
Method to start a game Requests by calling :read_playername on the UI for the playername Requests by calling :read_code_length on the UI for the code_length Requests by calling :display_welcome_message on the UI for displaying the welcome message
16 17 18 19 20 21 22 23 |
# File 'lib/mastermind_ruby/game.rb', line 16 def start @started = true @playername = @ui.read_playername @code_length = @ui.read_code_length @solution_code ||= Code.random(@code_length) @ui.(@playername) run end |