Emit27/php-project-lvl1

View on GitHub
src/Games/Even.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace BrainGames\Games\Even;

use function BrainGames\GameEngine\engineGameLaunch as play;

use const BrainGames\GameEngine\QUESTIONS_COUNT;

const MIN_RAND = 1;
const MAX_RAND = 99;

function isEven(int $number)
{
    return $number % 2 === 0;
}

function runGameBrainEven()
{
    $gameDescription = "Answer 'yes' if the number is even, otherwise answer 'no'.";
    $gameData = [];
    for ($i = 0; $i < QUESTIONS_COUNT; $i++) {
        $questionGame = rand(MIN_RAND, MAX_RAND);
        $correctAnswer = isEven($questionGame) ? 'yes' : 'no';
        $gameData[] = [$questionGame, $correctAnswer];
    }
    play($gameData, $gameDescription);
}