commit e9aaa63f7231204884b7f5f5bdd9cb7d0d0389cc parent 95dd3e52d3a09aa2d8b93f55405fad56695c657a Author: lukeeeeeee334 <lukeosullivan123@gmail.com> Date: Thu, 5 Dec 2024 10:59:09 +0000 comments on allscore, score and register Diffstat:
3 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/allscore.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/allscore.java @@ -58,13 +58,13 @@ public class allscore extends CustomPanel { } // Split the result into rows - String[] games = leagueData.split("\n"); - Map<String, int[]> playerStats = new HashMap<>(); + String[] games = leagueData.split("\n"); //splits the leagueTable into its games + Map<String, int[]> playerStats = new HashMap<>(); //The variable playerStats is of type Map<String, int[]> for (String game : games) { try { - String[] columns = game.split(","); //mabye change later depending if it shows up + String[] columns = game.split(","); //splits the games into the users ID and the game state if (columns.length < 4) { throw new IllegalArgumentException("Malformed row: " + game); } @@ -73,7 +73,7 @@ public class allscore extends CustomPanel { String player2UID = columns[2].trim(); // Player 2 UID String gameState = columns[3].trim(); // Game state as a string - int gameStateInt = Integer.parseInt(gameState); + int gameStateInt = Integer.parseInt(gameState); //turns game state into an int for if statments // update the stats for Player one playerStats.putIfAbsent(player1UID, new int[3]); @@ -98,17 +98,17 @@ public class allscore extends CustomPanel { // Build the display string StringBuilder statsBuilder = new StringBuilder(); - statsBuilder.append(String.format("%-20s %-10s %-10s %-10s\n", "Username", "Wins", "Losses", "Draws")); +// statsBuilder.append(String.format("%-20s %-10s %-10s %-10s\n", "Username", "Wins", "Losses", "Draws"));//headers for cleaner UI statsBuilder.append("-".repeat(50)).append("\n"); for (Map.Entry<String, int[]> entry : playerStats.entrySet()) { - String username = entry.getKey(); - int wins = entry.getValue()[0]; + String username = entry.getKey(); //updates the wins, losses and draws for this specific user + int wins = entry.getValue()[0]; int losses = entry.getValue()[1]; int draws = entry.getValue()[2]; - statsBuilder.append(String.format("%-20s %-10d %-10d %-10d\n", username, wins, losses, draws)); + statsBuilder.append(String.format("%-20s %-10d %-10d %-10d\n", username, wins, losses, draws)); //prints out all the wins losses and draws along with the username } - + // Set the stats to the JTextArea statsArea.setText(statsBuilder.toString()); } catch (Exception e) { diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/register.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/register.java @@ -136,7 +136,7 @@ public class register extends CustomPanel { JOptionPane.showMessageDialog(client.frame, "Please fill in all fields"); return; } - + // stores String response = client.proxy.register(usernameTextField.getText(), passwordTextField.getText(), nameTextField.getText(), surnameTextField.getText()); System.out.println(response); diff --git a/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/score.java b/TicTacToeClient/src/main/java/com/groupproject/tictactoeclient/ContentPanes/score.java @@ -44,7 +44,7 @@ public class score extends CustomPanel { }); try { - String leagueData = client.proxy.leagueTable(); + String leagueData = client.proxy.leagueTable(); //stores our leagueTable data into leagueData variable System.out.println("League Data: " + leagueData); // Check if the response indicates no games or a database error @@ -58,27 +58,28 @@ public class score extends CustomPanel { // Prepare header for stats StringBuilder statsBuilder = new StringBuilder(); - statsBuilder.append(String.format("%-20s %-10s %-10s %-10s\n", "Username", "Wins", "Losses", "Draws")); + statsBuilder.append(String.format("%-20s %-10s %-10s %-10s\n", "Username", "Wins", "Losses", "Draws")); //headers for the user, wins, losses and draws statsBuilder.append("-".repeat(50)).append("\n"); // Process league data - String[] games = leagueData.split("\n"); - int wins = 0; + String[] games = leagueData.split("\n"); // splits the league data into its diffrent games + //counters for the wins, losses and draws + int wins = 0; int losses = 0; int draws = 0; for (String game : games) { try { - String[] columns = game.split(","); + String[] columns = game.split(","); //splits each game into player1s ID, Player2s ID and the game state if (columns.length < 4) { throw new IllegalArgumentException("Malformed row: " + game); } - + //split game stores the users ID and the game state String player1UID = columns[1].trim(); String player2UID = columns[2].trim(); String gameState = columns[3].trim(); - int gameStateInt = Integer.parseInt(gameState); - + int gameStateInt = Integer.parseInt(gameState); //turns game state into an int for if statments + //checks the game state and assigns a win, loss or draw for a user if (player1UID.equals(client.username)) { if (gameStateInt == 1) { // Player 1 wins wins++; @@ -104,7 +105,7 @@ public class score extends CustomPanel { } // Add the user's stats to the output - statsBuilder.append(String.format("%-20s %-10d %-10d %-10d\n", client.username, wins, losses, draws)); + statsBuilder.append(String.format("%-20s %-10d %-10d %-10d\n", client.username, wins, losses, draws)); //prints out all the wins, losses and draws for a user // Set the stats to the JTextArea statsArea.setText(statsBuilder.toString());