44
55use function cli \line ;
66use function cli \prompt ;
7- use function BrainGames \BrainEven \brainEvenGame ;
8- use function BrainGames \BrainGcd \getGcd ;
9- use function BrainGames \BrainProgression \generateProgression ;
10- use function BrainGames \BrainProgression \hideElement ;
11- use function BrainGames \BrainPrime \isPrime ;
127
13- //---Приветствуем пользователя, получаем имя
8+ //---Приветствуем пользователя, получаем имя
149function getUserName (): string
1510{
1611 //Приветствуем пользователя
@@ -19,31 +14,37 @@ function getUserName(): string
1914 line ("Hello, %s! " , $ name );
2015 //Вернуть полученное имя
2116 return $ name ;
17+ }
18+ //---Функция проверки ответов
19+ function checkAnswer (array $ gameParams )
20+ {
21+ $ name = getUserName ();
22+ ["rules " => $ rules ,
23+ "expectedAnswer " => $ expectedAnswer ,
24+ "questions " => $ questions ] = $ gameParams ;
25+ line ($ rules );
26+ for ($ i = 0 ; $ i < count ($ questions ); $ i ++) {
27+ $ answer = prompt ("Question: {$ questions [$ i ]}" );
28+ line ("Your answer: {$ answer }" );
29+ if ($ answer != $ expectedAnswer [$ i ]) {
30+ wrongAnswer ($ name , $ answer [$ i ], $ expectedAnswer [$ i ]);
31+ return ;
32+ } else {
33+ line ("Correct! " );
34+ }
35+ }
36+ trueAnswers ($ name );
2237}
2338 //---Функция для неверного ответа
24- function wrongAnswer (string $ name , mixed $ answer , mixed $ expectedAnswer ) {
39+ function wrongAnswer (string $ name , mixed $ answer , mixed $ expectedAnswer )
40+ {
2541 line ("{$ answer } is wrong answer ;(. Correct answer was ' {$ expectedAnswer }'. " );
2642 line ("Let's try again, %s! " , $ name );
2743 return ;
2844}
2945 //---Функция для верного ответа
30- function trueAnswer (string $ name ) {
46+ function trueAnswers (string $ name )
47+ {
3148 line ("Congratulations, %s! " , $ name );
3249 return ;
33- }
34- //---Функция проверки ответов
35- function checkAnswer (int $ counterAnswers , string $ name , mixed $ answer , mixed $ expectedAnswer )
36- {
37- line ("Your answer: {$ answer }" );
38- if ($ answer != $ expectedAnswer ) {
39- wrongAnswer ($ name , $ answer , $ expectedAnswer );
40- return $ counterAnswers = 3 ;
41- } else {
42- line ("Correct! " );
43- $ counterAnswers ++;
44- if ($ counterAnswers == 3 ) {
45- trueAnswer ($ name );
46- }
47- }
48- return $ counterAnswers ;
4950}
0 commit comments