Class: Game

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output, messages) ⇒ Game

Returns a new instance of Game.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/game.rb', line 17

def initialize(input, output, messages)
  @answer      = Colors.new.secret_answer
  @judge       = Validate.new(@answer)
  @start_time  = Time.now
  @table       = Table.new
  @input       = input
  @output      = output
  @messages    = messages
  @command     = ''
  @guess_count = 0
  @old_guess   = []
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



7
8
9
# File 'lib/game.rb', line 7

def answer
  @answer
end

#commandObject (readonly)

Returns the value of attribute command.



7
8
9
# File 'lib/game.rb', line 7

def command
  @command
end

#guess_countObject (readonly)

Returns the value of attribute guess_count.



7
8
9
# File 'lib/game.rb', line 7

def guess_count
  @guess_count
end

#inputObject (readonly)

Returns the value of attribute input.



7
8
9
# File 'lib/game.rb', line 7

def input
  @input
end

#judgeObject (readonly)

Returns the value of attribute judge.



7
8
9
# File 'lib/game.rb', line 7

def judge
  @judge
end

#messagesObject (readonly)

Returns the value of attribute messages.



7
8
9
# File 'lib/game.rb', line 7

def messages
  @messages
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/game.rb', line 7

def output
  @output
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



7
8
9
# File 'lib/game.rb', line 7

def start_time
  @start_time
end

#tableObject (readonly)

Returns the value of attribute table.



7
8
9
# File 'lib/game.rb', line 7

def table
  @table
end

Instance Method Details

#playObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/game.rb', line 30

def play
  output.puts messages.game_start
  output.puts table.show
  until win? || lose?
    output.print messages.guess_prompt
    @command = input.gets.chomp.downcase
    guess_counter
    turn_evaluation
  end
end