Skip to content

Commit 8e16a1d

Browse files
committed
project check. ALL edition(5)
1 parent e11f78a commit 8e16a1d

File tree

13 files changed

+63
-75
lines changed

13 files changed

+63
-75
lines changed

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
1-
<h1>Welcome to the Brain Games!</h1>
1+
<h1 text-align="center">Welcome to the Brain Games!</h1>
2+
<h3 text-align="center">Проект 1: [Игры разума](https://ru.hexlet.io/programs/php/projects/45)</h3>
3+
<h6 text-align="center">профессия PHP-разработчик от Hexlet</h6>
24

3-
Brain-Even: https://asciinema.org/a/UZBtDobwLPOrNa1r3vp6JYiWS
5+
Описание: «Игры разума» — набор из пяти консольных игр, построенных по принципу популярных мобильных приложений для прокачки мозга.
6+
Каждая игра задает вопросы, на которые нужно дать правильные ответы.
7+
После трех правильных ответов считается, что игра пройдена.
8+
Неправильные ответы завершают игру и предлагают пройти ее заново.
49

5-
Brain-Calc: https://asciinema.org/a/cKn78eDiU1h5MTCMr1183kawd
610

7-
Brain-Gcd: https://asciinema.org/a/wWwYQWsxsikakJawzl5Wwxe4Y
11+
Установка: composer global require webdevway/hexlet-project-lvl1
812

9-
Brain-Progression: https://asciinema.org/a/sNPCT391AYUgrvR8Oy4ASUkYk
1013

11-
Brain-Prime: https://asciinema.org/a/fOkN1DJ0yYfTX13CLybPBwEec
14+
Определение четного числа.
15+
Запуск из консоли: make brain-even
16+
Пример: Brain-Even: https://asciinema.org/a/UZBtDobwLPOrNa1r3vp6JYiWS
17+
18+
Калькулятор. Арифметические выражения, которые необходимо вычислить.
19+
Запуск из консоли: make brain-calc
20+
Пример: Brain-Calc: https://asciinema.org/a/cKn78eDiU1h5MTCMr1183kawd
21+
22+
Определение наибольшего общего делителя.
23+
Запуск из консоли: make brain-gcd
24+
Пример: Brain-Gcd: https://asciinema.org/a/wWwYQWsxsikakJawzl5Wwxe4Y
25+
26+
Прогрессия. Поиск пропущенных чисел в последовательности чисел.
27+
Запуск из консоли: make brain-progression
28+
Пример: Brain-Progression: https://asciinema.org/a/sNPCT391AYUgrvR8Oy4ASUkYk
29+
30+
Определение простого числа.
31+
Запуск из консоли: make brain-prime
32+
Пример: Brain-Prime: https://asciinema.org/a/fOkN1DJ0yYfTX13CLybPBwEec
33+
1234

1335
### Hexlet tests and linter status:
1436

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

1739

1840
[![Actions Status](https://github.com/webDevWay/php-project-lvl1/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/webDevWay/php-project-lvl1/actions)
19-
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
20-
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=bugs)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
21-
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
22-
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
23-
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
24-
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
25-
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
26-
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
27-
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
28-
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
29-
[![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=webDevWay_php-project-lvl1)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)
41+
3042
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=webDevWay_php-project-lvl1&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=webDevWay_php-project-lvl1)

bin/brain-calc

Lines changed: 2 additions & 2 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\Calc\initGameData;
4+
use function BrainGames\Calc\initGameSession;
55

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

15-
initGameData();
15+
initGameSession();

bin/brain-even

Lines changed: 2 additions & 2 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\Even\initGameData;
4+
use function BrainGames\Even\initGameSession;
55

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

15-
initGameData();
15+
initGameSession();

bin/brain-gcd

Lines changed: 2 additions & 2 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\Gcd\initGameData;
4+
use function BrainGames\Gcd\initGameSession;
55

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

15-
initGameData();
15+
initGameSession();
1616

bin/brain-prime

Lines changed: 2 additions & 2 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\Prime\initGameData;
4+
use function BrainGames\Prime\initGameSession;
55

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

15-
initGameData();
15+
initGameSession();
1616

bin/brain-progression

Lines changed: 2 additions & 2 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\Progression\initGameData;
4+
use function BrainGames\Progression\initGameSession;
55

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

15-
initGameData();
15+
initGameSession();

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "hexlet/code",
2+
"name": "webdevway/hexlet-project-lvl1",
33
"license": "MIT",
44
"description": "Brain training games collection",
55
"autoload": {

src/Engine.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,25 @@
55
use function cli\line;
66
use function cli\prompt;
77

8-
//---Приветствуем пользователя, получаем имя
9-
function getUserName(): string
8+
function startGame(array $gameParams): void
109
{
1110
line('Welcome to the Brain Games!');
1211
$name = prompt('May I have your name?');
1312
line("Hello, %s!", $name);
14-
15-
return $name;
16-
}
17-
//---Функция логики игры и проверки ответов
18-
function startGame(array $gameParams): void
19-
{
20-
$name = getUserName();
21-
["rules" => $rules,
22-
"expectedAnswer" => $expectedAnswer,
23-
"questions" => $questions] = $gameParams;
13+
["rules" => $rules, "expectedAnswer" => $expectedAnswer, "questions" => $questions] = $gameParams;
2414
line($rules);
2515
for ($i = 0; $i < count($questions); $i++) {
2616
$answer = prompt("Question: {$questions[$i]}");
27-
$answer = is_string($expectedAnswer[$i]) ? $answer : (int)$answer;
17+
//$answer = is_string($expectedAnswer[$i]) ? $answer : (int)$answer;
2818
line("Your answer: {$answer}");
29-
if ($answer !== $expectedAnswer[$i]) {
30-
wrongAnswer($name, $answer, $expectedAnswer[$i]);
19+
if ($answer !== (string)$expectedAnswer[$i]) {
20+
line("{$answer} is wrong answer ;(. Correct answer was '{$expectedAnswer[$i]}'.");
21+
line("Let's try again, %s!", $name);
3122
return;
3223
} else {
3324
line("Correct!");
3425
}
3526
}
36-
trueAnswers($name);
37-
}
38-
//---Функция для неверного ответа
39-
function wrongAnswer(string $name, mixed $answer, mixed $expectedAnswer): void
40-
{
41-
line("{$answer} is wrong answer ;(. Correct answer was '{$expectedAnswer}'.");
42-
line("Let's try again, %s!", $name);
43-
return;
44-
}
45-
//---Функция для верного ответа (конец игры)
46-
function trueAnswers(string $name): void
47-
{
4827
line("Congratulations, %s!", $name);
4928
return;
5029
}

src/Games/Calc.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use function BrainGames\Engine\startGame;
66

77
//-- Игра - "Калькулятор"
8-
function initGameData(int $count = 3): void
8+
function initGameSession(int $count = 3): void
99
{
1010
$gameParams = [];
1111
$gameParams["rules"] = 'What is the result of the expression?';
@@ -21,13 +21,17 @@ function initGameData(int $count = 3): void
2121
startGame($gameParams);
2222
}
2323

24-
function calculate(int $x, int $y, string $operator): int
24+
function calculate(int $a, int $b, string $operator): int
2525
{
26-
$operations = [
27-
'+' => fn($x, $y) => $x + $y,
28-
'-' => fn($x, $y) => $x - $y,
29-
'*' => fn($x, $y) => $x * $y,
30-
];
31-
32-
return $operations[$operator]($x, $y);
26+
switch ($operator) {
27+
case '+':
28+
$result = $a + $b;
29+
break;
30+
case '-':
31+
$result = $a - $b;
32+
break;
33+
default:
34+
$result = 0;
35+
}
36+
return $result;
3337
}

src/Games/Even.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use function BrainGames\Engine\startGame;
66

77
//-- Игра - "Проверка на чётность"
8-
function initGameData(int $count = 3): void
8+
function initGameSession(int $count = 3): void
99
{
1010
$gameParams = [];
1111
$gameParams["rules"] = 'Answer "yes" if the number is even, otherwise answer "no".';
@@ -17,7 +17,6 @@ function initGameData(int $count = 3): void
1717

1818
startGame($gameParams);
1919
}
20-
//--- Функция проверки на чётность
2120
function isEven(int $num): bool
2221
{
2322
return $num % 2 === 0;

0 commit comments

Comments
 (0)