|
6 | 6 | import java.util.Scanner; |
7 | 7 |
|
8 | 8 | public class Progression { |
| 9 | + private static final int STEP_COUNT = 10; |
| 10 | + private static final int VALUE_COUNT = 10; |
| 11 | + |
9 | 12 | public static void play() { |
10 | 13 | String userName = Cli.greet(); |
11 | 14 | System.out.println("What number is missing in the progression?"); |
12 | 15 | Scanner scanner = new Scanner(System.in); |
13 | 16 |
|
14 | 17 |
|
15 | | - for (int i = 1; i <= Engine.rounds; i++) { |
16 | | - int start = (int) (Math.random() * 20) + 1; |
17 | | - int step = (int) (Math.random() * 10) + 1; |
18 | | - int length = 10; |
19 | | - int[] sequence = addSequence(start, step, length); |
| 18 | + for (int i = 1; i <= Engine.getRounds(); i++) { |
| 19 | + int start = (int) (Math.random() * Engine.getMaxNumber()) + 1; |
| 20 | + int step = (int) (Math.random() * STEP_COUNT) + 1; |
| 21 | + int[] sequence = addSequence(start, step, VALUE_COUNT); |
20 | 22 |
|
21 | | - int hideIndex = (int) (Math.random() * length); |
| 23 | + int hideIndex = (int) (Math.random() * VALUE_COUNT); |
22 | 24 | int rightAnswer = sequence[hideIndex]; |
23 | 25 |
|
24 | | - System.out.print(Engine.answerText); |
25 | | - for (int j = 0; j < length; j++) { |
| 26 | + System.out.print(Engine.getQuestionText()); |
| 27 | + for (int j = 0; j < VALUE_COUNT; j++) { |
26 | 28 | if (j == hideIndex) { |
27 | 29 | System.out.print(".. "); |
28 | 30 | } else { |
29 | 31 | System.out.print(sequence[j] + " "); |
30 | 32 | } |
31 | 33 | } |
32 | | - System.out.print(Engine.answerText); |
| 34 | + System.out.print(Engine.getAnswerText()); |
33 | 35 | int answer = scanner.nextInt(); |
34 | 36 |
|
35 | 37 | if (answer == rightAnswer) { |
36 | | - System.out.println(Engine.correctAnswer); |
| 38 | + System.out.println(Engine.getCorrectAnswer()); |
37 | 39 | } else { |
38 | | - System.out.printf(Engine.wrongAnswer, answer, rightAnswer); |
39 | | - System.out.printf(Engine.retry, userName); |
| 40 | + System.out.printf(Engine.getWrongAnswer(), answer, rightAnswer); |
| 41 | + System.out.printf(Engine.getRetry(), userName); |
40 | 42 | return; |
41 | 43 | } |
42 | 44 | } |
43 | | - System.out.printf(Engine.congratulations, userName); |
| 45 | + System.out.printf(Engine.getCongratulations(), userName); |
44 | 46 | } |
45 | 47 |
|
46 | 48 | public static int[] addSequence(int start, int step, int length) { |
|
0 commit comments