Skip to content

Commit 02b49cc

Browse files
committed
7st step +README. ascinema link
1 parent fe8b647 commit 02b49cc

File tree

4 files changed

+43
-23
lines changed

4 files changed

+43
-23
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ brain-even:
1010
brain-calc:
1111
php ./bin/brain-calc
1212

13+
brain-gcd:
14+
php ./bin/brain-gcd
15+
1316
validate:
1417
composer validate
1518

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Brain-Even - https://asciinema.org/a/UZBtDobwLPOrNa1r3vp6JYiWS
22

33
Brain-Calc - https://asciinema.org/a/cKn78eDiU1h5MTCMr1183kawd
44

5+
Brain-Gcd - https://asciinema.org/a/wWwYQWsxsikakJawzl5Wwxe4Y
6+
57
### Hexlet tests and linter status:
68

79
[![SonarQube Cloud](https://sonarcloud.io/images/project_badges/sonarcloud-light.svg)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
"src/Cli.php",
1111
"src/Games/BrainEven.php",
1212
"src/Games/BrainCalc.php",
13-
"src/Engine.php"
13+
"src/Engine.php",
14+
"src/Games/BrainGcd.php"
1415
]
1516
},
1617
"bin": [
1718
"bin/brain-games",
1819
"bin/brain-even",
19-
"bin/brain-calc"
20+
"bin/brain-calc",
21+
"bin/brain-gcd"
22+
2023
],
2124
"authors": [
2225
{

src/Engine.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use function cli\line;
66
use function cli\prompt;
7+
use function BrainGames\BrainGcd\getGcd;
8+
79
//---Приветствуем пользователя, получаем имя
810
function getUserName()
911
{
@@ -24,27 +26,37 @@ function checkAnswer($count, $name, $path) {
2426
//---Логика игр
2527
//Подлючим логику в зависимости от игры
2628
switch ($filepath) {
27-
case "even": line('Answer "yes" if the number is even, otherwise answer "no".');
28-
$answer = prompt("Question:", $num);
29-
$isEven = $num % 2 === 0 ? true : false;
30-
$expectedAnswer = $isEven ? 'yes' : 'no';
31-
break;
32-
case "calc": line('What is the result of the expression?');
33-
$operation = ["+", "-", "*"];
34-
$thisOperation = $operation[random_int(0, 2)];
35-
//Перебрать рандомные операторы
36-
switch ($thisOperation) {
37-
case "*": $expectedAnswer = $num * $num2;
38-
break;
39-
case "+": $expectedAnswer = $num + $num2;
40-
break;
41-
case "-": $expectedAnswer = $num - $num2;
42-
break;
43-
}
44-
$answer = prompt("Question:", "{$num} {$thisOperation} {$num2}");
45-
$answer = is_string($answer) ? $answer : (int)$answer;
46-
break;
47-
case "": return line("This Game is still in production :)");
29+
//Игра - Чётные числа
30+
case "even":
31+
line('Answer "yes" if the number is even, otherwise answer "no".');
32+
$answer = prompt("Question:", $num);
33+
$isEven = $num % 2 === 0 ? true : false;
34+
$expectedAnswer = $isEven ? 'yes' : 'no';
35+
break;
36+
//Игра - Калькулятор
37+
case "calc":
38+
line('What is the result of the expression?');
39+
$operation = ["+", "-", "*"];
40+
$thisOperation = $operation[random_int(0, 2)];
41+
//Перебрать рандомные операторы
42+
switch ($thisOperation) {
43+
case "*": $expectedAnswer = $num * $num2;
44+
break;
45+
case "+": $expectedAnswer = $num + $num2;
46+
break;
47+
case "-": $expectedAnswer = $num - $num2;
48+
break;
49+
}
50+
$answer = prompt("Question:", "{$num} {$thisOperation} {$num2}");
51+
$answer = is_string($answer) ? $answer : (int)$answer;
52+
break;
53+
//Игра - Общий делитель
54+
case "gcd":
55+
$expectedAnswer = getGcd($num, $num2);
56+
print_r($expectedAnswer);
57+
line('Find the greatest common divisor of given numbers.');
58+
$answer = prompt("Question:", "{$num} {$num2}");
59+
break;
4860
default: return line("This Game is still in production :)");
4961
}
5062
//Показать пользователю его ответ

0 commit comments

Comments
 (0)