File tree Expand file tree Collapse file tree 4 files changed +50
-3
lines changed Expand file tree Collapse file tree 4 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ brain-games:
88 ./bin/brain-games
99brain-even :
1010 ./bin/brain-even
11-
11+ brain-calc :
12+ ./bin/brain-calc
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env php
2+
3+ <?php
4+
5+ require __DIR__ ."/../vendor/autoload.php " ;
6+
7+ \BrainGames \CalcGame \startCalcGame ();
Original file line number Diff line number Diff line change 66 "autoload" : {
77 "files" : [
88 " src/Cli.php" ,
9- " src/EvenGame.php"
9+ " src/EvenGame.php" ,
10+ " src/CalcGame.php"
1011 ]
1112 },
1213 "bin" : [
13- " bin/brain-games"
14+ " bin/brain-games" ,
15+ " bin/brain-even" ,
16+ " bin/brain-calc"
1417 ],
1518 "authors" : [
1619 {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BrainGames \CalcGame ;
4+
5+ use function BrainGames \Cli \playGame ;
6+
7+ function startCalcGame (): void
8+ {
9+ $ questions = [];
10+ $ answers = [];
11+ for ($ i = 0 ; $ i < 3 ; $ i ++) {
12+ $ number1 = rand (1 , 100 );
13+ $ number2 = rand (1 , 100 );
14+ $ operationNumber = rand (1 , 3 );
15+ $ operation = '' ;
16+ $ expressionResult = 0 ;
17+ switch ($ operationNumber ) {
18+ case 1 :
19+ $ operation = '+ ' ;
20+ $ expressionResult = $ number1 + $ number2 ;
21+ break ;
22+ case 2 :
23+ $ operation = '- ' ;
24+ $ expressionResult = $ number1 - $ number2 ;
25+ break ;
26+ case 3 :
27+ $ operation = '* ' ;
28+ $ expressionResult = $ number1 * $ number2 ;
29+ break ;
30+ }
31+ $ expression ="{$ number1 }{$ operation }{$ number2 }" ;
32+ $ questions [$ i ] = $ expression ;
33+ $ answers [$ i ] = $ expressionResult ;
34+ }
35+ playGame ($ questions , $ answers , 'What is the result of the expression? ' );
36+ }
You can’t perform that action at this time.
0 commit comments