Skip to content

Commit c4bf9ce

Browse files
Minor bug improvements and optimalization
1 parent 114f023 commit c4bf9ce

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

src/com/vladimirsimek/checkers/gui.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,10 @@ public static void clearScreen() {
2727
for (int i = 0; i < 100; i++) {
2828
System.out.println(" ");
2929
}
30+
System.out.print("\033[H\033[2J");
3031
System.out.flush();
3132
} // Should clear screen
3233

33-
public static boolean isCharacterValidPlayer(String[][] fields, int a, int b) {
34-
boolean isValid = false;
35-
36-
return isValid;
37-
}
38-
3934
public static boolean isCoordinateValid(String[][] fields, String rawCoordinates) {
4035
boolean isValid = true;
4136
String[] stringCoordinates = rawCoordinates.split(",");
@@ -65,11 +60,9 @@ public static boolean isCoordinateValid(String[][] fields, String rawCoordinates
6560
} else if(fields[a][b].equals(player1)) {
6661
isValidData = true;
6762
}
68-
69-
7063
}
7164
return isValidData;
72-
}
65+
} // Checks if input of coordination is valid
7366

7467
public static void notValidCoordinate() {
7568
while (!isCoordinateValid(fields, rawCoordinates)) {
@@ -78,30 +71,32 @@ public static void notValidCoordinate() {
7871
System.out.println(row);
7972
rawCoordinates = sc.next();
8073
}
81-
}
74+
} // Tells player that his input is invalid and will require a new one
8275

8376
public static void gameOver1Won() {
77+
clearScreen();
8478
System.out.println("Game over!");
8579
System.out.println("Player 1 won the game! Congratulations!");
8680
System.out.println(row);
8781
System.out.println("It took you total of " + (runTimeCycles - 2) + " rounds to beat player 2.");
8882
System.exit(0);
89-
}
83+
} // Ends the game if Player 1 won
9084

9185
public static void gameOver2Won() {
86+
clearScreen();
9287
System.out.println("Game over!");
9388
System.out.println("Player 2 won the game! Congratulations!");
9489
System.out.println(row);
9590
System.out.println("It took you total of " + (runTimeCycles - 2) + " rounds to beat player 1.");
9691
System.exit(0);
97-
}
92+
} // Ends the game if Player 2 won
9893

9994
public static void areHerePlayers() {
10095
player2amount = 0;
10196
player1amount = 0;
10297
playersLeft = false;
10398
int index = 0;
104-
for (String[] field : fields) { // Checks if there are still some players left
99+
for (String[] field : fields) {
105100
for (String s : field) {
106101
if (s.equals(player2)) {
107102
player2amount++;
@@ -125,5 +120,5 @@ public static void areHerePlayers() {
125120
} else if (index == 3) {
126121
playersLeft = true;
127122
}
128-
}
123+
} // Checks if are any players remaining, if yes game continues, if not gameOver() will be called
129124
}

0 commit comments

Comments
 (0)