Skip to content

Commit

Permalink
integrated ui with startgame method
Browse files Browse the repository at this point in the history
  • Loading branch information
Antenehden authored Aug 9, 2024
1 parent 8ac99d0 commit 8ac671a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/main/java/uta/cse3310/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public void onOpen(WebSocket conn, ClientHandshake handshake) {
System.out.println("< " + jsonString);
broadcastToGame(game, jsonString); // Broadcast to the specific game

/*if (game.getPlayers().size() == 2) {
if (game.getPlayers().size() == 2) {
game.startGame();
}*/
}
}

@Override
Expand All @@ -116,6 +116,10 @@ public void onMessage(WebSocket conn, String message) {
String jsonString = gson.toJson(game);
System.out.println("> " + jsonString);
broadcastToGame(game, jsonString); // Broadcast to the specific game
if (game.playerActionComplete) {
game.getCurrentRound().playerActionTaken();
game.playerActionComplete = false;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/uta/cse3310/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Game {
private Statistics stats;
private int gameId;
private boolean inTestingMode;
public boolean playerActionComplete;
private transient Scanner scanner; // Marked as transient

public Game(List<Player> players, String wordFilePath, String stakeFilePath, Statistics stats, Scanner scanner) throws IOException {
Expand All @@ -29,6 +30,7 @@ public Game(List<Player> players, String wordFilePath, String stakeFilePath, Sta
this.stats = stats; // Keep the passed stats
this.gameId = 0;
this.inTestingMode = false;
this.playerActionComplete = false;

for (int i = 0; i < 3; i++) {
rounds.add(new Round(players, wordFilePath, stakeFilePath, scanner));
Expand Down Expand Up @@ -98,6 +100,7 @@ public void update(UserEvent event) {
switch (action) {
case "BUY_VOWEL":
currentRound.buyVowel(currentPlayer, event.getValue().charAt(0));
playerActionComplete = true;
break;
case "SELECT_CONSONANT":
currentRound.selectConsonant(currentPlayer, event.getValue().charAt(0));
Expand All @@ -109,6 +112,8 @@ public void update(UserEvent event) {
System.out.println("Unknown action: " + action);
}

//currentRound.playerActionTaken();

// Debugging log
System.out.println("Updated game state: " + new Gson().toJson(this));
}
Expand Down Expand Up @@ -181,6 +186,10 @@ public int getCurrentRoundIndex() {
return currentRoundIndex;
}

public Round getCurrentRound() {
return rounds.get(currentRoundIndex);
}

public void determineWinner() {
Player winner = null;
int highestScore = 0;
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/uta/cse3310/Round.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Round {
private int currentPlayerIndex;
private List<Player> players;
private boolean isRoundActive;
private static final int TURN_TIME_LIMIT = 100;
private static final int TURN_TIME_LIMIT = 1000000;
private static final int VOWEL_COST = 50;
private WordList wordlist = new WordList();
private ArrayList<String> wordsforgame;
Expand All @@ -24,6 +24,8 @@ public class Round {
private transient Scanner scanner;
public boolean waitingForInput = false;
private final Object turnLock = new Object();
public final Object broadcastLock = new Object();


@SuppressWarnings("static-access")
public Round(List<Player> players, String wordFilePath, String stakeFilePath, Scanner scanner) throws IOException {
Expand Down Expand Up @@ -111,7 +113,7 @@ public void buyVowel(Player currentPlayer, char vowel) {
currentPlayer.deductScore(VOWEL_COST);
currentPlayer.buyVowel(vowel);
processGuess(currentPlayer, vowel);
playerActionTaken(); // Notify the waiting thread
//playerActionTaken(); // Notify the waiting thread
} else {
System.out.println("Invalid vowel or not enough points or already bought. Try again.");
}
Expand Down Expand Up @@ -156,7 +158,7 @@ private void processGuess(Player currentPlayer, char guessedLetter) {
if (correctguesses.equals(lettersinword)) {
System.out.println("Word guessed correctly! Round over.");
isRoundActive = false;
playerActionTaken(); // Notify the waiting thread
//playerActionTaken(); // Notify the waiting thread
} else {
currentPlayer.getTimer().reset();
//nextTurn();
Expand Down

0 comments on commit 8ac671a

Please sign in to comment.