|
| 1 | +package hexlet.code.Games; |
| 2 | + |
| 3 | +import hexlet.code.Engine; |
| 4 | + |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.Random; |
| 7 | + |
| 8 | +public class Progression { |
| 9 | + public static int progression() { |
| 10 | + Random random = new Random(); |
| 11 | + String mainGameQuestion = "What number is missing in the progression?"; |
| 12 | + |
| 13 | + String[] question = new String[Engine.rounds]; |
| 14 | + String[] correctAnswer = new String[Engine.rounds]; |
| 15 | + |
| 16 | + for (var i = 0; i < Engine.rounds; i++) { |
| 17 | + |
| 18 | + int arrayLength = random.nextInt(5) + 5; |
| 19 | + int[] array = new int[arrayLength]; |
| 20 | + |
| 21 | + int step = random.nextInt(9) + 1; |
| 22 | + int start = random.nextInt(14) + 1; |
| 23 | + |
| 24 | + for (int j = 0; j < arrayLength; j++) { |
| 25 | + array[j] = start + j * step; |
| 26 | + } |
| 27 | + |
| 28 | + int indexFromArray = random.nextInt(arrayLength - 1); |
| 29 | + |
| 30 | + String arrayToString = Arrays.toString(array); |
| 31 | + String elementToHide = String.valueOf(array[indexFromArray]); |
| 32 | + String oneElement = "\\b" + elementToHide + "\\b"; |
| 33 | + String arrayHideNumber = arrayToString.replaceFirst(oneElement, ".."); |
| 34 | + arrayHideNumber = arrayHideNumber.replace("[", "").replace("]", "") |
| 35 | + .replace(",", ""); |
| 36 | + |
| 37 | + question[i] = arrayHideNumber; |
| 38 | + correctAnswer[i] = String.valueOf(array[indexFromArray]); |
| 39 | + |
| 40 | + } |
| 41 | + Engine.skeletonOfGames(mainGameQuestion, question, correctAnswer); |
| 42 | + return 0; |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments