Class: CodebrackerSimb::Game

Inherits:
Object
  • Object
show all
Includes:
Codebracker::CodeValidator, Codebracker::NameValidator
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, player) ⇒ Game

Returns a new instance of Game.



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

def initialize(complexity, player)
  @attempts = set_options(complexity)[:attempts]
  @hints = set_options(complexity)[:hints]
  @player = player
end

Instance Attribute Details

#answerObject

Returns the value of attribute answer.



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

def answer
  @answer
end

#attemptsObject (readonly)

Returns the value of attribute attempts.



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

def attempts
  @attempts
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#playerObject (readonly)

Returns the value of attribute player.



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

def player
  @player
end

Instance Method Details

#check_answerObject



32
33
34
# File 'lib/codebracker_simb/game.rb', line 32

def check_answer
  Checker.new(code, answer).compare
end

#define_codeObject



36
37
38
# File 'lib/codebracker_simb/game.rb', line 36

def define_code
  @code = Array.new(4) { rand(1..6) }
end

#end_with_win?Boolean

Returns:



40
41
42
# File 'lib/codebracker_simb/game.rb', line 40

def end_with_win?
  code == answer 
end

#input_answer(input) ⇒ Object



28
29
30
# File 'lib/codebracker_simb/game.rb', line 28

def input_answer(input)
  @answer = Code.new(input)
end

#refresh_attempts_quantityObject



44
45
46
47
48
49
# File 'lib/codebracker_simb/game.rb', line 44

def refresh_attempts_quantity
  if @attempts > 0
    @attempts -= 1
    message = "#{@attempts} left"
  end
end