-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameLoop.java
48 lines (46 loc) · 1.82 KB
/
GameLoop.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.lang.Math;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
public class GameLoop {
public static final String YELLOW = "\u001B[33m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String WHITE = "\u001B[37m";
public static final String PURPLE = "\u001B[35m";
private int rounds;
private String secretCode;
private MastermindAlgorithm mastermindAlgorithm;
public GameLoop(int rounds, String secretCode) {
this.rounds = rounds;
this.secretCode = secretCode;
}
public void run() {
int round = 1;
String inputCode;
System.out.println(GREEN + "Will you find the secret code?");
Scanner input = new Scanner(System.in);
while (round <= rounds) {
System.out.printf(YELLOW + "-------🏁 Round %d/%d 🏁 -------\n" + PURPLE + " ", round, rounds);
inputCode = input.nextLine();
this.mastermindAlgorithm = new MastermindAlgorithm(
this.secretCode,
inputCode
);
if(GameFunctions.wrongInput(inputCode)) {
System.out.println(RED + "------❌ Wrong input!❌ -------");
continue;
} else if (secretCode.equals(inputCode)) {
System.out.println(GREEN + "Congrats! You did it!🥳 🥳 🥳");
break;
} else {
mastermindAlgorithm.wellPiecesAlgo();
mastermindAlgorithm.misPiecesAlgo();
}
if (round == this.rounds)
System.out.printf(RED + "-------❌ Game Over ❌ -------\n"+ GREEN +"----- Secret code: %s -----\n", this.secretCode);
round++;
}
}
}