Class: CodebrackerSimb::Game
- Inherits:
-
Object
- Object
- CodebrackerSimb::Game
- 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
-
#answer ⇒ Object
Returns the value of attribute answer.
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
Instance Method Summary collapse
- #check_answer ⇒ Object
- #define_code ⇒ Object
- #end_with_win? ⇒ Boolean
-
#initialize(complexity, player) ⇒ Game
constructor
A new instance of Game.
- #input_answer(input) ⇒ Object
- #refresh_attempts_quantity ⇒ Object
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 = (complexity)[:attempts] @hints = (complexity)[:hints] @player = player end |
Instance Attribute Details
#answer ⇒ Object
Returns the value of attribute answer.
12 13 14 |
# File 'lib/codebracker_simb/game.rb', line 12 def answer @answer end |
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
10 11 12 |
# File 'lib/codebracker_simb/game.rb', line 10 def attempts @attempts end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
9 10 11 |
# File 'lib/codebracker_simb/game.rb', line 9 def code @code end |
#player ⇒ Object (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_answer ⇒ Object
32 33 34 |
# File 'lib/codebracker_simb/game.rb', line 32 def check_answer Checker.new(code, answer).compare end |
#define_code ⇒ Object
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
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_quantity ⇒ Object
44 45 46 47 48 49 |
# File 'lib/codebracker_simb/game.rb', line 44 def refresh_attempts_quantity if @attempts > 0 @attempts -= 1 = "#{@attempts} left" end end |