Sha256: ddfc10826f0ebc5651f3d6c565d3c821fef5e12362107ff0d14cba110cbaacda
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 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, time: DateTime.now, 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
code_brkr_game_training-0.9.2 | lib/code_brkr_game_training/modules/statistics.rb |