Skip to content

Commit 2ef87f1

Browse files
committed
refactor: add new method
1 parent cbd8e57 commit 2ef87f1

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11
package hexlet.code.games;
22

33
import hexlet.code.Engine;
4-
5-
import java.util.Random;
4+
import hexlet.code.Utils;
65

76
public class Progression {
87
public static void startGame() {
9-
final int arrLength = 10;
10-
final int stepMax = 10;
11-
final int hideElementMax = 9;
12-
final int firstNumMax = 100;
138
String[][] roundsData = new String[Engine.ROUNDS][2];
14-
Random randNum = new Random();
159
String description = "What number is missing in the progression?";
1610

1711
for (int i = 0; i < Engine.ROUNDS; i++) {
18-
int progressionStep = randNum.nextInt(1, stepMax);
19-
int randHideElement = randNum.nextInt(0, hideElementMax);
20-
int firstNum = randNum.nextInt(1, firstNumMax);
21-
22-
int[] progression = new int[arrLength];
23-
progression[0] = firstNum;
24-
for (int j = 1; j < progression.length; j++) {
25-
progression[j] = progression[j - 1] + progressionStep;
26-
}
27-
28-
String[] progressionWithDots = new String[progression.length];
12+
int randHideElement = Utils.generateNumber(0, 9);
13+
String[] progressionWithDots = new String[getProgression().length];
2914

30-
for (int k = 0; k < progression.length; k++) {
15+
for (int k = 0; k < getProgression().length; k++) {
3116
if (k == randHideElement) {
3217
progressionWithDots[k] = "..";
3318
} else {
34-
progressionWithDots[k] = String.valueOf(progression[k]);
19+
progressionWithDots[k] = String.valueOf(getProgression()[k]);
3520
}
3621
}
3722
String question = String.join(" ", progressionWithDots);
3823
roundsData[i][0] = question;
39-
roundsData[i][1] = String.valueOf(progression[randHideElement]);
24+
roundsData[i][1] = String.valueOf(getProgression()[randHideElement]);
4025
}
4126
Engine.run(description, roundsData);
4227
}
28+
29+
private static int[] getProgression() {
30+
final int arrLength = 10;
31+
int progressionStep = Utils.generateNumber(0, 10);
32+
int firstNum = Utils.generateNumber(0, 100);
33+
34+
int[] progression = new int[arrLength];
35+
progression[0] = firstNum;
36+
for (int j = 1; j < progression.length; j++) {
37+
progression[j] = progression[j - 1] + progressionStep;
38+
}
39+
return progression;
40+
}
4341
}

0 commit comments

Comments
 (0)