Skip to content

Commit

Permalink
fixed it to an indexed array, make lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Egorskov committed Nov 4, 2024
1 parent 30c0dd6 commit 00c3c66
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ function communicate(array $answers, string $game): void
{
$name = greeting();
line("$game");
foreach ($answers as $key => $value) {
$answer = prompt("Question: $key\nYou answer");
if ($answer !== $value) {
line("'$answer' is wrong answer ;( Correct answer: '$value') \nLet's try again, $name!");
foreach ($answers as $key) {
[$question, $correctAnswer] = $key;
$answer = prompt("Question: $question\nYou answer");
if ($answer !== $correctAnswer) {
line("'$answer' is wrong answer ;( Correct answer: '$correctAnswer') \nLet's try again, $name!");
return;
} else {
line("Correct!");
Expand Down
2 changes: 1 addition & 1 deletion src/Games/Calc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function runCalc(): void
$first = mt_rand(MIN_NUM, MAX_NUM);
$second = mt_rand(MIN_NUM, MAX_NUM);
$operator = $signs[array_rand($signs)];
$answers["$first $operator $second"] = (string) calculate($first, $second, $operator);
$answers[] = ["$first $operator $second", (string) calculate($first, $second, $operator)];
}
communicate($answers, $game);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Games/Even.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function runEven()
$answers = [];
foreach (getArrayNumbers() as $number) {
if (isEven($number)) {
$answers[$number] = 'yes';
$answers[] = [$number,'yes'];
} else {
$answers[$number] = 'no';
$answers[] = [$number,'no'];
}
}
communicate($answers, $game);
Expand Down
2 changes: 1 addition & 1 deletion src/Games/Gcd.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function runGcd(): void
for ($i = 1; $i <= ROUND; $i++) {
$first = mt_rand(MIN_NUM, MAX_NUM);
$second = mt_rand(MIN_NUM, MAX_NUM);
$answers["$first $second"] = getNod($first, $second);
$answers[] = ["$first $second", getNod($first, $second)];
}
communicate($answers, $game);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Games/Prime.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function runPrime(): void
$answers = [];
foreach (getArrayNumbers() as $number) {
if (isPrime($number)) {
$answers[$number] = 'yes';
$answers[] = [$number, 'yes'];
} else {
$answers[$number] = 'no';
$answers[] = [$number, 'no'];
}
}
communicate($answers, $game);
Expand Down
2 changes: 1 addition & 1 deletion src/Games/Progression.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function runProgression(): void
$correctAnswer = $numbers[$randomSym];
$numbers[$randomSym] = '..';
$numbersString = implode(' ', $numbers);
$answers[$numbersString] = "$correctAnswer";
$answers[] = [$numbersString, "$correctAnswer"];
}
communicate($answers, $game);
}
Expand Down

0 comments on commit 00c3c66

Please sign in to comment.