Class: CodeBreakerGemHoltobinAnton::Game
- Inherits:
-
Object
- Object
- CodeBreakerGemHoltobinAnton::Game
- Defined in:
- lib/code_breaker_gem_holtobin_anton.rb
Constant Summary collapse
- SECRET_CODE_SIZE =
4
Instance Attribute Summary collapse
-
#choice_did ⇒ Object
Returns the value of attribute choice_did.
-
#choice_size ⇒ Object
Returns the value of attribute choice_size.
-
#hint_used ⇒ Object
Returns the value of attribute hint_used.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#secret_code ⇒ Object
readonly
Returns the value of attribute secret_code.
-
#user_code ⇒ Object
Returns the value of attribute user_code.
Instance Method Summary collapse
- #end_game ⇒ Object
- #hint ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #inspection_game ⇒ Object
- #start ⇒ Object
- #submit ⇒ Object
Methods included from View
#attempts_ended, #end_game_mess, #hint_mess, #print_marking, #restart_game_mess?, #start_mess
Methods included from GameIO
Methods included from DataCheck
#check_attempts_ended?, #check_for_match, #check_victory?, #data_checking?
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
89 90 91 92 93 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 89 def initialize @choice_size = 10 @secret_code, @user_code, @result = '', '', '' @hint_used, @choice_did = 0, 0 end |
Instance Attribute Details
#choice_did ⇒ Object
Returns the value of attribute choice_did.
81 82 83 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 81 def choice_did @choice_did end |
#choice_size ⇒ Object
Returns the value of attribute choice_size.
81 82 83 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 81 def choice_size @choice_size end |
#hint_used ⇒ Object
Returns the value of attribute hint_used.
81 82 83 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 81 def hint_used @hint_used end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
82 83 84 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 82 def result @result end |
#secret_code ⇒ Object (readonly)
Returns the value of attribute secret_code.
82 83 84 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 82 def secret_code @secret_code end |
#user_code ⇒ Object
Returns the value of attribute user_code.
81 82 83 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 81 def user_code @user_code end |
Instance Method Details
#end_game ⇒ Object
114 115 116 117 118 119 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 114 def end_game attempts_ended if(check_attempts_ended?) str = check_victory??end_game_mess('won') : end_game_mess('lost') save_game(str) false end |
#hint ⇒ Object
121 122 123 124 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 121 def hint @hint_used += 1 hint_mess(@secret_code[rand(4)]) end |
#inspection_game ⇒ Object
108 109 110 111 112 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 108 def inspection_game return end_game if(check_attempts_ended?) return end_game if(check_victory?) true end |
#start ⇒ Object
95 96 97 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 95 def start @secret_code = SECRET_CODE_SIZE.times.map{1 + Random.rand(6)}.join end |
#submit ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/code_breaker_gem_holtobin_anton.rb', line 99 def submit @result = '' begin puts 'Please enter :' end while data_checking?(@user_code = gets.chomp) check_for_match @choice_did += 1 end |