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, player) ⇒ Game

Returns a new instance of Game.



19
20
21
22
23
# File 'lib/codebracker_simb/game.rb', line 19

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



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

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

#define_codeObject



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

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

#end_with_win?Boolean

Returns:

  • (Boolean)


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

def end_with_win?
  code == answer 
end

#input_answer(input) ⇒ Object



25
26
27
# File 'lib/codebracker_simb/game.rb', line 25

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

#refresh_attempts_quantityObject



41
42
43
44
45
46
# File 'lib/codebracker_simb/game.rb', line 41

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