Skip to content

Commit 350c533

Browse files
committed
project check. ALL edition
1 parent cc80357 commit 350c533

File tree

13 files changed

+24
-207
lines changed

13 files changed

+24
-207
lines changed

bin/brain-calc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33

4-
use function BrainGames\Engine\getUserName;
5-
use function BrainGames\Engine\checkAnswer;
4+
use function BrainGames\Calc\initGameData;
65

76
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
87
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
@@ -13,5 +12,4 @@ if (file_exists($autoloadPath1)) {
1312
require_once $autoloadPath2;
1413
}
1514

16-
17-
//checkAnswer($count = 3, $userName, $path="calc");
15+
initGameData();

bin/brain-even

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33

4-
use function BrainGames\BrainEven\brainEvenGame;
4+
use function BrainGames\Even\initGameData;
55

66
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
77
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
@@ -12,5 +12,4 @@ if (file_exists($autoloadPath1)) {
1212
require_once $autoloadPath2;
1313
}
1414

15-
//запуск игры со значением счётчиика по умолчанию
16-
brainEvenGame($count = 3);
15+
initGameData();

bin/brain-games

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ if (file_exists($autoloadPath1)) {
1212
require_once $autoloadPath2;
1313
}
1414

15-
//получим имя пользователя
1615
getName();

bin/brain-gcd

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

4-
use function BrainGames\Engine\getUserName;
5-
use function BrainGames\Engine\checkAnswer;
6-
4+
use function BrainGames\Gcd\initGameData;
75

86
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
97
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
@@ -13,15 +11,6 @@ if (file_exists($autoloadPath1)) {
1311
} else {
1412
require_once $autoloadPath2;
1513
}
16-
//получим имя пользователя
17-
/*$userName = getUserName();
18-
//запуск игры
19-
checkAnswer($count = 3, $userName, $path="gcd");
2014

21-
//-- Игра - Общий делитель -- "НОД"
22-
case "gcd":
23-
$expectedAnswer = getGcd($num, $num2);
24-
line('Find the greatest common divisor of given numbers.');
25-
$answer = prompt("Question: {$num} {$num2}");
26-
break;
15+
initGameData();
2716

bin/brain-prime

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33

4-
use function BrainGames\Engine\getUserName;
5-
use function BrainGames\Engine\checkAnswer;
6-
4+
use function BrainGames\Prime\initGameData;
75

86
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
97
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
@@ -13,15 +11,6 @@ if (file_exists($autoloadPath1)) {
1311
} else {
1412
require_once $autoloadPath2;
1513
}
16-
//получим имя пользователя
17-
/*$userName = getUserName();
18-
//запуск игры
19-
checkAnswer($count = 3, $userName, $path="prime");
20-
case "prime":
21-
line('Answer "yes" if given number is prime. Otherwise answer "no".');
22-
$answer = prompt("Question: {$num}");
23-
$expectedAnswer = isPrime($num) ? 'yes' : 'no';
24-
break;
25-
default:
26-
return line("This Game is still in production :)");
27-
}
14+
15+
initGameData();
16+

bin/brain-progression

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

4-
use function BrainGames\Engine\getUserName;
5-
use function BrainGames\Engine\checkAnswer;
6-
4+
use function BrainGames\Progression\initGameData;
75

86
$autoloadPath1 = __DIR__ . '/../../../autoload.php';
97
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';
@@ -13,17 +11,5 @@ if (file_exists($autoloadPath1)) {
1311
} else {
1412
require_once $autoloadPath2;
1513
}
16-
//получим имя пользователя
17-
/*$userName = getUserName();
18-
//Запустим игру
19-
checkAnswer($count = 3, $userName, $path="progression");
2014

21-
case "progression":
22-
$progression = generateProgression();
23-
$hiddenElement = hideElement($progression);
24-
$expectedAnswer = $hiddenElement["hidden_value"];
25-
line('What number is missing in the progression?');
26-
$answer = prompt("Question: " . implode(" ", $hiddenElement["progression"]));
27-
break;
28-
//-- Игра - "Простое ли число?"
29-
15+
initGameData();

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
},
99
"files": [
1010
"src/Cli.php",
11-
"src/Games/BrainEven.php",
12-
"src/Games/BrainCalc.php",
1311
"src/Engine.php",
14-
"src/Games/BrainGcd.php",
15-
"src/Games/BrainProgression.php",
16-
"src/Games/BrainPrime.php"
12+
"src/Games/Even.php",
13+
"src/Games/Calc.php",
14+
"src/Games/Gcd.php",
15+
"src/Games/Progression.php",
16+
"src/Games/Prime.php"
1717
]
1818
},
1919
"bin": [

src/Engine.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,25 @@
88
//---Приветствуем пользователя, получаем имя
99
function getUserName(): string
1010
{
11-
//Приветствуем пользователя
1211
line('Welcome to the Brain Games!');
1312
$name = prompt('May I have your name?');
1413
line("Hello, %s!", $name);
15-
//Вернуть полученное имя
14+
1615
return $name;
1716
}
18-
//---Функция проверки ответов
19-
function checkAnswer(array $gameParams)
17+
//---Функция логики игры и проверки ответов
18+
function startGame(array $gameParams)
2019
{
2120
$name = getUserName();
22-
["rules" => $rules,
21+
["rules" => $rules,
2322
"expectedAnswer" => $expectedAnswer,
2423
"questions" => $questions] = $gameParams;
2524
line($rules);
26-
for($i = 0; $i < count($questions); $i++) {
25+
for ($i = 0; $i < count($questions); $i++) {
2726
$answer = prompt("Question: {$questions[$i]}");
2827
line("Your answer: {$answer}");
2928
if ($answer != $expectedAnswer[$i]) {
30-
wrongAnswer($name, $answer[$i], $expectedAnswer[$i]);
29+
wrongAnswer($name, $answer, $expectedAnswer[$i]);
3130
return;
3231
} else {
3332
line("Correct!");
@@ -42,7 +41,7 @@ function wrongAnswer(string $name, mixed $answer, mixed $expectedAnswer)
4241
line("Let's try again, %s!", $name);
4342
return;
4443
}
45-
//---Функция для верного ответа
44+
//---Функция для верного ответа (конец игры)
4645
function trueAnswers(string $name)
4746
{
4847
line("Congratulations, %s!", $name);

src/Games/BrainCalc.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Games/BrainEven.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)