mastermind_generator 0.1.0 → 0.2.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/README.md +98 -120
- data/demo/Gemfile.lock +57 -0
- data/demo/lib/mastermind.rb +13 -8
- data/lib/mastermind_generator.rb +1 -0
- data/lib/mastermind_generator/difficulty.rb +5 -1
- data/lib/mastermind_generator/game.rb +20 -9
- data/lib/mastermind_generator/guess.rb +17 -8
- data/lib/mastermind_generator/player.rb +21 -0
- data/lib/mastermind_generator/timer.rb +11 -4
- data/lib/mastermind_generator/version.rb +1 -1
- data/mastermind_generator.gemspec +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29e6aefa848cecb0f5d8a2715fa0e18755ac9963a89a203bace224bd8117d3f1
|
4
|
+
data.tar.gz: 793b610e4de1d2127d902aa3de246051c3de54f8c756038622fa6a7aceb85a5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a3a2a54f761d3522e5f97e8c79aef1779993f2f6e904996040e58b4fb961deafc57aa0cc366cc1f4d76266aba111fec4eb5f4fde3b2688cf11443a1c307a461
|
7
|
+
data.tar.gz: d3f65f26cd38d2216b86f2a3cf25b1f7ee64e43bec4fc85ee82c9d16adb5ccbf89c793502b6ed8f122dc096746f217b1f61f77b55cf801107f38227f47baa6bd
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -30,28 +30,23 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
## Configuration
|
32
32
|
|
33
|
-
Before you use mastermind generator you need to configure it. Two attributes should be supplied
|
34
|
-
* **items:** The items array you want to play with.
|
35
|
-
* **difficulties:** Difficulty levels of your game. It must be in a ruby hash format.
|
36
|
-
* For each level,
|
37
|
-
* **item_count:** players allowed to use how many items.
|
38
|
-
* **sequence_length:** sequences must be how many characters length.
|
33
|
+
Before you use mastermind generator you need to configure it. Two attributes should be supplied like below:
|
39
34
|
|
40
35
|
```ruby
|
41
36
|
MastermindGenerator.configure do |config|
|
42
37
|
config.items = %w[red green blue yellow purple orange]
|
43
38
|
config.difficulties = {
|
44
|
-
beginner: {
|
39
|
+
beginner: {
|
45
40
|
item_count: 4,
|
46
|
-
sequence_length: 4
|
41
|
+
sequence_length: 4
|
47
42
|
},
|
48
|
-
intermediate: {
|
49
|
-
item_count: 5,
|
50
|
-
sequence_length: 6
|
43
|
+
intermediate: {
|
44
|
+
item_count: 5,
|
45
|
+
sequence_length: 6
|
51
46
|
},
|
52
|
-
advanced: {
|
53
|
-
item_count: 6,
|
54
|
-
sequence_length: 8
|
47
|
+
advanced: {
|
48
|
+
item_count: 6,
|
49
|
+
sequence_length: 8
|
55
50
|
}
|
56
51
|
}
|
57
52
|
end
|
@@ -63,12 +58,11 @@ Require the gem and include it in your class definition.
|
|
63
58
|
|
64
59
|
```ruby
|
65
60
|
require 'mastermind_generator'
|
66
|
-
# If you write your configuration code in a seperate file uncomment the line below:
|
67
61
|
# require "path_to_your_configuration_file"
|
68
62
|
|
69
63
|
class MastermindGame
|
70
64
|
include MastermindGenerator
|
71
|
-
|
65
|
+
|
72
66
|
# your code goes here...
|
73
67
|
end
|
74
68
|
```
|
@@ -76,139 +70,124 @@ end
|
|
76
70
|
Now, you can generate game objects...
|
77
71
|
|
78
72
|
```ruby
|
79
|
-
|
80
|
-
# other requires
|
73
|
+
...
|
81
74
|
|
82
|
-
class MastermindGame
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
75
|
+
class MastermindGame
|
76
|
+
include MastermindGenerator
|
77
|
+
attr_reader :game
|
78
|
+
|
79
|
+
def start
|
80
|
+
# You must supply one of the difficulty level as an argument to `Game.new`
|
81
|
+
@game = Game.new(:beginner)
|
82
|
+
|
83
|
+
# You can add one or two player
|
84
|
+
game.add_player("Aaron")
|
85
|
+
game.add_player("Celine")
|
86
|
+
|
87
|
+
# You are ready to create a game loop however you want
|
88
|
+
# An example is shown below
|
89
|
+
loop do
|
90
|
+
# Current player takes a guess (chosen automatically)
|
91
|
+
print "Hey #{game.player_name}! What's your guess?"
|
92
|
+
game.take_a_guess(gets.strip)
|
93
|
+
|
94
|
+
# Check the guess is succeed or fail
|
95
|
+
if game.finished?
|
96
|
+
puts "congrats"
|
97
|
+
break
|
98
|
+
else
|
99
|
+
puts "feedback"
|
100
|
+
end
|
101
|
+
|
102
|
+
# if the game is multi-player, you need to call `@game.next_turn`
|
103
|
+
game.next_turn if game.players_count > 1
|
107
104
|
end
|
108
|
-
|
109
|
-
# if the game is multi-player, you need to call `@game.next_turn`
|
110
|
-
@game.next_turn if game.players.length > 1
|
111
105
|
end
|
112
106
|
end
|
113
|
-
end
|
114
107
|
```
|
115
108
|
|
116
|
-
##
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
* `@game.player.guesses`: All guesses entered by current player. It might be useful to show some historical information.
|
122
|
-
* `@game.player.guess`: Last guess of the user, returns `MastermindGenerator::Guess` instance.
|
123
|
-
* `@game.player.winner?`: Returns `true` if player's latest guess is successful, otherwise returns false.
|
124
|
-
* `@game.player.timer`: Returns a `MastermindGenerator::Timer` object. You can use it to show players how much time they spent to break the code.
|
125
|
-
|
126
|
-
## Guess Information
|
127
|
-
|
128
|
-
You can access guess instances by players. Every `MastermindGenerator::Guess` instances have these methods:
|
129
|
-
|
130
|
-
* `@game.player.guess.succeed?`: Whether the guess was successful or not.
|
131
|
-
* `@game.player.guess.correct_element_count`: How many elements were matched with the target sequence.
|
132
|
-
* `@game.player.guess.correct_position_count`: How many positions were matched with the target sequence.
|
133
|
-
* `@game.player.guess.correct_position_hints`: You can use it to show the correct positions like `R_BG__`
|
134
|
-
* `@game.player.guess.statistics`: Returns a hash that it contains all the information about the guess.
|
135
|
-
|
109
|
+
## Gathering information
|
110
|
+
|
111
|
+
You can use following methods to get information about the game.
|
112
|
+
|
136
113
|
```ruby
|
137
|
-
|
114
|
+
game.sequence_value # returns auto-generated target sequence value
|
115
|
+
|
116
|
+
game.player_name # returns current player's name
|
117
|
+
|
118
|
+
game.guesses # returns all of guesses of the current player
|
119
|
+
|
120
|
+
game.guess_stats
|
121
|
+
# returns all information about the current player guesses
|
138
122
|
# # => {
|
139
123
|
# value: guess sequence value,
|
140
|
-
# target: target
|
141
|
-
# status: successful or
|
142
|
-
# count:
|
124
|
+
# target: target sequence value,
|
125
|
+
# status: successful or fail,
|
126
|
+
# count: count of guesses,
|
143
127
|
# element_count: correct element count,
|
144
|
-
#
|
145
|
-
# position_hints: correct position hints
|
128
|
+
# position_count: correct position count,
|
129
|
+
# position_hints: correct position hints,
|
130
|
+
# duration: elapsed time,
|
131
|
+
# duration_as_text: elapsed time in human readable format,
|
146
132
|
# }
|
147
|
-
```
|
148
|
-
|
149
|
-
## Timer Information
|
150
|
-
|
151
|
-
As we mentioned above, each `MastermindGenerator::Player` instance has a method called `#timer` that can be used to
|
152
|
-
access that player's timer. However, timers are setting up behind the scenes, you can also start, pause or stop
|
153
|
-
them by using `@game.player.timer.start`, `@game.player.timer.pause`, and `@game.player.timer.stop` methods.
|
154
133
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
# 123
|
161
|
-
|
162
|
-
# returns duration as human readable text
|
163
|
-
@game.player.timer.duration_as_text
|
164
|
-
# 2 minutes, 3 seconds
|
134
|
+
# You can also get some of the statistics by piece
|
135
|
+
game.guess_value
|
136
|
+
game.guess_count
|
137
|
+
game.timer_duration
|
138
|
+
game.timer_duration_as_text
|
165
139
|
```
|
166
140
|
|
167
141
|
## Providing Feedbacks
|
168
142
|
|
169
|
-
You can give feedbacks to your
|
143
|
+
You can give feedbacks to your players by using the methods we mentioned above. An example is given below:
|
170
144
|
|
171
145
|
```ruby
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
146
|
+
def congrats
|
147
|
+
print(<<~MSG)
|
148
|
+
Congratulations #{game.player_name}! You guessed the sequence '#{game.sequence_value.upcase}' \
|
149
|
+
in #{game.guesses_count} guesses over #{game.timer_duration_as_text}.
|
150
|
+
MSG
|
151
|
+
end
|
152
|
+
```
|
179
153
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
154
|
+
```ruby
|
155
|
+
def feedback
|
156
|
+
stats = game.guess_stats
|
157
|
+
print(<<~MSG)
|
158
|
+
'#{stats[:value].upcase}' has #{stats[:element_count]} of the correct elements with \
|
159
|
+
#{stats[:position_count]} in the correct positions.\nYou've taken #{stats[:count]} guess.
|
160
|
+
MSG
|
161
|
+
end
|
186
162
|
```
|
187
163
|
|
188
164
|
## Exception Handling
|
189
165
|
|
190
|
-
There are
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
166
|
+
There are six error types defined in the gem with proper `#message` methods.
|
167
|
+
|
168
|
+
* SequenceTooLongError
|
169
|
+
* SequenceTooShortError
|
170
|
+
* SequenceHasInvalidCharsError
|
171
|
+
* InvalidDifficultyError
|
172
|
+
* TimerNotStartedError
|
173
|
+
* TimerNotStoppedError
|
195
174
|
|
196
175
|
An example usage might be like this:
|
197
176
|
|
198
177
|
```ruby
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
178
|
+
begin
|
179
|
+
print("Hey #{game.player_name}! What's your guess? > ")
|
180
|
+
game.take_a_guess(gets.strip)
|
181
|
+
rescue SequenceTooLongError, SequenceTooShortError, SequenceHasInvalidCharsError => e
|
182
|
+
warn("#{e.message}. Try again!")
|
183
|
+
retry
|
184
|
+
end
|
206
185
|
```
|
207
186
|
|
208
187
|
## Contributing
|
209
188
|
|
210
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/sbagdat/mastermind_generator. This project
|
211
|
-
|
189
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sbagdat/mastermind_generator. This project is
|
190
|
+
intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
|
212
191
|
the [code of conduct](https://github.com/sbagdat/mastermind_generator/blob/main/CODE_OF_CONDUCT.md).
|
213
192
|
|
214
193
|
## License
|
@@ -218,5 +197,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
218
197
|
## Code of Conduct
|
219
198
|
|
220
199
|
Everyone interacting in the MastermindGenerator project's codebases, issue trackers, chat rooms and mailing lists is
|
221
|
-
expected to follow
|
222
|
-
the [code of conduct](https://github.com/sbagdat/mastermind_generator/blob/main/CODE_OF_CONDUCT.md).
|
200
|
+
expected to follow the [code of conduct](https://github.com/sbagdat/mastermind_generator/blob/main/CODE_OF_CONDUCT.md).
|
data/demo/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ansi (1.5.0)
|
5
|
+
ast (2.4.2)
|
6
|
+
builder (3.2.4)
|
7
|
+
docile (1.3.5)
|
8
|
+
mastermind_generator (0.2.0)
|
9
|
+
minitest (5.14.4)
|
10
|
+
minitest-reporters (1.4.3)
|
11
|
+
ansi
|
12
|
+
builder
|
13
|
+
minitest (>= 5.0)
|
14
|
+
ruby-progressbar
|
15
|
+
parallel (1.20.1)
|
16
|
+
parser (3.0.0.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
rainbow (3.0.0)
|
19
|
+
rake (13.0.3)
|
20
|
+
regexp_parser (2.1.1)
|
21
|
+
rexml (3.2.4)
|
22
|
+
rubocop (1.11.0)
|
23
|
+
parallel (~> 1.10)
|
24
|
+
parser (>= 3.0.0.0)
|
25
|
+
rainbow (>= 2.2.2, < 4.0)
|
26
|
+
regexp_parser (>= 1.8, < 3.0)
|
27
|
+
rexml
|
28
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
29
|
+
ruby-progressbar (~> 1.7)
|
30
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
31
|
+
rubocop-ast (1.4.1)
|
32
|
+
parser (>= 2.7.1.5)
|
33
|
+
rubocop-minitest (0.10.3)
|
34
|
+
rubocop (>= 0.87, < 2.0)
|
35
|
+
ruby-progressbar (1.11.0)
|
36
|
+
simplecov (0.21.2)
|
37
|
+
docile (~> 1.1)
|
38
|
+
simplecov-html (~> 0.11)
|
39
|
+
simplecov_json_formatter (~> 0.1)
|
40
|
+
simplecov-html (0.12.3)
|
41
|
+
simplecov_json_formatter (0.1.2)
|
42
|
+
unicode-display_width (2.0.0)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
x86_64-darwin-20
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
mastermind_generator
|
49
|
+
minitest (>= 5.14.3)
|
50
|
+
minitest-reporters (>= 0.5.0)
|
51
|
+
rake (>= 13.0.3)
|
52
|
+
rubocop (>= 1.8.1)
|
53
|
+
rubocop-minitest (>= 0.10.3)
|
54
|
+
simplecov (>= 0.21.2)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
2.2.5
|
data/demo/lib/mastermind.rb
CHANGED
@@ -59,24 +59,27 @@ class Mastermind # rubocop:disable Metrics/ClassLength
|
|
59
59
|
else
|
60
60
|
feedback
|
61
61
|
end
|
62
|
-
game.next_turn if game.
|
62
|
+
game.next_turn if game.players_count > 1
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def feedback
|
67
|
-
stats =
|
68
|
-
cli.print_message(
|
69
|
-
|
67
|
+
stats = game.guess_stats
|
68
|
+
cli.print_message(<<~MSG.chomp)
|
69
|
+
'#{stats[:value].upcase}' has #{stats[:element_count]} of the correct elements with \
|
70
|
+
#{stats[:position_count]} in the correct positions.\nYou've taken #{stats[:count]} guess.
|
71
|
+
MSG
|
70
72
|
end
|
71
73
|
|
72
74
|
def congrats
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
cli.print_message(<<~MSG.chomp)
|
76
|
+
Congratulations #{game.player_name}! You guessed the sequence '#{game.sequence_value.upcase}' \
|
77
|
+
in #{game.guesses_count} guesses over #{game.timer_duration_as_text}.
|
78
|
+
MSG
|
76
79
|
end
|
77
80
|
|
78
81
|
def take_a_guess
|
79
|
-
cli.ask_question("Hey #{game.
|
82
|
+
cli.ask_question("Hey #{game.player_name}! What's your guess?")
|
80
83
|
begin
|
81
84
|
game.take_a_guess(cli.answer)
|
82
85
|
rescue SequenceTooLongError, SequenceTooShortError, SequenceHasInvalidCharsError => e
|
@@ -139,3 +142,5 @@ class Mastermind # rubocop:disable Metrics/ClassLength
|
|
139
142
|
"(#{value[0]})#{value[1..]}"
|
140
143
|
end
|
141
144
|
end
|
145
|
+
|
146
|
+
Mastermind.new.play
|
data/lib/mastermind_generator.rb
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
module MastermindGenerator
|
4
4
|
# Exception for passing invalid difficulty value as an argument to `Difficulty.new`
|
5
|
-
class InvalidDifficultyError < StandardError
|
5
|
+
class InvalidDifficultyError < StandardError
|
6
|
+
def message
|
7
|
+
"Invalid Difficulty: It must be one of the difficulty levels which you specified in configuration"
|
8
|
+
end
|
9
|
+
end
|
6
10
|
|
7
11
|
# Reprsents difficulty of the game
|
8
12
|
# It affects of how many items will be used for secret sequences
|
@@ -5,6 +5,8 @@ module MastermindGenerator
|
|
5
5
|
class Game
|
6
6
|
attr_reader :difficulty, :sequence, :players
|
7
7
|
|
8
|
+
extend Forwardable
|
9
|
+
|
8
10
|
def initialize(difficulty)
|
9
11
|
@difficulty = Difficulty.new(difficulty)
|
10
12
|
@sequence = SequenceGenerator.new(@difficulty).generate
|
@@ -15,17 +17,11 @@ module MastermindGenerator
|
|
15
17
|
def take_a_guess(value)
|
16
18
|
seq = Sequence.new(difficulty, value)
|
17
19
|
guess = Guess.new(seq)
|
18
|
-
player.
|
20
|
+
player.timer_start
|
19
21
|
player.take_a_guess(guess)
|
20
22
|
player.guess.assign_target(sequence)
|
21
23
|
end
|
22
24
|
|
23
|
-
def player
|
24
|
-
return players.first if players.length == 1
|
25
|
-
|
26
|
-
@turn_counter.odd? ? players.first : players.last
|
27
|
-
end
|
28
|
-
|
29
25
|
def add_player(player_name)
|
30
26
|
return if players.length > 1
|
31
27
|
|
@@ -35,7 +31,7 @@ module MastermindGenerator
|
|
35
31
|
def finished?
|
36
32
|
return false unless player.guess.succeed?
|
37
33
|
|
38
|
-
player.
|
34
|
+
player.timer_stop
|
39
35
|
true
|
40
36
|
end
|
41
37
|
|
@@ -44,8 +40,23 @@ module MastermindGenerator
|
|
44
40
|
end
|
45
41
|
|
46
42
|
def next_turn
|
47
|
-
player.
|
43
|
+
player.timer_pause
|
48
44
|
@turn_counter += 1
|
49
45
|
end
|
46
|
+
|
47
|
+
def player
|
48
|
+
return players.first if players_count == 1
|
49
|
+
|
50
|
+
@turn_counter.odd? ? players.first : players.last
|
51
|
+
end
|
52
|
+
|
53
|
+
def_delegator :@players, :length, :players_count
|
54
|
+
def_delegator :@sequence, :value, :sequence_value
|
55
|
+
|
56
|
+
def_delegator :player, :name, :player_name
|
57
|
+
def_delegators :player, :guess_value, :guess_stats, :guesses, :timer_duration, :timer_duration_as_text
|
58
|
+
|
59
|
+
def_delegator :guesses, :count, :guesses_count
|
60
|
+
def_delegator :winner, :name, :winner_name
|
50
61
|
end
|
51
62
|
end
|
@@ -5,6 +5,8 @@ module MastermindGenerator
|
|
5
5
|
class Guess
|
6
6
|
attr_reader :sequence, :target
|
7
7
|
|
8
|
+
extend Forwardable
|
9
|
+
|
8
10
|
def initialize(sequence)
|
9
11
|
@sequence = sequence
|
10
12
|
@target = nil
|
@@ -19,23 +21,22 @@ module MastermindGenerator
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def correct_element_count
|
22
|
-
|
24
|
+
sequence_codes.reduce(0) { |sum, code| sum + [target_value.count(code), value.count(code)].min }
|
23
25
|
end
|
24
26
|
|
25
27
|
def correct_position_count
|
26
28
|
seuence_target_packs.count { _1 == _2 }
|
27
29
|
end
|
28
30
|
|
29
|
-
def correct_position_hints
|
30
|
-
seuence_target_packs.map { _1 == _2 ? _1 :
|
31
|
+
def correct_position_hints(mark = "_")
|
32
|
+
seuence_target_packs.map { _1 == _2 ? _1 : mark }.join
|
31
33
|
end
|
32
34
|
|
33
35
|
def statistics
|
34
36
|
{
|
35
|
-
value:
|
36
|
-
target:
|
37
|
-
status:
|
38
|
-
count: guesses.length,
|
37
|
+
value: value,
|
38
|
+
target: target_value,
|
39
|
+
status: status,
|
39
40
|
element_count: correct_element_count,
|
40
41
|
position_count: correct_position_count,
|
41
42
|
position_hints: correct_position_hints
|
@@ -44,8 +45,16 @@ module MastermindGenerator
|
|
44
45
|
|
45
46
|
private
|
46
47
|
|
48
|
+
def status
|
49
|
+
{ true => "success", false => "fail" }[succeed?]
|
50
|
+
end
|
51
|
+
|
47
52
|
def seuence_target_packs
|
48
|
-
|
53
|
+
value.chars.zip(target_value.chars)
|
49
54
|
end
|
55
|
+
|
56
|
+
def_delegator :@sequence, :codes, :sequence_codes
|
57
|
+
def_delegator :@sequence, :value
|
58
|
+
def_delegator :@target, :value, :target_value
|
50
59
|
end
|
51
60
|
end
|
@@ -5,6 +5,8 @@ module MastermindGenerator
|
|
5
5
|
class Player
|
6
6
|
attr_reader :name, :guesses, :timer
|
7
7
|
|
8
|
+
extend Forwardable
|
9
|
+
|
8
10
|
def initialize(name)
|
9
11
|
@name = name
|
10
12
|
@guesses = []
|
@@ -22,5 +24,24 @@ module MastermindGenerator
|
|
22
24
|
def winner?
|
23
25
|
guess.succeed?
|
24
26
|
end
|
27
|
+
|
28
|
+
def guess_stats
|
29
|
+
guess_statistics.merge(
|
30
|
+
{ count: guesses.count,
|
31
|
+
duration: timer_duration,
|
32
|
+
duration_as_text: timer_duration_as_text
|
33
|
+
}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def_delegator :guesses, :count, :guesses_count
|
38
|
+
def_delegator :guess, :value, :guess_value
|
39
|
+
def_delegator :guess, :statistics, :guess_statistics
|
40
|
+
|
41
|
+
def_delegator :@timer, :duration, :timer_duration
|
42
|
+
def_delegator :@timer, :duration_as_text, :timer_duration_as_text
|
43
|
+
def_delegator :@timer, :stop, :timer_stop
|
44
|
+
def_delegator :@timer, :start, :timer_start
|
45
|
+
def_delegator :@timer, :pause, :timer_pause
|
25
46
|
end
|
26
47
|
end
|
@@ -2,10 +2,14 @@
|
|
2
2
|
|
3
3
|
module MastermindGenerator
|
4
4
|
# Exception for ending timer without starting it before
|
5
|
-
class TimerNotStartedError < StandardError
|
5
|
+
class TimerNotStartedError < StandardError
|
6
|
+
def message
|
7
|
+
"Timer is not started! To stop or pause a timer, you need to start it first."
|
8
|
+
end
|
9
|
+
end
|
6
10
|
|
7
11
|
# A simple timer
|
8
|
-
# Calculates the time between start and end
|
12
|
+
# Calculates the time between start and end
|
9
13
|
class Timer
|
10
14
|
include TimeHelpers
|
11
15
|
|
@@ -23,11 +27,14 @@ module MastermindGenerator
|
|
23
27
|
alias pause stop
|
24
28
|
|
25
29
|
def duration
|
26
|
-
|
30
|
+
pause
|
31
|
+
elapsed_time = stop_time - start_time
|
32
|
+
start
|
33
|
+
elapsed_time
|
27
34
|
end
|
28
35
|
|
29
36
|
def duration_as_text
|
30
|
-
time_in_writing(
|
37
|
+
time_in_writing(duration)
|
31
38
|
end
|
32
39
|
|
33
40
|
private
|
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["sbagdat@gmail.com"]
|
10
10
|
|
11
11
|
spec.summary = "Fully customizable mastermind game generator."
|
12
|
-
spec.description = "Mastermind* Generator is a fully customizable mastermind (or master mind) game generator.
|
12
|
+
spec.description = "Mastermind* Generator is a fully customizable mastermind (or master mind) game generator. "\
|
13
|
+
"It supports using custom items other than classic color variations. It can also generate multi-player games."
|
13
14
|
spec.homepage = "https://github.com/sbagdat/mastermind_generator"
|
14
15
|
spec.license = "MIT"
|
15
16
|
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mastermind_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sıtkı Bağdat
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- bin/console
|
34
34
|
- bin/setup
|
35
35
|
- demo/Gemfile
|
36
|
+
- demo/Gemfile.lock
|
36
37
|
- demo/README.md
|
37
38
|
- demo/lib/mastermind.rb
|
38
39
|
- demo/lib/mastermind/console_interface.rb
|