brain_games 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/brain_games.gemspec +46 -0
- data/exe/brain_games +15 -0
- data/lib/brain_games/cli.rb +81 -0
- data/lib/brain_games/engine.rb +39 -0
- data/lib/brain_games/games/brain_calc.rb +37 -0
- data/lib/brain_games/games/brain_calc_stub.rb +17 -0
- data/lib/brain_games/games/brain_even.rb +28 -0
- data/lib/brain_games/games/brain_even_stub.rb +17 -0
- data/lib/brain_games/games/brain_gcd.rb +34 -0
- data/lib/brain_games/games/brain_gcd_stub.rb +17 -0
- data/lib/brain_games/games/brain_prime.rb +33 -0
- data/lib/brain_games/games/brain_prime_stub.rb +17 -0
- data/lib/brain_games/games/brain_progression.rb +39 -0
- data/lib/brain_games/games/brain_progression_stub.rb +17 -0
- data/lib/brain_games/utils/utils.rb +11 -0
- data/lib/brain_games/version.rb +5 -0
- data/lib/brain_games.rb +26 -0
- metadata +66 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ccb83662e90caa8433e5e4a3f5fb63341c3d4b310fefa4ece013728ff0850da6
|
|
4
|
+
data.tar.gz: 5eb7190d5000180bc695cf01044a9a5acaab6b2704005d1af7f0d086418084b8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9e976156dc00a22f13c85c655bac29a9de8b37beb82445a522504d73a662bc35820a729c95fda41c539b915ff3aa265fe7441d02d033723a1402ca74ae0989cd
|
|
7
|
+
data.tar.gz: 8ab0d1c57739d9810a7c63a902a0708ccc00dace3e63c2d7ac7784d576bfbee9cc386123aa038e566feb6421795e0a8122989fb85dcbdd0ae86b94f8fc6e29ca
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 usernaimandrey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# BrainGames
|
|
2
|
+
|
|
3
|
+
[](https://github.com/usernaimandrey/brain_games/actions/workflows/main.yml)
|
|
4
|
+
|
|
5
|
+
## **Brain Games This is a collection of 5 games:**
|
|
6
|
+
|
|
7
|
+
1. Brain: Even - guess even or not even number
|
|
8
|
+
|
|
9
|
+
2. Brain: Calc - test your basic math skills
|
|
10
|
+
|
|
11
|
+
3. Brain: GCD - find the greatest common divisor
|
|
12
|
+
|
|
13
|
+
4. Brain: Prime - count a prime number or not
|
|
14
|
+
|
|
15
|
+
5. Brain: Progression - write the missing number in progression
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
20
|
+
|
|
21
|
+
$ bundle add brain_gemes
|
|
22
|
+
|
|
23
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
24
|
+
|
|
25
|
+
$ gem install brain_gemes
|
|
26
|
+
|
|
27
|
+
or
|
|
28
|
+
|
|
29
|
+
clone this repository
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
$ git clone https://github.com/usernaimandrey/brain_games.git
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
at the root of the project
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
$ make build
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
and play games
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
$ barin_games -g or --game=NAME -l --language=LANGUAGE
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
How palay:
|
|
50
|
+
|
|
51
|
+
### Options:
|
|
52
|
+
|
|
53
|
+
[](https://asciinema.org/a/v5lrBYirDiHOUpulk4obnSugN)
|
|
54
|
+
|
|
55
|
+
### Play brain even on english and russion:
|
|
56
|
+
|
|
57
|
+
[](https://asciinema.org/a/549554)
|
|
58
|
+
|
|
59
|
+
The list of available games can be viewed by calling the --rulle option
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
64
|
+
|
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
66
|
+
|
|
67
|
+
## Contributing
|
|
68
|
+
|
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/brain_gemes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/brain_gemes/blob/master/CODE_OF_CONDUCT.md).
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
74
|
+
|
|
75
|
+
## Code of Conduct
|
|
76
|
+
|
|
77
|
+
Everyone interacting in the BrainGemes project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/brain_gemes/blob/master/CODE_OF_CONDUCT.md).
|
data/brain_games.gemspec
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/brain_games/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'brain_games'
|
|
7
|
+
spec.version = BrainGames::VERSION
|
|
8
|
+
spec.authors = ['Andrey']
|
|
9
|
+
spec.email = ['anshlyapnikov@yandex.ru']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'This is a CLI APP Brain Games'
|
|
12
|
+
spec.description = 'Brain Games This is a collection of 5 games'
|
|
13
|
+
spec.homepage = 'https://github.com/usernaimandrey/brain_games'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 2.6.0'
|
|
16
|
+
|
|
17
|
+
# spec.metadata['allowed_push_host'] = ''
|
|
18
|
+
|
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/usernaimandrey/brain_games'
|
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/usernaimandrey/brain_games.'
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
# spec.files = Dir.chdir(__dir__) do
|
|
26
|
+
# `git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
# (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
|
28
|
+
# end
|
|
29
|
+
# end
|
|
30
|
+
|
|
31
|
+
spec.files = Dir.glob('{lib,man,exe}/**/*', File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
|
|
32
|
+
# Include the CHANGELOG.md, LICENSE.md, README.md manually
|
|
33
|
+
spec.files += %w[LICENSE.txt README.md]
|
|
34
|
+
# include the gemspec itself because warbler breaks w/o it
|
|
35
|
+
spec.files += %w[brain_games.gemspec]
|
|
36
|
+
spec.bindir = 'exe'
|
|
37
|
+
spec.executables = 'brain_games'
|
|
38
|
+
spec.require_paths = ['lib']
|
|
39
|
+
|
|
40
|
+
# Uncomment to register a new dependency of your gem
|
|
41
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
42
|
+
|
|
43
|
+
# For more information and examples about making a new gem, check out our
|
|
44
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
45
|
+
# spec.metadata['rubygems_mfa_required'] = 'true'
|
|
46
|
+
end
|
data/exe/brain_games
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
base_path = File.expand_path('../lib', __dir__)
|
|
5
|
+
|
|
6
|
+
if File.exist?(base_path)
|
|
7
|
+
require_relative '../lib/brain_games'
|
|
8
|
+
require_relative '../lib/brain_games/cli'
|
|
9
|
+
else
|
|
10
|
+
require 'brain_games'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
args = BrainGames::Cli.run(ARGV)
|
|
14
|
+
|
|
15
|
+
BrainGames.play_game(args)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require_relative 'version'
|
|
5
|
+
|
|
6
|
+
module BrainGames
|
|
7
|
+
class Cli
|
|
8
|
+
OPTIONS = Struct.new(:lang, :game_name)
|
|
9
|
+
|
|
10
|
+
LANGUAGE = %w[en ru].freeze
|
|
11
|
+
|
|
12
|
+
GAMES = %w[clac even gcd prime progression].freeze
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
def run(options)
|
|
16
|
+
args = OPTIONS.new
|
|
17
|
+
|
|
18
|
+
opt_parser = OptionParser.new do |opts|
|
|
19
|
+
opts.banner = 'Usage: brain_games | Использование brain_games [options]'
|
|
20
|
+
|
|
21
|
+
opts.on('-g', '--game=NAME', 'Game name | Имя игры') do |g|
|
|
22
|
+
if GAMES.include?(g)
|
|
23
|
+
args.game_name = g
|
|
24
|
+
else
|
|
25
|
+
puts(<<-EOF
|
|
26
|
+
Такой игры пока нет, доступные игры и правила можно посмотреть вызвав --rulles
|
|
27
|
+
There are no such games yet, available games and rules can be viewed by calling --rulles
|
|
28
|
+
EOF
|
|
29
|
+
)
|
|
30
|
+
exit
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
opts.on('-l', '--lang=LANGUAGE[en ru]',
|
|
35
|
+
'Language game, default english | Язык игры, по умолчанию английский') do |lang|
|
|
36
|
+
if LANGUAGE.include?(lang)
|
|
37
|
+
args.lang = lang
|
|
38
|
+
else
|
|
39
|
+
puts('Check option, language may be en or ru | Проверьте опцию, язык может быть en или ru')
|
|
40
|
+
exit
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
opts.on('-v', '--version', 'Version app | Версия приложения') do
|
|
45
|
+
puts(BrainGames::VERSION)
|
|
46
|
+
exit
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
opts.on('--rulles', 'Game rules | Правила игр') do
|
|
50
|
+
puts(<<-EOF
|
|
51
|
+
even: Answer yes if the number is even, otherwise answer no.
|
|
52
|
+
Ответьте yes, если число четное, иначе ответьте no
|
|
53
|
+
|
|
54
|
+
calc: What is the result of the expression?
|
|
55
|
+
Что является результатом выражения?
|
|
56
|
+
|
|
57
|
+
gcd: Find the greatest common divisor of given numbers.
|
|
58
|
+
Найдите наибольший общий делитель данных чисел.
|
|
59
|
+
|
|
60
|
+
prime: Answer yes if given number is prime. Otherwise answer no.
|
|
61
|
+
Ответьте yes, если данное число простое. В противном случае ответьте no.
|
|
62
|
+
|
|
63
|
+
progression: What number is missing in the progression?
|
|
64
|
+
Какое число пропущено в прогрессии?
|
|
65
|
+
EOF
|
|
66
|
+
)
|
|
67
|
+
exit
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
opts.on('-h', '--help', 'Prints this help') do
|
|
71
|
+
puts opts
|
|
72
|
+
exit
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
opt_parser.parse!(options)
|
|
77
|
+
args
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BrainGames
|
|
4
|
+
class Engine
|
|
5
|
+
attr_reader :game
|
|
6
|
+
|
|
7
|
+
ROUNDS = 3
|
|
8
|
+
|
|
9
|
+
def initialize(game)
|
|
10
|
+
@game = game
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def run
|
|
14
|
+
puts(I18n.t(:greating))
|
|
15
|
+
|
|
16
|
+
print(I18n.t(:acquaintance))
|
|
17
|
+
|
|
18
|
+
name = $stdin.gets.chop
|
|
19
|
+
puts(I18n.t(:personal_greating, name: name))
|
|
20
|
+
puts(game.game_rule)
|
|
21
|
+
ROUNDS.times do
|
|
22
|
+
question, right_answer = game.question_right_answer
|
|
23
|
+
|
|
24
|
+
print(I18n.t(:question, question: question))
|
|
25
|
+
|
|
26
|
+
answer = $stdin.gets.chop.downcase
|
|
27
|
+
|
|
28
|
+
puts(I18n.t(:answer, answer: answer))
|
|
29
|
+
if answer == right_answer
|
|
30
|
+
puts(I18n.t(:correct))
|
|
31
|
+
else
|
|
32
|
+
puts(I18n.t(:no_correct, answer: answer, right_answer: right_answer, name: name))
|
|
33
|
+
return
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
puts(I18n.t(:goodbye, name: name))
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../utils/utils'
|
|
4
|
+
|
|
5
|
+
module BrainGames
|
|
6
|
+
module Games
|
|
7
|
+
class BrainCalc
|
|
8
|
+
class << self
|
|
9
|
+
OPERATIONS = %w[+ - *].freeze
|
|
10
|
+
|
|
11
|
+
def game_rule
|
|
12
|
+
I18n.t(:game_rule, scope: :calc)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def question_right_answer
|
|
16
|
+
left_operand = Utils.generate_random(1, 100)
|
|
17
|
+
right_operand = Utils.generate_random(1, 100)
|
|
18
|
+
operation = OPERATIONS[Utils.generate_random(0, 2)]
|
|
19
|
+
question = "#{left_operand} #{operation} #{right_operand}"
|
|
20
|
+
right_answer = nil
|
|
21
|
+
|
|
22
|
+
case operation
|
|
23
|
+
when '+'
|
|
24
|
+
right_answer = left_operand + right_operand
|
|
25
|
+
when '*'
|
|
26
|
+
right_answer = left_operand * right_operand
|
|
27
|
+
when '-'
|
|
28
|
+
right_answer = left_operand - right_operand
|
|
29
|
+
else
|
|
30
|
+
puts("Unknow operation #{operation}")
|
|
31
|
+
end
|
|
32
|
+
[question, right_answer.to_s]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../utils/utils'
|
|
4
|
+
|
|
5
|
+
module BrainGames
|
|
6
|
+
module Games
|
|
7
|
+
class BrainEven
|
|
8
|
+
class << self
|
|
9
|
+
def game_rule
|
|
10
|
+
I18n.t(:game_rule, scope: :even)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def question_right_answer
|
|
14
|
+
question = Utils.generate_random(1, 100)
|
|
15
|
+
right_answer = even?(question) ? 'yes' : 'no'
|
|
16
|
+
|
|
17
|
+
[question.to_s, right_answer]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def even?(number)
|
|
23
|
+
(number % 2).zero?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../utils/utils'
|
|
4
|
+
|
|
5
|
+
module BrainGames
|
|
6
|
+
module Games
|
|
7
|
+
class BrainGcd
|
|
8
|
+
class << self
|
|
9
|
+
def game_rule
|
|
10
|
+
I18n.t(:game_rule, scope: :gcd)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def question_right_answer
|
|
14
|
+
num_one = Utils.generate_random(1, 100)
|
|
15
|
+
num_two = Utils.generate_random(1, 100)
|
|
16
|
+
number_lesser, number_bigest = [num_one, num_two].minmax
|
|
17
|
+
question = "#{num_one} #{num_two}"
|
|
18
|
+
right_answer = gcd(number_bigest, number_lesser)
|
|
19
|
+
|
|
20
|
+
[question, right_answer.to_s]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def gcd(number_bigest, number_lesser)
|
|
26
|
+
remainder = number_bigest.remainder number_lesser
|
|
27
|
+
return number_lesser if remainder.zero?
|
|
28
|
+
|
|
29
|
+
gcd(number_lesser, remainder)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../utils/utils'
|
|
4
|
+
|
|
5
|
+
module BrainGames
|
|
6
|
+
module Games
|
|
7
|
+
class BrainPrime
|
|
8
|
+
class << self
|
|
9
|
+
def show_game_rule
|
|
10
|
+
I18n.t(:game_rule, scope: :prime)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def question_right_answer
|
|
14
|
+
question = Utils.generate_random(1, 100)
|
|
15
|
+
right_answer = prime?(question) ? 'yes' : 'no'
|
|
16
|
+
|
|
17
|
+
[question.to_s, right_answer]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def prime?(number)
|
|
21
|
+
return false if number < 2
|
|
22
|
+
|
|
23
|
+
return true if number == 2
|
|
24
|
+
|
|
25
|
+
(2..Math.sqrt(number).round).each do |divider|
|
|
26
|
+
return false if (number % divider).zero?
|
|
27
|
+
end
|
|
28
|
+
true
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../utils/utils'
|
|
4
|
+
|
|
5
|
+
module BrainGames
|
|
6
|
+
module Games
|
|
7
|
+
class BrainProgression
|
|
8
|
+
class << self
|
|
9
|
+
def game_rule
|
|
10
|
+
puts(I18n.t(:game_rule, scope: :progression))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def question_right_answer
|
|
14
|
+
elements_count = Utils.generate_random(5, 15)
|
|
15
|
+
step_progression = Utils.generate_random(2, 10)
|
|
16
|
+
element_hidden = Utils.generate_random(0, elements_count)
|
|
17
|
+
first_element = Utils.generate_random(0, 100)
|
|
18
|
+
last_element = first_element + (elements_count * step_progression)
|
|
19
|
+
|
|
20
|
+
right_answer = 0
|
|
21
|
+
question = []
|
|
22
|
+
index = 0
|
|
23
|
+
|
|
24
|
+
(first_element..last_element).step(step_progression) do |element|
|
|
25
|
+
if index == element_hidden
|
|
26
|
+
right_answer = element
|
|
27
|
+
question << '..'
|
|
28
|
+
index += 1
|
|
29
|
+
next
|
|
30
|
+
end
|
|
31
|
+
question << element
|
|
32
|
+
index += 1
|
|
33
|
+
end
|
|
34
|
+
[question.join(' '), right_answer.to_s]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BrainGames
|
|
4
|
+
module Games
|
|
5
|
+
class BrainProgressionStub
|
|
6
|
+
class << self
|
|
7
|
+
def game_rule
|
|
8
|
+
I18n.t(:game_rule, scope: :progression)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def question_right_answer
|
|
12
|
+
['1 3 5 .. 9', '7']
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/brain_games.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'zeitwerk'
|
|
4
|
+
require 'i18n'
|
|
5
|
+
|
|
6
|
+
I18n.load_path += Dir["#{File.expand_path('config/locales')}/*.yml"]
|
|
7
|
+
I18n.config.available_locales = %i[en ru]
|
|
8
|
+
I18n.default_locale = :en
|
|
9
|
+
|
|
10
|
+
loader = Zeitwerk::Loader.for_gem
|
|
11
|
+
loader.setup
|
|
12
|
+
|
|
13
|
+
module BrainGames
|
|
14
|
+
class << self
|
|
15
|
+
def play_game(args)
|
|
16
|
+
if args.game_name.nil?
|
|
17
|
+
puts(I18n.t(:no_exist_game))
|
|
18
|
+
return
|
|
19
|
+
end
|
|
20
|
+
I18n.locale = args.lang if args.lang
|
|
21
|
+
class_game = Object.const_get "BrainGames::Games::Brain#{args.game_name.capitalize}"
|
|
22
|
+
game = Engine.new(class_game)
|
|
23
|
+
game.run
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: brain_games
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrey
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-01-08 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Brain Games This is a collection of 5 games
|
|
14
|
+
email:
|
|
15
|
+
- anshlyapnikov@yandex.ru
|
|
16
|
+
executables:
|
|
17
|
+
- brain_games
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- LICENSE.txt
|
|
22
|
+
- README.md
|
|
23
|
+
- brain_games.gemspec
|
|
24
|
+
- exe/brain_games
|
|
25
|
+
- lib/brain_games.rb
|
|
26
|
+
- lib/brain_games/cli.rb
|
|
27
|
+
- lib/brain_games/engine.rb
|
|
28
|
+
- lib/brain_games/games/brain_calc.rb
|
|
29
|
+
- lib/brain_games/games/brain_calc_stub.rb
|
|
30
|
+
- lib/brain_games/games/brain_even.rb
|
|
31
|
+
- lib/brain_games/games/brain_even_stub.rb
|
|
32
|
+
- lib/brain_games/games/brain_gcd.rb
|
|
33
|
+
- lib/brain_games/games/brain_gcd_stub.rb
|
|
34
|
+
- lib/brain_games/games/brain_prime.rb
|
|
35
|
+
- lib/brain_games/games/brain_prime_stub.rb
|
|
36
|
+
- lib/brain_games/games/brain_progression.rb
|
|
37
|
+
- lib/brain_games/games/brain_progression_stub.rb
|
|
38
|
+
- lib/brain_games/utils/utils.rb
|
|
39
|
+
- lib/brain_games/version.rb
|
|
40
|
+
homepage: https://github.com/usernaimandrey/brain_games
|
|
41
|
+
licenses:
|
|
42
|
+
- MIT
|
|
43
|
+
metadata:
|
|
44
|
+
homepage_uri: https://github.com/usernaimandrey/brain_games
|
|
45
|
+
source_code_uri: https://github.com/usernaimandrey/brain_games
|
|
46
|
+
changelog_uri: https://github.com/usernaimandrey/brain_games.
|
|
47
|
+
post_install_message:
|
|
48
|
+
rdoc_options: []
|
|
49
|
+
require_paths:
|
|
50
|
+
- lib
|
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 2.6.0
|
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
requirements: []
|
|
62
|
+
rubygems_version: 3.2.22
|
|
63
|
+
signing_key:
|
|
64
|
+
specification_version: 4
|
|
65
|
+
summary: This is a CLI APP Brain Games
|
|
66
|
+
test_files: []
|