diff --git a/src/main/java/uta/cse 3310/.DS_Store b/src/main/java/uta/cse3310/.DS_Store similarity index 100% rename from src/main/java/uta/cse 3310/.DS_Store rename to src/main/java/uta/cse3310/.DS_Store diff --git a/src/main/java/uta/cse 3310/App.java b/src/main/java/uta/cse3310/App.java similarity index 100% rename from src/main/java/uta/cse 3310/App.java rename to src/main/java/uta/cse3310/App.java diff --git a/src/main/java/uta/cse 3310/Game.java b/src/main/java/uta/cse3310/Game.java similarity index 96% rename from src/main/java/uta/cse 3310/Game.java rename to src/main/java/uta/cse3310/Game.java index fe1ac39..a8f4a47 100644 --- a/src/main/java/uta/cse 3310/Game.java +++ b/src/main/java/uta/cse3310/Game.java @@ -1,121 +1,121 @@ -package uta.cse3310; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import org.java_websocket.WebSocket; - -public class Game { - - private List players; - private List rounds; - private int currentRoundIndex; - private boolean isGameActive; - private Statistics stats; - private int gameId; - - public Game(List players, String wordFilePath, String stakeFilePath, Statistics stats) throws IOException { - this.players = players; - this.rounds = new ArrayList<>(); - this.currentRoundIndex = 0; - this.isGameActive = true; - this.stats = stats; - this.gameId = 0; - stats = new Statistics(); - - // Initialize rounds - for (int i = 0; i < 3; i++) { // Assuming a game consists of 3 rounds - rounds.add(new Round(players, wordFilePath, stakeFilePath)); - } - } - - public List getPlayers() { - return players; - } - - public void setGameId(int gameId) { - this.gameId = gameId; - } - - public void removePlayer(WebSocket conn) { - players.removeIf(player -> player.getId().equals(conn.getAttachment())); - } - - public void update(UserEvent event) { - // Implementation of update method - } - - public void startGame() { - System.out.println("Game started with " + players.size() + " players."); - startNextRound(); - } - - public void startNextRound() { - if (currentRoundIndex >= rounds.size()) { - System.out.println("All rounds completed."); - isGameActive = false; - determineWinner(); - return; - } - - Round currentRound = rounds.get(currentRoundIndex); - currentRound.startRound(); - currentRoundIndex++; - } - - public void playRound() { - if (!isGameActive) { - System.out.println("Game is not active."); - return; - } - - Round currentRound = rounds.get(currentRoundIndex - 1); // -1 because we incremented in startNextRound - while (currentRound.isRoundActive()) { - currentRound.nextTurn(); - } - - // After the round ends, start the next round - startNextRound(); - } - public void endGame(Player player) { - stats.updateWinner(player); - } - - public Statistics getStatistics() { - return stats; - } - - private void determineWinner() { - Player winner = null; - int highestScore = 0; - for (Player player : players) { - if (player.getScore() > highestScore) { - highestScore = player.getScore(); - winner = player; - } - } - - if (winner != null) { - System.out.println("The winner is " + winner.getName() + " with a score of " + highestScore); - stats.updateWinner(winner); - } else { - System.out.println("No winner determined."); - } - } - - public void resetGame() { - currentRoundIndex = 0; - isGameActive = true; - for (Round round : rounds) { - try { - round.resetRound(); - } catch (IOException e) { - System.err.println("Error resetting round: " + e.getMessage()); - } - } - } -} - - - - +package uta.cse3310; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.java_websocket.WebSocket; + +public class Game { + + private List players; + private List rounds; + private int currentRoundIndex; + private boolean isGameActive; + private Statistics stats; + private int gameId; + + public Game(List players, String wordFilePath, String stakeFilePath, Statistics stats) throws IOException { + this.players = players; + this.rounds = new ArrayList<>(); + this.currentRoundIndex = 0; + this.isGameActive = true; + this.stats = stats; + this.gameId = 0; + stats = new Statistics(); + + // Initialize rounds + for (int i = 0; i < 3; i++) { // Assuming a game consists of 3 rounds + rounds.add(new Round(players, wordFilePath, stakeFilePath)); + } + } + + public List getPlayers() { + return players; + } + + public void setGameId(int gameId) { + this.gameId = gameId; + } + + public void removePlayer(WebSocket conn) { + players.removeIf(player -> player.getId().equals(conn.getAttachment())); + } + + public void update(UserEvent event) { + // Implementation of update method + } + + public void startGame() { + System.out.println("Game started with " + players.size() + " players."); + startNextRound(); + } + + public void startNextRound() { + if (currentRoundIndex >= rounds.size()) { + System.out.println("All rounds completed."); + isGameActive = false; + determineWinner(); + return; + } + + Round currentRound = rounds.get(currentRoundIndex); + currentRound.startRound(); + currentRoundIndex++; + } + + public void playRound() { + if (!isGameActive) { + System.out.println("Game is not active."); + return; + } + + Round currentRound = rounds.get(currentRoundIndex - 1); // -1 because we incremented in startNextRound + while (currentRound.isRoundActive()) { + currentRound.nextTurn(); + } + + // After the round ends, start the next round + startNextRound(); + } + public void endGame(Player player) { + stats.updateWinner(player); + } + + public Statistics getStatistics() { + return stats; + } + + private void determineWinner() { + Player winner = null; + int highestScore = 0; + for (Player player : players) { + if (player.getScore() > highestScore) { + highestScore = player.getScore(); + winner = player; + } + } + + if (winner != null) { + System.out.println("The winner is " + winner.getName() + " with a score of " + highestScore); + stats.updateWinner(winner); + } else { + System.out.println("No winner determined."); + } + } + + public void resetGame() { + currentRoundIndex = 0; + isGameActive = true; + for (Round round : rounds) { + try { + round.resetRound(); + } catch (IOException e) { + System.err.println("Error resetting round: " + e.getMessage()); + } + } + } +} + + + + diff --git a/src/main/java/uta/cse 3310/GameTimer.java b/src/main/java/uta/cse3310/GameTimer.java similarity index 95% rename from src/main/java/uta/cse 3310/GameTimer.java rename to src/main/java/uta/cse3310/GameTimer.java index 75e35dc..872e05d 100644 --- a/src/main/java/uta/cse 3310/GameTimer.java +++ b/src/main/java/uta/cse3310/GameTimer.java @@ -1,58 +1,58 @@ -package uta.cse3310; - -import java.util.Timer; -import java.util.TimerTask; - -public class GameTimer { - - private Timer timer; - private long startTime; - private long elapsedTime; - private boolean isRunning; - - public GameTimer() { - this.timer = new Timer(); - this.elapsedTime = 0; - this.isRunning = false; - } - - public void start() { - if (isRunning) { - return; // Timer is already running - } - this.startTime = System.currentTimeMillis(); - this.isRunning = true; - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - elapsedTime = System.currentTimeMillis() - startTime; - } - }, 0, 1000); // Update elapsed time every second - } - - public void stop() { - if (!isRunning) { - return; // Timer is already stopped - } - this.timer.cancel(); - this.elapsedTime = System.currentTimeMillis() - startTime; - this.isRunning = false; - } - - public void reset() { - this.timer.cancel(); - this.timer = new Timer(); - this.elapsedTime = 0; - this.isRunning = false; - } - - public long getElapsedTime() { - return elapsedTime / 1000; // Return elapsed time in seconds - } - - public boolean isRunning() { - return isRunning; - } -} - - +package uta.cse3310; + +import java.util.Timer; +import java.util.TimerTask; + +public class GameTimer { + + private Timer timer; + private long startTime; + private long elapsedTime; + private boolean isRunning; + + public GameTimer() { + this.timer = new Timer(); + this.elapsedTime = 0; + this.isRunning = false; + } + + public void start() { + if (isRunning) { + return; // Timer is already running + } + this.startTime = System.currentTimeMillis(); + this.isRunning = true; + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + elapsedTime = System.currentTimeMillis() - startTime; + } + }, 0, 1000); // Update elapsed time every second + } + + public void stop() { + if (!isRunning) { + return; // Timer is already stopped + } + this.timer.cancel(); + this.elapsedTime = System.currentTimeMillis() - startTime; + this.isRunning = false; + } + + public void reset() { + this.timer.cancel(); + this.timer = new Timer(); + this.elapsedTime = 0; + this.isRunning = false; + } + + public long getElapsedTime() { + return elapsedTime / 1000; // Return elapsed time in seconds + } + + public boolean isRunning() { + return isRunning; + } +} + + diff --git a/src/main/java/uta/cse 3310/HttpServer.java b/src/main/java/uta/cse3310/HttpServer.java similarity index 100% rename from src/main/java/uta/cse 3310/HttpServer.java rename to src/main/java/uta/cse3310/HttpServer.java diff --git a/src/main/java/uta/cse3310/Main.java b/src/main/java/uta/cse3310/Main.java new file mode 100644 index 0000000..a6d9d94 --- /dev/null +++ b/src/main/java/uta/cse3310/Main.java @@ -0,0 +1,20 @@ +package uta.cse 3310; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + + + +public class Main { + public static void main(String[] args) + { + Word word = new Word(); + word.getWords(); + WordList wordist = new WordList(); + wordist.checkLetter(); + + } +} diff --git a/src/main/java/uta/cse 3310/Player.java b/src/main/java/uta/cse3310/Player.java similarity index 94% rename from src/main/java/uta/cse 3310/Player.java rename to src/main/java/uta/cse3310/Player.java index 3da3619..d7d8f36 100644 --- a/src/main/java/uta/cse 3310/Player.java +++ b/src/main/java/uta/cse3310/Player.java @@ -1,49 +1,49 @@ -package uta.cse3310; - -import java.util.UUID; - -public class Player { - private String id; - private String name; - private int score; - private boolean winner; - private GameTimer timer; // Updated reference - - public boolean isWinner() { - return winner; - } - - public void setWinner(boolean winner) { - this.winner = winner; - } - - public Player(String name) { - this.id = UUID.randomUUID().toString(); - this.name = name; - this.score = 0; - this.timer = new GameTimer(); // Updated reference - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public int getScore() { - return score; - } - - public void addScore(int points) { - this.score += points; - } - - public void resetScore() { - this.score = 0; - } -} - - - +package uta.cse3310; + +import java.util.UUID; + +public class Player { + private String id; + private String name; + private int score; + private boolean winner; + private GameTimer timer; // Updated reference + + public boolean isWinner() { + return winner; + } + + public void setWinner(boolean winner) { + this.winner = winner; + } + + public Player(String name) { + this.id = UUID.randomUUID().toString(); + this.name = name; + this.score = 0; + this.timer = new GameTimer(); // Updated reference + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public int getScore() { + return score; + } + + public void addScore(int points) { + this.score += points; + } + + public void resetScore() { + this.score = 0; + } +} + + + diff --git a/src/main/java/uta/cse 3310/PlayerType.java b/src/main/java/uta/cse3310/PlayerType.java similarity index 100% rename from src/main/java/uta/cse 3310/PlayerType.java rename to src/main/java/uta/cse3310/PlayerType.java diff --git a/src/main/java/uta/cse 3310/Round.java b/src/main/java/uta/cse3310/Round.java similarity index 96% rename from src/main/java/uta/cse 3310/Round.java rename to src/main/java/uta/cse3310/Round.java index 0f6d049..99eb7ed 100644 --- a/src/main/java/uta/cse 3310/Round.java +++ b/src/main/java/uta/cse3310/Round.java @@ -1,77 +1,77 @@ -package uta.cse3310; - -import java.io.IOException; -import java.util.List; - -public class Round { - private Word word; - private Stake stake; - private int currentPlayerIndex; - private List players; - private boolean isRoundActive; - - public Round(List players, String wordFilePath, String stakeFilePath) throws IOException { - this.players = players; - this.word = new Word(loadWords(wordFilePath)); - this.stake = new Stake(stakeFilePath); - this.currentPlayerIndex = 0; - this.isRoundActive = true; - } - - private String[] loadWords(String filePath) throws IOException { - List lines = java.nio.file.Files.readAllLines(java.nio.file.Paths.get(filePath)); - return lines.toArray(new String[0]); - } - - public void startRound() { - System.out.println("New round started. Word to guess: " + word.getWordProgress()); - } - - public void nextTurn() { - if (!isRoundActive) { - System.out.println("Round is not active."); - return; - } - - Player currentPlayer = players.get(currentPlayerIndex); - System.out.println("Current player: " + currentPlayer.getName()); - - char guessedLetter = 'a'; // Replace with actual guess from player input - boolean isCorrect = word.guessLetter(guessedLetter); - if (isCorrect) { - System.out.println("Correct guess!"); - } else { - System.out.println("Incorrect guess."); - } - - if (word.isFullyGuessed()) { - System.out.println("Word guessed correctly! Round over."); - isRoundActive = false; - } else { - currentPlayerIndex = (currentPlayerIndex + 1) % players.size(); - } - } - - public String getCurrentWordProgress() { - return word.getWordProgress(); - } - - /* public String getCurrentStake() { - return stake.getCurrentStake(); - }*/ - - public void resetRound() throws IOException { - this.word.reset(); - // this.stake.reset(); - this.currentPlayerIndex = 0; - this.isRoundActive = true; - } - - public boolean isRoundActive() { - return isRoundActive; - } -} - - - - +package uta.cse3310; + +import java.io.IOException; +import java.util.List; + +public class Round { + private Word word; + private Stake stake; + private int currentPlayerIndex; + private List players; + private boolean isRoundActive; + + public Round(List players, String wordFilePath, String stakeFilePath) throws IOException { + this.players = players; + this.word = new Word(loadWords(wordFilePath)); + this.stake = new Stake(stakeFilePath); + this.currentPlayerIndex = 0; + this.isRoundActive = true; + } + + private String[] loadWords(String filePath) throws IOException { + List lines = java.nio.file.Files.readAllLines(java.nio.file.Paths.get(filePath)); + return lines.toArray(new String[0]); + } + + public void startRound() { + System.out.println("New round started. Word to guess: " + word.getWordProgress()); + } + + public void nextTurn() { + if (!isRoundActive) { + System.out.println("Round is not active."); + return; + } + + Player currentPlayer = players.get(currentPlayerIndex); + System.out.println("Current player: " + currentPlayer.getName()); + + char guessedLetter = 'a'; // Replace with actual guess from player input + boolean isCorrect = word.guessLetter(guessedLetter); + if (isCorrect) { + System.out.println("Correct guess!"); + } else { + System.out.println("Incorrect guess."); + } + + if (word.isFullyGuessed()) { + System.out.println("Word guessed correctly! Round over."); + isRoundActive = false; + } else { + currentPlayerIndex = (currentPlayerIndex + 1) % players.size(); + } + } + + public String getCurrentWordProgress() { + return word.getWordProgress(); + } + + /* public String getCurrentStake() { + return stake.getCurrentStake(); + }*/ + + public void resetRound() throws IOException { + this.word.reset(); + // this.stake.reset(); + this.currentPlayerIndex = 0; + this.isRoundActive = true; + } + + public boolean isRoundActive() { + return isRoundActive; + } +} + + + + diff --git a/src/main/java/uta/cse 3310/ServerEvent.java b/src/main/java/uta/cse3310/ServerEvent.java similarity index 100% rename from src/main/java/uta/cse 3310/ServerEvent.java rename to src/main/java/uta/cse3310/ServerEvent.java diff --git a/src/main/java/uta/cse 3310/Stake.java b/src/main/java/uta/cse3310/Stake.java similarity index 94% rename from src/main/java/uta/cse 3310/Stake.java rename to src/main/java/uta/cse3310/Stake.java index 6062bf9..d0b2d41 100644 --- a/src/main/java/uta/cse 3310/Stake.java +++ b/src/main/java/uta/cse3310/Stake.java @@ -1,30 +1,30 @@ -package uta.cse3310; - -public class Stake { - private String currentStake; - - // Default constructor - public Stake() { - } - - // Constructor that accepts a string argument - public Stake(String currentStake) { - this.currentStake = currentStake; - } - - public String getCurrentStake() { - return currentStake; - } - - public void setCurrentStake(String currentStake) { - this.currentStake = currentStake; - } - - public void reset() { - this.currentStake = null; // Or any default value - } -} - - - - +package uta.cse3310; + +public class Stake { + private String currentStake; + + // Default constructor + public Stake() { + } + + // Constructor that accepts a string argument + public Stake(String currentStake) { + this.currentStake = currentStake; + } + + public String getCurrentStake() { + return currentStake; + } + + public void setCurrentStake(String currentStake) { + this.currentStake = currentStake; + } + + public void reset() { + this.currentStake = null; // Or any default value + } +} + + + + diff --git a/src/main/java/uta/cse 3310/Statistics.java b/src/main/java/uta/cse3310/Statistics.java similarity index 100% rename from src/main/java/uta/cse 3310/Statistics.java rename to src/main/java/uta/cse3310/Statistics.java diff --git a/src/main/java/uta/cse 3310/UserEvent.java b/src/main/java/uta/cse3310/UserEvent.java similarity index 100% rename from src/main/java/uta/cse 3310/UserEvent.java rename to src/main/java/uta/cse3310/UserEvent.java diff --git a/src/main/java/uta/cse 3310/Word.java b/src/main/java/uta/cse3310/Word.java similarity index 96% rename from src/main/java/uta/cse 3310/Word.java rename to src/main/java/uta/cse3310/Word.java index b383228..7f54858 100644 --- a/src/main/java/uta/cse 3310/Word.java +++ b/src/main/java/uta/cse3310/Word.java @@ -1,62 +1,62 @@ -package uta.cse3310; - -import java.util.Random; - -public class Word { - - private String[] words; - private String selectedWord; - private boolean[] guessedLetters; - - public Word(String[] wordList) { - this.words = wordList; - selectRandomWord(); - } - - private void selectRandomWord() { - Random rand = new Random(); - selectedWord = words[rand.nextInt(words.length)]; - guessedLetters = new boolean[selectedWord.length()]; - } - - public String getSelectedWord() { - return selectedWord; - } - - public boolean guessLetter(char letter) { - boolean found = false; - for (int i = 0; i < selectedWord.length(); i++) { - if (selectedWord.charAt(i) == letter) { - guessedLetters[i] = true; - found = true; - } - } - return found; - } - - public String getWordProgress() { - StringBuilder progress = new StringBuilder(); - for (int i = 0; i < selectedWord.length(); i++) { - if (guessedLetters[i]) { - progress.append(selectedWord.charAt(i)); - } else { - progress.append('_'); - } - } - return progress.toString(); - } - - public boolean isFullyGuessed() { - for (boolean guessed : guessedLetters) { - if (!guessed) { - return false; - } - } - return true; - } - - public void reset() { - selectRandomWord(); - } -} - +package uta.cse3310; + +import java.util.Random; + +public class Word { + + private String[] words; + private String selectedWord; + private boolean[] guessedLetters; + + public Word(String[] wordList) { + this.words = wordList; + selectRandomWord(); + } + + private void selectRandomWord() { + Random rand = new Random(); + selectedWord = words[rand.nextInt(words.length)]; + guessedLetters = new boolean[selectedWord.length()]; + } + + public String getSelectedWord() { + return selectedWord; + } + + public boolean guessLetter(char letter) { + boolean found = false; + for (int i = 0; i < selectedWord.length(); i++) { + if (selectedWord.charAt(i) == letter) { + guessedLetters[i] = true; + found = true; + } + } + return found; + } + + public String getWordProgress() { + StringBuilder progress = new StringBuilder(); + for (int i = 0; i < selectedWord.length(); i++) { + if (guessedLetters[i]) { + progress.append(selectedWord.charAt(i)); + } else { + progress.append('_'); + } + } + return progress.toString(); + } + + public boolean isFullyGuessed() { + for (boolean guessed : guessedLetters) { + if (!guessed) { + return false; + } + } + return true; + } + + public void reset() { + selectRandomWord(); + } +} + diff --git a/src/main/java/uta/cse 3310/WordList.java b/src/main/java/uta/cse3310/WordList.java similarity index 96% rename from src/main/java/uta/cse 3310/WordList.java rename to src/main/java/uta/cse3310/WordList.java index d68164f..3c422f9 100644 --- a/src/main/java/uta/cse 3310/WordList.java +++ b/src/main/java/uta/cse3310/WordList.java @@ -1,40 +1,40 @@ -package uta.cse3310; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class WordList { - - private List words; - - public WordList(String filePath) throws IOException { - loadWords(filePath); - } - - private void loadWords(String filePath) throws IOException { - words = Files.readAllLines(Paths.get(filePath)); - } - - public String getRandomWord() { - Random rand = new Random(); - return words.get(rand.nextInt(words.size())); - } - - public List getWords() { - return new ArrayList<>(words); - } - - public static void main(String[] args) { - try { - WordList wordList = new WordList("path/to/words.txt"); - System.out.println("Random word: " + wordList.getRandomWord()); - } catch (IOException e) { - System.err.println("Error loading words: " + e.getMessage()); - } - } -} - +package uta.cse3310; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class WordList { + + private List words; + + public WordList(String filePath) throws IOException { + loadWords(filePath); + } + + private void loadWords(String filePath) throws IOException { + words = Files.readAllLines(Paths.get(filePath)); + } + + public String getRandomWord() { + Random rand = new Random(); + return words.get(rand.nextInt(words.size())); + } + + public List getWords() { + return new ArrayList<>(words); + } + + public static void main(String[] args) { + try { + WordList wordList = new WordList("path/to/words.txt"); + System.out.println("Random word: " + wordList.getRandomWord()); + } catch (IOException e) { + System.err.println("Error loading words: " + e.getMessage()); + } + } +} + diff --git a/src/test/Java/uta/cse3310/UserEventTest.java b/src/test/Java/uta/cse3310/UserEventTest.java index fa38124..037253d 100644 --- a/src/test/Java/uta/cse3310/UserEventTest.java +++ b/src/test/Java/uta/cse3310/UserEventTest.java @@ -1,5 +1,6 @@ package uta.cse3310; -package org.junit.jupiter.api; +//package org.junit.jupiter.api; +//import org.junit.jupiter.api; import org.junit.jupiter.api.BeforeEach;