@@ -17,56 +17,62 @@ function getUserName()
1717 return $ name ;
1818}
1919//---Функция проверки ответов
20- function checkAnswer ($ count , $ name , $ path ) {
20+ function checkAnswer ($ count , $ name , $ path )
21+ {
2122 //---Узнать какой файл обратился (для дальнейшей логики)
2223 $ filepath = $ path ;
2324 $ num = random_int (1 , 100 );
2425 $ num2 = random_int (1 , 10 );
25-
26- //---Логика игр
26+
27+ //---Логика игр
2728 //Подлючим логику в зависимости от игры
2829 switch ($ filepath ) {
2930 //Игра - Чётные числа
30- case "even " :
31+ case "even " :
3132 line ('Answer "yes" if the number is even, otherwise answer "no". ' );
32- $ answer = prompt ("Question: " , $ num );
33+ $ answer = prompt ("Question: " , $ num );
3334 $ isEven = $ num % 2 === 0 ? true : false ;
3435 $ expectedAnswer = $ isEven ? 'yes ' : 'no ' ;
3536 break ;
3637 //Игра - Калькулятор
37- case "calc " :
38+ case "calc " :
3839 line ('What is the result of the expression? ' );
3940 $ operation = ["+ " , "- " , "* " ];
4041 $ 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- }
42+ //Перебрать рандомные операторы
43+ switch ($ thisOperation ) {
44+ case "* " :
45+ $ expectedAnswer = $ num * $ num2 ;
46+ break ;
47+
48+ case "+ " :
49+ $ expectedAnswer = $ num + $ num2 ;
50+ break ;
51+
52+ case "- " :
53+ $ expectedAnswer = $ num - $ num2 ;
54+ break ;
55+ }
5056 $ answer = prompt ("Question: " , "{$ num } {$ thisOperation } {$ num2 }" );
5157 $ answer = is_string ($ answer ) ? $ answer : (int )$ answer ;
5258 break ;
5359 //Игра - Общий делитель
54- case "gcd " :
60+ case "gcd " :
5561 $ expectedAnswer = getGcd ($ num , $ num2 );
5662 print_r ($ expectedAnswer );
5763 line ('Find the greatest common divisor of given numbers. ' );
58- $ answer = prompt ("Question: " , "{$ num } {$ num2 }" );
64+ $ answer = prompt ("Question: " , "{$ num } {$ num2 }" );
5965 break ;
60- default : return line ("This Game is still in production :) " );
66+ default :
67+ return line ("This Game is still in production :) " );
6168 }
6269 //Показать пользователю его ответ
6370 line ("Your answer: {$ answer }" );
6471
6572 if ($ answer != $ expectedAnswer ) {
6673 line ("{$ answer } is wrong answer ;(. Correct answer was ' {$ expectedAnswer }'. " );
6774 return line ("Let's try again, %s! " , $ name );
68- }
69- else {
75+ } else {
7076 line ("Correct! " );
7177 $ count --;
7278 if ($ count <= 0 ) {
@@ -75,5 +81,3 @@ function checkAnswer($count, $name, $path) {
7581 checkAnswer ($ count , $ name , $ path );
7682 }
7783}
78-
79-
0 commit comments