@@ -9,31 +9,30 @@ public class Progression {
99 private static final int RIGHT_BORDER_OF_SIZE_PROGRESSION = 10 ;
1010 private static final int LEFT_BORDER_OF_STEP_PROGRESSION = 5 ;
1111 private static final int RIGHT_BORDER_OF_STEP_PROGRESSION = 10 ;
12+ private static final int COUNT_LEVELS = 3 ;
1213
14+ public static void startGame () {
1315
14- public static void start (int countLevels ) {
15- String userName = Engine .greeting ();
16- Engine .printGameRules (GAME_RULE );
17- for (int i = 0 ; i < countLevels ; i ++) {
18- int [] progression = Progression .generateProgression ();
19- int positionOfWishingElement = Engine .randomIntValue (0 , progression .length );
16+ String [][] levels = new String [COUNT_LEVELS ][2 ];
17+ for (int level = 0 ; level < levels .length ; level ++) {
18+ for (int i = 0 ; i < levels [level ].length ; i ++) {
19+ int sizeProgression = Utils .randomIntValue (LEFT_BORDER_OF_SIZE_PROGRESSION ,
20+ RIGHT_BORDER_OF_SIZE_PROGRESSION );
21+ int stepOfProgression = Utils .randomIntValue (LEFT_BORDER_OF_STEP_PROGRESSION ,
22+ RIGHT_BORDER_OF_STEP_PROGRESSION );
23+ int [] progression = Progression .generateProgression (sizeProgression , stepOfProgression );
24+ int positionOfWishingElement = Utils .randomIntValue (0 , progression .length );
2025
2126
22- String question = getQuestion (progression , positionOfWishingElement );
23- int rightAnswer = progression [positionOfWishingElement ];
24-
25- Engine .askQuestion (question );
26- String userAnswer = Engine .getAnswer ();
27- if (!Engine .isRightAnswer (userAnswer , Integer .toString (rightAnswer ))) {
28- Engine .wrongAnswer (userAnswer , Integer .toString (rightAnswer ), userName );
29- return ;
27+ String question = getQuestion (progression , positionOfWishingElement );
28+ int rightAnswer = progression [positionOfWishingElement ];
29+ levels [level ][0 ] = question ;
30+ levels [level ][1 ] = Integer .toString (rightAnswer );
3031 }
31- System .out .println ("Correct!" );
3232 }
33- Engine .winGame (userName );
34- }
35-
3633
34+ Engine .startLevels (GAME_RULE , levels );
35+ }
3736 private static String getQuestion (int [] progression , int positionOfWishingElement ) {
3837 if (positionOfWishingElement < 0 || positionOfWishingElement > progression .length ) {
3938 return null ;
@@ -51,13 +50,10 @@ private static String getQuestion(int[] progression, int positionOfWishingElemen
5150 return result .toString ().trim ();
5251 }
5352
54- private static int [] generateProgression () {
55- int sizeProgression = Engine .randomIntValue (LEFT_BORDER_OF_SIZE_PROGRESSION , RIGHT_BORDER_OF_SIZE_PROGRESSION );
56- int stepOfProgression = Engine .randomIntValue (LEFT_BORDER_OF_STEP_PROGRESSION ,
57- RIGHT_BORDER_OF_STEP_PROGRESSION );
53+ private static int [] generateProgression (int sizeProgression , int stepOfProgression ) {
5854 int [] progression = new int [sizeProgression ];
5955
60- progression [0 ] = Engine .randomIntValue ();
56+ progression [0 ] = Utils .randomIntValue ();
6157 for (int i = 1 ; i < progression .length ; i ++) {
6258 progression [i ] = progression [i - 1 ] + stepOfProgression ;
6359 }
0 commit comments