Skip to content

Commit dc6b042

Browse files
committed
Fixed Game and bin files after mentor comments
1 parent 935806d commit dc6b042

File tree

16 files changed

+229
-174
lines changed

16 files changed

+229
-174
lines changed

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
install:
2-
composer install
2+
@composer install
33

44
brain-games:
5-
bin/brain-games
5+
@bin/brain-games
66

77
brain-even:
8-
bin/brain-even
8+
@bin/brain-even
99

1010
brain-calc:
11-
bin/brain-calc
11+
@bin/brain-calc
1212

1313
brain-gcd:
14-
bin/brain-gcd
14+
@bin/brain-gcd
1515

1616
brain-progression:
17-
bin/brain-progression
17+
@bin/brain-progression
1818

1919
brain-prime:
20-
bin/brain-prime
20+
@bin/brain-prime
2121

2222
validate:
23-
composer validate
23+
@composer validate
2424

2525
lint:
26-
composer exec --verbose phpcs -- --standard=PSR12 src bin
26+
@composer exec --verbose phpcs -- --standard=PSR12 src bin
2727

2828
correct:
29-
composer exec -- phpcbf --standard=PSR12 src bin
29+
@composer exec -- phpcbf --standard=PSR12 src bin

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,34 @@
1818
**Доступные игры**
1919
1. Brain Even - Проверка на чётность
2020
Определите, является ли случайное число чётным.
21-
make brain-even
21+
22+
Команда: make brain-even
2223
Демонстрация - https://asciinema.org/a/PZIB0AMPHDWAigwTO2UAGq9PI
2324

2425
2. Brain Calc - Калькулятор
2526
Решите простое арифметическое выражение.
2627

27-
make brain-calc
28+
Команда: make brain-calc
2829
Демонстрация - https://asciinema.org/a/5gDhJ6Taqf9GAgZvAtUY4W16l
2930

3031
3. Brain GCD - Наибольший общий делитель
3132
Найдите Наибольший общий делитель двух случайных чисел.
3233

33-
make brain-gcd
34+
Команда: make brain-gcd
3435
Демонстрация - https://asciinema.org/a/bBiNGAePf6ZXq4p0odlB5zFD6
3536

3637

3738

3839
4. Brain Progression - Арифметическая прогрессия
3940
Найдите пропущенный элемент в прогрессии.
4041

41-
make brain-progression
42+
Команда: make brain-progression
4243
Демонстрация - https://asciinema.org/a/HawCHRR9MDuvTWbaOEE4d76Zh
4344

4445
5. Brain Prime - Простое число
4546
Определите, является ли число простым.
4647

47-
make brain-prime
48+
Команда: make brain-prime
4849
Демонстрация - https://asciinema.org/a/JuOx3oZ2UACiALbcsQ5da10V2
4950

5051
**Требования**

bin/brain-calc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env php
2-
32
<?php
43

5-
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once __DIR__ . '/../src/Engine.php';
7-
require_once __DIR__ . '/../src/Games/Calc.php';
4+
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
5+
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
6+
7+
if (file_exists($autoloadPath1)) {
8+
require_once $autoloadPath1;
9+
} else {
10+
require_once $autoloadPath2;
11+
}
812

9-
runGame('Calc');
13+
BrainGames\Games\Calc\runGame();

bin/brain-even

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/usr/bin/env php
2-
32
<?php
43

5-
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once __DIR__ . '/../src/Engine.php';
7-
require_once __DIR__ . '/../src/Games/Even.php';
4+
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
5+
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
6+
7+
if (file_exists($autoloadPath1)) {
8+
require_once $autoloadPath1;
9+
} else {
10+
require_once $autoloadPath2;
11+
}
812

9-
runGame('Even');
13+
BrainGames\Games\Even\runGame();
1014

1115

1216

bin/brain-games

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#!/usr/bin/env php
2-
32
<?php
43

5-
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once __DIR__ . '/../src/Cli.php';
4+
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
5+
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
6+
7+
if (file_exists($autoloadPath1)) {
8+
require_once $autoloadPath1;
9+
} else {
10+
require_once $autoloadPath2;
11+
}
12+
13+
BrainGames\Cli\welcome();

bin/brain-gcd

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env php
2-
32
<?php
43

5-
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once __DIR__ . '/../src/Engine.php';
7-
require_once __DIR__ . '/../src/Games/Gcd.php';
4+
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
5+
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
6+
7+
if (file_exists($autoloadPath1)) {
8+
require_once $autoloadPath1;
9+
} else {
10+
require_once $autoloadPath2;
11+
}
812

9-
runGame('Gcd');
13+
BrainGames\Games\Gcd\runGame();

bin/brain-prime

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env php
2-
32
<?php
43

5-
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once __DIR__ . '/../src/Engine.php';
7-
require_once __DIR__ . '/../src/Games/Prime.php';
4+
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
5+
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
6+
7+
if (file_exists($autoloadPath1)) {
8+
require_once $autoloadPath1;
9+
} else {
10+
require_once $autoloadPath2;
11+
}
812

9-
runGame('Prime');
13+
BrainGames\Games\Prime\runGame();

bin/brain-progression

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env php
2-
32
<?php
43

5-
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once __DIR__ . '/../src/Engine.php';
7-
require_once __DIR__ . '/../src/Games/Progression.php';
4+
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
5+
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
6+
7+
if (file_exists($autoloadPath1)) {
8+
require_once $autoloadPath1;
9+
} else {
10+
require_once $autoloadPath2;
11+
}
812

9-
runGame('Progression');
13+
BrainGames\Games\Progression\runGame();

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,16 @@
2727
"scripts": {
2828
"phpcs": "phpcs --standard=PSR12 src bin",
2929
"phpcbf": "phpcbf --standard=PSR12 src bin"
30+
},
31+
"autoload": {
32+
"files": [
33+
"src/Engine.php",
34+
"src/Cli.php",
35+
"src/Games/Even.php",
36+
"src/Games/Calc.php",
37+
"src/Games/Gcd.php",
38+
"src/Games/Prime.php",
39+
"src/Games/Progression.php"
40+
]
3041
}
3142
}

src/Cli.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

3-
namespace Src\Cli;
3+
namespace BrainGames\Cli;
44

55
use function cli\line;
66
use function cli\prompt;
77

8-
line('Welcome to the Brain Games!');
9-
$name = prompt('May I have your name?');
10-
line("Hello, %s!", $name);
8+
function welcome(): void
9+
{
10+
line('Welcome to the Brain Games!');
11+
$name = prompt('May I have your name?');
12+
line("Hello, %s!", $name);
13+
}

0 commit comments

Comments
 (0)