Skip to content

Commit 2576e17

Browse files
committed
Add Even game
1 parent 33152ac commit 2576e17

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
install:
22
composer install
3-
brain-games:
4-
./bin/brain-games
53
validate:
64
composer validate
75
lint:
8-
composer exec --verbose phpcs -- --standard=PSR12 src bin
6+
composer exec --verbose phpcs -- --standard=PSR12 src bin
7+
brain-games:
8+
./bin/brain-games
9+
brain-even:
10+
./bin/brain-even
11+

bin/brain-even

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env php
2+
3+
<?php
4+
5+
require __DIR__."/../vendor/autoload.php";
6+
7+
\BrainGames\EvenGame\startEvenGame();

src/EvenGame.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace BrainGames\EvenGame;
4+
5+
use function BrainGames\Cli\playGame;
6+
7+
function startEvenGame(): void
8+
{
9+
$questions = [];
10+
$answers = [];
11+
for ($i = 0; $i < 3; $i++) {
12+
$questions[$i] = rand(1, 100);
13+
$answers[$i] = isEven($questions[$i]) ? 'yes' : 'no';
14+
}
15+
playGame($questions, $answers);
16+
}
17+
18+
function isEven(int $number): bool
19+
{
20+
return $number % 2 === 0;
21+
}

0 commit comments

Comments
 (0)