generated from BudDavis/TicTacToe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebfbe3d
commit 5a3285b
Showing
16 changed files
with
459 additions
and
438 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
242 changes: 121 additions & 121 deletions
242
src/main/java/uta/cse 3310/Game.java → src/main/java/uta/cse3310/Game.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Player> players; | ||
private List<Round> rounds; | ||
private int currentRoundIndex; | ||
private boolean isGameActive; | ||
private Statistics stats; | ||
private int gameId; | ||
|
||
public Game(List<Player> 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<Player> 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<Player> players; | ||
private List<Round> rounds; | ||
private int currentRoundIndex; | ||
private boolean isGameActive; | ||
private Statistics stats; | ||
private int gameId; | ||
|
||
public Game(List<Player> 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<Player> 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()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
116 changes: 58 additions & 58 deletions
116
src/main/java/uta/cse 3310/GameTimer.java → src/main/java/uta/cse3310/GameTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
||
} | ||
} |
Oops, something went wrong.