From 19be9259e8dc776157a04b180598038798ef62bd Mon Sep 17 00:00:00 2001 From: Guerrero96 Date: Tue, 30 Apr 2024 17:55:30 -0500 Subject: [PATCH] Update GameLogic.java for leaderboard --- src/main/java/uta/cse3310/GameLogic.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/uta/cse3310/GameLogic.java b/src/main/java/uta/cse3310/GameLogic.java index 7f08f7f..dc4f7b4 100644 --- a/src/main/java/uta/cse3310/GameLogic.java +++ b/src/main/java/uta/cse3310/GameLogic.java @@ -20,8 +20,9 @@ public class GameLogic { private List players; private Broadcast broadcaster; - List validWords; + private List validWords; private List allWords; + private Leaderboard leaderboard; private int gameId; @@ -34,6 +35,7 @@ public GameLogic(List players, Broadcast broadcaster) { this.wordGrid = new char[35][35]; this.broadcaster = broadcaster; this.validWords = new ArrayList<>(); + this.leaderboard = new Leaderboard(); } public int getGameId() { @@ -362,6 +364,11 @@ public int calculatePoints(String word) { return 0; // Invalid word length } } + public void updatePlayerScore(PlayerType player, String word) { + int points = calculatePoints(word); // Calculate points for the word + player.setScore(player.getScore() + points); // Update player's score + leaderboard.addOrUpdatePlayer(player, player.getScore()); // Update player's score in the leaderboard + } // Method to check if the highlighted word matches any word in the word list