Class: MastermindRuby::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/mastermind_ruby/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_countObject (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

#startObject

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.display_welcome_message(@playername)
  run
end