class AlexCodebreaker::Session
Constants
- INITIAL_ATTEMPTS_USED
- INITIAL_HINTS_USED
- WINNERS_FILE_NAME
Attributes
attempts_total[R]
attempts_used[R]
difficulty_level[R]
difficulty_name[R]
hints_total[R]
hints_used[R]
player_name[R]
time[R]
Public Class Methods
new()
click to toggle source
# File lib/alex_codebreaker/session.rb, line 12 def initialize @attempts_used = INITIAL_ATTEMPTS_USED @hints_used = INITIAL_HINTS_USED @time = Time.new end
Public Instance Methods
add_difficulty(difficulty)
click to toggle source
# File lib/alex_codebreaker/session.rb, line 22 def add_difficulty(difficulty) difficulty_level = AlexCodebreaker::Modules::DifficultyLevels::DIFFICULTY_LEVELS[difficulty.downcase.to_sym] return unless difficulty_level @difficulty_name = difficulty_level[:name] @difficulty_level = difficulty_level[:level] @attempts_total = difficulty_level[:attempts_total] @hints_total = difficulty_level[:hints_total] end
add_name(given_name)
click to toggle source
# File lib/alex_codebreaker/session.rb, line 18 def add_name(given_name) @player_name = given_name if name_validation(given_name) end
check_attempts()
click to toggle source
# File lib/alex_codebreaker/session.rb, line 36 def check_attempts @attempts_used += 1 return if @attempts_used >= @attempts_total true end
check_hints()
click to toggle source
# File lib/alex_codebreaker/session.rb, line 32 def check_hints @hints_used += 1 if @hints_used < @hints_total end
save_winner_statistic()
click to toggle source
# File lib/alex_codebreaker/session.rb, line 43 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 Instance Methods
check_folder_existence()
click to toggle source
# File lib/alex_codebreaker/session.rb, line 52 def check_folder_existence return if File.directory?(AlexCodebreaker.configuration.winners_folder_path) FileUtils.mkdir_p(AlexCodebreaker.configuration.winners_folder_path) end