44
55use function cli \line ;
66use function cli \prompt ;
7+ use function BrainGames \BrainGcd \getGcd ;
8+
79//---Приветствуем пользователя, получаем имя
810function getUserName ()
911{
@@ -24,27 +26,37 @@ function checkAnswer($count, $name, $path) {
2426 //---Логика игр
2527 //Подлючим логику в зависимости от игры
2628 switch ($ filepath ) {
27- case "even " : line ('Answer "yes" if the number is even, otherwise answer "no". ' );
28- $ answer = prompt ("Question: " , $ num );
29- $ isEven = $ num % 2 === 0 ? true : false ;
30- $ expectedAnswer = $ isEven ? 'yes ' : 'no ' ;
31- break ;
32- case "calc " : line ('What is the result of the expression? ' );
33- $ operation = ["+ " , "- " , "* " ];
34- $ thisOperation = $ operation [random_int (0 , 2 )];
35- //Перебрать рандомные операторы
36- switch ($ thisOperation ) {
37- case "* " : $ expectedAnswer = $ num * $ num2 ;
38- break ;
39- case "+ " : $ expectedAnswer = $ num + $ num2 ;
40- break ;
41- case "- " : $ expectedAnswer = $ num - $ num2 ;
42- break ;
43- }
44- $ answer = prompt ("Question: " , "{$ num } {$ thisOperation } {$ num2 }" );
45- $ answer = is_string ($ answer ) ? $ answer : (int )$ answer ;
46- break ;
47- case "" : return line ("This Game is still in production :) " );
29+ //Игра - Чётные числа
30+ case "even " :
31+ line ('Answer "yes" if the number is even, otherwise answer "no". ' );
32+ $ answer = prompt ("Question: " , $ num );
33+ $ isEven = $ num % 2 === 0 ? true : false ;
34+ $ expectedAnswer = $ isEven ? 'yes ' : 'no ' ;
35+ break ;
36+ //Игра - Калькулятор
37+ case "calc " :
38+ line ('What is the result of the expression? ' );
39+ $ operation = ["+ " , "- " , "* " ];
40+ $ thisOperation = $ operation [random_int (0 , 2 )];
41+ //Перебрать рандомные операторы
42+ switch ($ thisOperation ) {
43+ case "* " : $ expectedAnswer = $ num * $ num2 ;
44+ break ;
45+ case "+ " : $ expectedAnswer = $ num + $ num2 ;
46+ break ;
47+ case "- " : $ expectedAnswer = $ num - $ num2 ;
48+ break ;
49+ }
50+ $ answer = prompt ("Question: " , "{$ num } {$ thisOperation } {$ num2 }" );
51+ $ answer = is_string ($ answer ) ? $ answer : (int )$ answer ;
52+ break ;
53+ //Игра - Общий делитель
54+ case "gcd " :
55+ $ expectedAnswer = getGcd ($ num , $ num2 );
56+ print_r ($ expectedAnswer );
57+ line ('Find the greatest common divisor of given numbers. ' );
58+ $ answer = prompt ("Question: " , "{$ num } {$ num2 }" );
59+ break ;
4860 default : return line ("This Game is still in production :) " );
4961 }
5062 //Показать пользователю его ответ
0 commit comments