lib/alex_codebreaker/session.rb in alex_codebreaker-0.1.13 vs lib/alex_codebreaker/session.rb in alex_codebreaker-0.2.0
- old
+ new
@@ -10,10 +10,11 @@
:difficulty_name, :attempts_total, :difficulty_level, :time
def initialize
@attempts_used = INITIAL_ATTEMPTS_USED
@hints_used = INITIAL_HINTS_USED
+ @time = Time.new
end
def add_name(given_name)
@player_name = given_name if name_validation(given_name)
end
@@ -32,20 +33,22 @@
@hints_used += 1 if @hints_used < @hints_total
end
def check_attempts
@attempts_used += 1
- return unless @attempts_used < @attempts_total
+ return if @attempts_used >= @attempts_total
- @attempts_used
+ true
end
def save_winner_statistic
@time = Time.new
check_folder_existence
path = "#{AlexCodebreaker.configuration.winners_folder_path}#{WINNERS_FILE_NAME}"
File.open(path, 'a') { |file| file.write(to_yaml) }
end
+
+ private
def check_folder_existence
return if File.directory?(AlexCodebreaker.configuration.winners_folder_path)
FileUtils.mkdir_p(AlexCodebreaker.configuration.winners_folder_path)