55use function cli \line ;
66use function cli \prompt ;
77use function BrainGames \BrainGcd \getGcd ;
8+ use function BrainGames \BrainProgression \generateProgression ;
9+ use function BrainGames \BrainProgression \hideElement ;
810
911//---Приветствуем пользователя, получаем имя
1012function getUserName ()
@@ -24,22 +26,22 @@ function checkAnswer($count, $name, $path)
2426 $ num = random_int (1 , 100 );
2527 $ num2 = random_int (1 , 10 );
2628
27- //---Логика игр
28- //Подлючим логику в зависимости от игры
29+ //--- Логика игр
30+ //-- Подлючим логику в зависимости от выбора игры
2931 switch ($ filepath ) {
30- //Игра - Чётные числа
32+ //-- Игра - "Проверка на чётность"
3133 case "even " :
3234 line ('Answer "yes" if the number is even, otherwise answer "no". ' );
3335 $ answer = prompt ("Question: " , $ num );
3436 $ isEven = $ num % 2 === 0 ? true : false ;
3537 $ expectedAnswer = $ isEven ? 'yes ' : 'no ' ;
3638 break ;
37- //Игра - Калькулятор
39+ //-- Игра - " Калькулятор"
3840 case "calc " :
3941 line ('What is the result of the expression? ' );
4042 $ operation = ["+ " , "- " , "* " ];
4143 $ thisOperation = $ operation [random_int (0 , 2 )];
42- //Перебрать рандомные операторы
44+ //-- Перебрать рандомные операторы --
4345 switch ($ thisOperation ) {
4446 case "* " :
4547 $ expectedAnswer = $ num * $ num2 ;
@@ -56,13 +58,20 @@ function checkAnswer($count, $name, $path)
5658 $ answer = prompt ("Question: " , "{$ num } {$ thisOperation } {$ num2 }" );
5759 $ answer = is_string ($ answer ) ? $ answer : (int )$ answer ;
5860 break ;
59- //Игра - Общий делитель
61+ //-- Игра - Общий делитель -- "НОД"
6062 case "gcd " :
6163 $ expectedAnswer = getGcd ($ num , $ num2 );
62- print_r ($ expectedAnswer );
6364 line ('Find the greatest common divisor of given numbers. ' );
6465 $ answer = prompt ("Question: " , "{$ num } {$ num2 }" );
6566 break ;
67+ //-- Игра - "Арифметическая прогрессия"
68+ case "progression " :
69+ $ progression = generateProgression ();
70+ $ hiddenElement = hideElement ($ progression );
71+ $ expectedAnswer = $ hiddenElement ["hidden_value " ];
72+ line ('What number is missing in the progression? ' );
73+ $ answer = prompt ("Question: " , implode (" " , $ hiddenElement ["progression " ]));
74+ break ;
6675 default :
6776 return line ("This Game is still in production :) " );
6877 }
0 commit comments