codebreaker_bo 0.1.6 → 0.1.7
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/data/statistic.yml +13 -13
- data/lib/codebreaker/config.rb +8 -0
- data/lib/codebreaker/console.rb +125 -0
- data/lib/codebreaker/const.rb +24 -0
- data/lib/codebreaker/game.rb +4 -4
- data/lib/codebreaker/statistic.rb +7 -3
- data/lib/codebreaker/test_console.rb +28 -0
- data/lib/codebreaker/version.rb +1 -1
- data/lib/codebreaker.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bb25b1b330862296d60fc3cd1951db75a602b1d1825225ee953e5705d00206b
|
4
|
+
data.tar.gz: 81349b8524f6e3e43e79c1b857dccb7497997ccdd4564c60dc8d044d3903eb60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57c2eeb143123b112fb6a834e7a5886674610144e3e581d9136ee6fcc53a752b07d84ef3d5c842ba2ae36614f81058a21fcefe1ff603863b747ead192310e0b6
|
7
|
+
data.tar.gz: cf100f7e81e06e78c859d4f1a773dd0c0c84ef67240eff7ec93823b6fedba88de5abf8f1df97861165ed885992c8b5fa4b5aa8ee5e12ce6ca1904cee008d8df2
|
data/Gemfile.lock
CHANGED
data/data/statistic.yml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
:difficulty: easy
|
4
|
-
:attempts_total: 15
|
5
|
-
:attempts_used: 15
|
6
|
-
:hints_total: 2
|
7
|
-
:hints_used: 2
|
8
|
-
|
9
|
-
:difficulty: medium
|
10
|
-
:attempts_total: 10
|
11
|
-
:attempts_used: 10
|
12
|
-
:hints_total: 1
|
13
|
-
:hints_used: 1
|
1
|
+
#---
|
2
|
+
#- :user_name: WEWEE
|
3
|
+
# :difficulty: easy
|
4
|
+
# :attempts_total: 15
|
5
|
+
# :attempts_used: 15
|
6
|
+
# :hints_total: 2
|
7
|
+
# :hints_used: 2
|
8
|
+
#- :user_name: TWTWTWT
|
9
|
+
# :difficulty: medium
|
10
|
+
# :attempts_total: 10
|
11
|
+
# :attempts_used: 10
|
12
|
+
# :hints_total: 1
|
13
|
+
# :hints_used: 1
|
data/lib/codebreaker/config.rb
CHANGED
data/lib/codebreaker/console.rb
CHANGED
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# # frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# require 'codebreaker'
|
5
|
+
# require_relative 'config'
|
6
|
+
# class Console
|
7
|
+
# # include Rules
|
8
|
+
#
|
9
|
+
# attr_accessor :game
|
10
|
+
#
|
11
|
+
# def initialize
|
12
|
+
# @game = Codebreaker::Game.new
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# def start_game
|
16
|
+
# puts 'Welcome to game'
|
17
|
+
# choose_action
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def game_process(number)
|
21
|
+
# puts game.check_guess(number)
|
22
|
+
# if game.check_guess(number) == game.win
|
23
|
+
# save_game
|
24
|
+
# choose_action
|
25
|
+
# elsif game.used_attempts.zero?
|
26
|
+
# lose
|
27
|
+
# new_process
|
28
|
+
# else
|
29
|
+
# game_actions
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# private
|
34
|
+
#
|
35
|
+
# def game_actions
|
36
|
+
# puts 'use [hint, guess, exit]'
|
37
|
+
#
|
38
|
+
# case input
|
39
|
+
# when Constants::GAME_ACTIONS[:hint] then show_hints
|
40
|
+
# when Constants::GAME_ACTIONS[:guess] then enter_number
|
41
|
+
# else p 'Wrong action'
|
42
|
+
# game_actions
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# def make_registration
|
47
|
+
# puts 'Enter your name'
|
48
|
+
# name = input.to_s
|
49
|
+
# game.difficulties
|
50
|
+
# # puts "What difficulty? #{game.difficulties}"
|
51
|
+
# level = input.to_s
|
52
|
+
# game.create_settings(name, level)
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def choose_action
|
56
|
+
# menu
|
57
|
+
# case input
|
58
|
+
# when Constants::USER_ACTIONS[:start] then process
|
59
|
+
# when Constants::USER_ACTIONS[:rules] then rules
|
60
|
+
# when Constants::USER_ACTIONS[:stats] then take_stats
|
61
|
+
# else
|
62
|
+
# p 'Wrong text'
|
63
|
+
# choose_action
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# def rules
|
68
|
+
# show_rules
|
69
|
+
# choose_action
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# def new_process
|
73
|
+
# choose_action
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# def process
|
77
|
+
# registration = make_registration
|
78
|
+
# registration.is_a?(Array) && !registration.empty? ? registration : game_actions
|
79
|
+
# p registration
|
80
|
+
# choose_action
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# def enter_number
|
84
|
+
# puts 'Enter number'
|
85
|
+
# number = gets.chomp.to_i
|
86
|
+
# game_process(number)
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# def input
|
90
|
+
# input = gets.chomp
|
91
|
+
# input == Constants::USER_ACTIONS[:exit] ? exit : input
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# def menu
|
95
|
+
# puts 'make a choice'
|
96
|
+
# new_menu = Constants::USER_ACTIONS
|
97
|
+
# p new_menu.values
|
98
|
+
# end
|
99
|
+
#
|
100
|
+
# def save_game
|
101
|
+
# puts 'If save game enter: yes'
|
102
|
+
# input == Constants::ACTIONS_FOR_DATABASE[:save_player] ? game.save_stats : new_process
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# def show_hints
|
106
|
+
# p game.use_hint
|
107
|
+
# game_actions
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# def lose
|
111
|
+
# puts "You lose,secret code -> #{game.secret_code} enter start to start a new game."
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# def exit
|
115
|
+
# puts 'goodbye'
|
116
|
+
# abort
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# def take_stats
|
120
|
+
# headings = Constants::HEADINGS
|
121
|
+
# rows = @game.load_stats.map { |key| key }
|
122
|
+
# puts Terminal::Table.new(headings: headings, rows: rows)
|
123
|
+
# choose_action
|
124
|
+
# end
|
125
|
+
# end
|
data/lib/codebreaker/const.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# # frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# module Constants
|
5
|
+
# USER_ACTIONS = {
|
6
|
+
# start: 'start',
|
7
|
+
# rules: 'rules',
|
8
|
+
# stats: 'stats',
|
9
|
+
# exit: 'exit'
|
10
|
+
# }.freeze
|
11
|
+
# GAME_ACTIONS = {
|
12
|
+
# hint: 'hint',
|
13
|
+
# guess: 'guess'
|
14
|
+
# }.freeze
|
15
|
+
# ACTIONS_FOR_DATABASE = {
|
16
|
+
# save_player: 'yes'
|
17
|
+
# }.freeze
|
18
|
+
# HITS = {
|
19
|
+
# user_hits: 'hits'
|
20
|
+
# }.freeze
|
21
|
+
#
|
22
|
+
# HEADINGS = ['Rating', 'Name', 'Difficulty', 'Attempts Total', 'Attempts Used', 'Hints Total', 'Hints Used'].freeze
|
23
|
+
# DIFFICULTY = '[easy] [medium] [hell]'
|
24
|
+
# end
|
data/lib/codebreaker/game.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Codebreaker
|
4
4
|
class Game < BaseClass
|
5
|
-
attr_reader :secret_code, :total_attempts, :used_attempts, :total_hints, :used_hints, :stats, :level
|
5
|
+
attr_reader :secret_code, :total_attempts, :used_attempts, :total_hints, :used_hints, :stats, :level, :player_name
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
super()
|
@@ -33,13 +33,13 @@ module Codebreaker
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def create_settings(name, level)
|
36
|
-
|
36
|
+
user_name(name)
|
37
37
|
create_level(level)
|
38
38
|
|
39
39
|
show_errors unless valid?
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
42
|
+
def user_name(name)
|
43
43
|
user = User.new(name)
|
44
44
|
return @player_name = user.name if user.valid?
|
45
45
|
|
@@ -47,6 +47,7 @@ module Codebreaker
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def accept_level(level)
|
50
|
+
@level = level
|
50
51
|
current_level = Constants::LEVELS[level.to_sym]
|
51
52
|
handle_errors('entered level is not present') unless current_level
|
52
53
|
current_level
|
@@ -64,7 +65,6 @@ module Codebreaker
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def add_level(choice_level)
|
67
|
-
@level = level
|
68
68
|
@used_hints = choice_level[:hints]
|
69
69
|
@total_hints = choice_level[:hints]
|
70
70
|
@total_attempts = choice_level[:attempts]
|
@@ -3,23 +3,27 @@
|
|
3
3
|
module Codebreaker
|
4
4
|
class Statistic
|
5
5
|
def collect_statistic(hash)
|
6
|
+
game_date = Time.new.strftime '%Y/%m/%d'
|
6
7
|
@stat = [{
|
7
8
|
user_name: hash[:user_name],
|
8
9
|
difficulty: hash[:difficulty],
|
9
10
|
attempts_total: hash[:attempts_total],
|
10
11
|
attempts_used: hash[:attempts_used],
|
11
12
|
hints_total: hash[:hints_total],
|
12
|
-
hints_used: hash[:hints_used]
|
13
|
+
hints_used: hash[:hints_used],
|
14
|
+
date: game_date
|
13
15
|
}]
|
14
16
|
save_statistic
|
15
17
|
end
|
16
18
|
|
17
19
|
def show_statistic
|
18
20
|
@items = YAML.load_file(Constants::PATH)
|
19
|
-
@items.
|
21
|
+
return if @items.nil?
|
22
|
+
|
23
|
+
@items.sort_by! { |game| [game[:difficulty].reverse, game[:attempts_used], game[:hints_used]] }
|
20
24
|
@items.each_with_index.map do |stat, index|
|
21
25
|
[index.next, stat[:user_name], stat[:difficulty], stat[:attempts_total],
|
22
|
-
stat[:attempts_used], stat[:hints_total], stat[:hints_used]]
|
26
|
+
stat[:attempts_used], stat[:hints_total], stat[:hints_used], stat[:date]]
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require 'codebreaker'
|
4
|
+
# require_relative 'console'
|
5
|
+
# require 'pry'
|
6
|
+
#
|
7
|
+
# c = Console.new
|
8
|
+
# c.start_game
|
9
|
+
|
10
|
+
# p c.registration
|
11
|
+
# p c
|
12
|
+
# p c.game_process
|
13
|
+
|
14
|
+
# frozen_string_literal: true
|
15
|
+
|
16
|
+
# require 'yaml'
|
17
|
+
#
|
18
|
+
# require 'codebreaker'
|
19
|
+
# require_relative 'console'
|
20
|
+
# require 'pry'
|
21
|
+
#
|
22
|
+
# c = Console.new
|
23
|
+
# c.choose_action
|
24
|
+
# c.take_stats
|
25
|
+
|
26
|
+
# p c.registration
|
27
|
+
# p c
|
28
|
+
# p c.game_process
|
data/lib/codebreaker/version.rb
CHANGED
data/lib/codebreaker.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_bo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oladko Bohdan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|