Sha256: 4631f977ce6ff5532a09b34e13f1aa90f37987c6ba72a965aa355c8ba18f1b5a
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true require 'yaml' require_relative 'user' class Stats def self.save_game(user) @data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : [] @data << user File.new('stats.yml', 'w') unless File.exist?('stats.yml') File.open('stats.yml', 'w') { |file| file.write(@data.to_yaml) } end def self.show_stats @data = File.exist?('stats.yml') ? YAML.load_file('stats.yml') : [] @data.sort_by! { |user| [user.attempts[:all], user.attempts[:used], user.hints[:used]] } @data.each_with_index do |user, index| stats_format(user, index) end end def self.stats_format(user, index) index += 1 puts "Rating: #{index}", "Name: #{user.name}", "Difficulty: #{Settings::DIFFICULTY.key({ attempts: user.attempts[:all], hints: user.hints[:all] })}", "Available Attempts: #{user.attempts[:all]}", "Used Attempts: #{user.attempts[:used]}", "Available Hints: #{user.hints[:all]}", "Used Hints: #{user.hints[:used]}", '-----------------------' end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
codebreaker_kirill-1.0.2 | lib/codebreaker_kirill/stats.rb |
codebreaker_kirill-1.0.1 | lib/codebreaker_kirill/stats.rb |
codebreaker_kirill-1.0.0 | lib/codebreaker_kirill/stats.rb |