Class: CodebrackerSimb::Game

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

Overview

game cl

Constant Summary collapse

ERR_UNEXPECTED_COMPLEXITY =
'complexity could be easy, medium or hard'
IS_OVER =
'Game is over, you lose'
GREETING =
'Hello! Welcome to CodeBracker Game! Have fun!'
CONGRATULATIONS =
'Congratulations! You broked a code, master!'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(complexity) ⇒ Game

Returns a new instance of Game.



18
19
20
# File 'lib/codebracker_simb/game.rb', line 18

def initialize(complexity)
  @attempts = attempts(complexity)
end

Instance Attribute Details

#answerObject

Returns the value of attribute answer.



11
12
13
# File 'lib/codebracker_simb/game.rb', line 11

def answer
  @answer
end

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/codebracker_simb/game.rb', line 9

def code
  @code
end

Instance Method Details

#playObject



22
23
24
25
26
27
28
29
30
# File 'lib/codebracker_simb/game.rb', line 22

def play
  define_code
  loop do
    input_answer
    result =  Checker.new(code, answer).compare
    refresh_attempts_quantity
    break if win? || @attempts == 0
  end
end