Class: CodeBreakerGemHoltobinAnton::Game

Inherits:
Object
  • Object
show all
Includes:
DataCheck, GameIO, View
Defined in:
lib/code_breaker_gem_holtobin_anton.rb

Constant Summary collapse

SECRET_CODE_SIZE =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from View

#attempts_ended, #end_game_mess, #hint_mess, #print_marking, #restart_game_mess?, #start_mess

Methods included from GameIO

#save_game

Methods included from DataCheck

#check_attempts_ended?, #check_for_match, #check_victory?, #data_checking?

Constructor Details

#initializeGame

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_didObject

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_sizeObject

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_usedObject

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

#resultObject (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_codeObject (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_codeObject

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_gameObject



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

#hintObject



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_gameObject



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

#startObject



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

#submitObject



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