Class: CodebrackerSimb::Game
- Inherits:
-
Object
- Object
- CodebrackerSimb::Game
- 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.
19 20 21 22 23 |
# File 'lib/codebracker_simb/game.rb', line 19 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
29 30 31 |
# File 'lib/codebracker_simb/game.rb', line 29 def check_answer Checker.new(code, answer).compare end |
#define_code ⇒ Object
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
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_quantity ⇒ Object
41 42 43 44 45 46 |
# File 'lib/codebracker_simb/game.rb', line 41 def refresh_attempts_quantity if @attempts > 0 @attempts -= 1 = "#{@attempts} left" end end |