code_brkr_game_training 0.7.5 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/code_brkr_game_training/entities/difficulty_controller.rb +2 -9
- data/lib/code_brkr_game_training/modules/file_operations.rb +13 -5
- data/lib/code_brkr_game_training/modules/statistics.rb +7 -5
- data/lib/code_brkr_game_training/version.rb +1 -1
- metadata +2 -3
- data/lib/code_brkr_game_training/data/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa7c47465b1e2c3dd28ca04daedb8541838f41b5a7a47ddeb810524e6cd18ed0
|
4
|
+
data.tar.gz: 3f8a8157e5536ba0fb345b79311ff32749a62e6924c37d36f8af15bf5b63611d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 942ce924395aed6b92b89f67cdfaa7a678e8e550dc6f1fc2680873aa9f8f9d5ca58d1c4b77b48792c617a03f4297f67248af9cf8c50d289032ea81dd30c4a47e
|
7
|
+
data.tar.gz: f7899ade2921c5b9eabff52705dcdbd21135081c6e7b63a538fcf0c6ae0fb6f4160d4325f4eed39ee5023c21da99d7bf5f134de3a7e9741c24a83c7773d561a3
|
data/Gemfile.lock
CHANGED
@@ -7,20 +7,13 @@ module CodeBrkrGameTraining
|
|
7
7
|
include Validator
|
8
8
|
|
9
9
|
GAME_DIFFICULTIES = {
|
10
|
-
|
10
|
+
hell: { name: 'hell', attempts: 5, hints: 1 },
|
11
11
|
medium: { name: 'medium', attempts: 10, hints: 1 },
|
12
|
-
|
12
|
+
easy: { name: 'easy', attempts: 15, hints: 2 }
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
attr_reader :init_values, :actual_values
|
16
16
|
|
17
|
-
def self.difficulty_levels_order
|
18
|
-
GAME_DIFFICULTIES
|
19
|
-
.values
|
20
|
-
.sort_by { |difficulty| [difficulty[:attempts], difficulty[:hints]] }
|
21
|
-
.collect { |difficulty| difficulty[:name] }
|
22
|
-
end
|
23
|
-
|
24
17
|
def initialize(difficulty_value)
|
25
18
|
@value_name = difficulty_value
|
26
19
|
validate
|
@@ -4,14 +4,16 @@
|
|
4
4
|
module CodeBrkrGameTraining
|
5
5
|
# Module for file operations
|
6
6
|
module FileOperations
|
7
|
-
def save_to_file(
|
8
|
-
|
9
|
-
|
7
|
+
def save_to_file(**args)
|
8
|
+
ensuring_directory_availability args[:directory]
|
9
|
+
|
10
|
+
yml = YAML.dump(args[:data])
|
11
|
+
File.open(File.join(args[:directory], args[:file]), 'a') { |yml_file| yml_file.write(yml) }
|
10
12
|
end
|
11
13
|
|
12
|
-
def load_from_file(
|
14
|
+
def load_from_file(directory, file)
|
13
15
|
begin
|
14
|
-
yml_data = File.open(
|
16
|
+
yml_data = File.open(File.join(directory, file), &:read)
|
15
17
|
rescue Errno::ENOENT
|
16
18
|
yml_data = ''
|
17
19
|
end
|
@@ -20,5 +22,11 @@ module CodeBrkrGameTraining
|
|
20
22
|
yml_data
|
21
23
|
)
|
22
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def ensuring_directory_availability(directory)
|
29
|
+
Dir.mkdir(directory) unless Dir.exist?(directory)
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
@@ -4,7 +4,9 @@
|
|
4
4
|
module CodeBrkrGameTraining
|
5
5
|
# Module for game stats
|
6
6
|
module Statistics
|
7
|
-
STATISTICS_FILE_PATH = File.dirname(File.expand_path(__FILE__)) + '/../data/game_stats.yml'
|
7
|
+
# STATISTICS_FILE_PATH = File.dirname(File.expand_path(__FILE__)) + '/../data/game_stats.yml'
|
8
|
+
SAVE_DIRECTORY = 'data'
|
9
|
+
SAVE_FILE = 'game_stats.yml'
|
8
10
|
|
9
11
|
def save_game_results!(user, difficulty)
|
10
12
|
difficulty_init = difficulty.init_values
|
@@ -15,16 +17,16 @@ module CodeBrkrGameTraining
|
|
15
17
|
}
|
16
18
|
game_session[:attempts_used] = game_session[:attempts_total] - difficulty_actual[:attempts]
|
17
19
|
game_session[:hints_used] = game_session[:hints_total] - difficulty_actual[:hints]
|
18
|
-
save_to_file(game_session,
|
20
|
+
save_to_file(data: game_session, directory: SAVE_DIRECTORY, file: SAVE_FILE)
|
19
21
|
end
|
20
22
|
|
21
23
|
def full_statistics
|
22
|
-
games_array = load_from_file(
|
24
|
+
games_array = load_from_file(SAVE_DIRECTORY, SAVE_FILE)
|
23
25
|
return games_array if games_array.empty?
|
24
26
|
|
25
|
-
difficulty_order = DifficultyController.
|
27
|
+
difficulty_order = DifficultyController::GAME_DIFFICULTIES.keys
|
26
28
|
games_array.sort_by do |game|
|
27
|
-
[difficulty_order.index(game[:difficulty]), game[:attempts_used], game[:hints_used]]
|
29
|
+
[difficulty_order.index(game[:difficulty].to_sym), game[:attempts_used], game[:hints_used]]
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_brkr_game_training
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fasterer
|
@@ -131,7 +131,6 @@ files:
|
|
131
131
|
- lefthook.yml
|
132
132
|
- lib/code_brkr_game_training.rb
|
133
133
|
- lib/code_brkr_game_training/bootstrap/autoloader.rb
|
134
|
-
- lib/code_brkr_game_training/data/.keep
|
135
134
|
- lib/code_brkr_game_training/entities/code.rb
|
136
135
|
- lib/code_brkr_game_training/entities/difficulty_controller.rb
|
137
136
|
- lib/code_brkr_game_training/entities/game.rb
|
File without changes
|