Sha256: acfc49e942ef394d604d564f71a231345d8c7a667228650dbca18dcb42b148da
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true # Main Gem module module CodeBrkrGameTraining # Module for game stats module Statistics # STATISTICS_FILE_PATH = File.dirname(File.expand_path(__FILE__)) + '/../data/game_stats.yml' SAVE_DIRECTORY = 'data' SAVE_FILE = 'game_stats.yml' def save_game_results!(user, difficulty) difficulty_init = difficulty.init_values difficulty_actual = difficulty.actual_values game_session = { name: user.name, difficulty: difficulty_init[:name], attempts_total: difficulty_init[:attempts], hints_total: difficulty_init[:hints] } game_session[:attempts_used] = game_session[:attempts_total] - difficulty_actual[:attempts] game_session[:hints_used] = game_session[:hints_total] - difficulty_actual[:hints] save_to_file(data: game_session, directory: SAVE_DIRECTORY, file: SAVE_FILE) end def full_statistics games_array = load_from_file(SAVE_DIRECTORY, SAVE_FILE) return games_array if games_array.empty? difficulty_order = DifficultyController::GAME_DIFFICULTIES.keys games_array.sort_by do |game| [difficulty_order.index(game[:difficulty].to_sym), game[:attempts_used], game[:hints_used]] end end end end
Version data entries
3 entries across 3 versions & 1 rubygems