diff --git a/src/main/java/edu/sdccd/cisc191/game/GalacticShip.java b/src/main/java/edu/sdccd/cisc191/game/GalacticShip.java index 1aaddc9..3ccc7fa 100644 --- a/src/main/java/edu/sdccd/cisc191/game/GalacticShip.java +++ b/src/main/java/edu/sdccd/cisc191/game/GalacticShip.java @@ -8,9 +8,11 @@ * Each ship has a name, health, attack power, and combat abilities, and can engage in combat. */ public class GalacticShip { + // TODO: make field final, since they are never changed after initialization private String name; private int health; private int attackPower; + // TODO: make field final, since they are never changed after initialization private List combatAbilities; /** diff --git a/src/main/java/edu/sdccd/cisc191/game/Game.java b/src/main/java/edu/sdccd/cisc191/game/Game.java index b79a3cd..2e3ad63 100644 --- a/src/main/java/edu/sdccd/cisc191/game/Game.java +++ b/src/main/java/edu/sdccd/cisc191/game/Game.java @@ -3,6 +3,7 @@ import edu.sdccd.cisc191.subsystems.CombatSystem; import edu.sdccd.cisc191.subsystems.ExplorationSystem; import edu.sdccd.cisc191.subsystems.ResourceManagement; +// TODO: remove unused import import edu.sdccd.cisc191.game.PlayerInventory; import edu.sdccd.cisc191.utilities.GameUI; @@ -27,6 +28,8 @@ // Main Game Class (Integrates JavaFX, Shipyard System, and Exploration System) public class Game extends Application { + // TODO: break Game into different classes for UI, game logic, and subsystems + // TODO: create separate packages for game resources, like Planet, Player, PlayerInventory, etc. private Shipyard shipyard; private ExplorationSystem explorationSystem; private ResourceManagement resourceManagement; @@ -56,7 +59,8 @@ public static void main(String[] args) { // Launch the JavaFX application } @Override - public void start (Stage primaryStage) { // Main window + public void start (Stage primaryStage) {// Main window + // TODO: split this portion to load game into a separate method // Initialize game components shipyard = new Shipyard(); explorationSystem = new ExplorationSystem(); @@ -72,17 +76,21 @@ public void start (Stage primaryStage) { // Main window gameState = GameState.MENU; // Create UI elements + // TODO: separate these methods to load specific javafx components into separate components statusLabel = new Label("Welcome to Galactic Strategy! (Press ENTER to start)"); fleetListView = new ListView<>(); updateFleetDisplay(); // Load fleet data gameLog = new TextArea(); gameLog.setEditable(false); + // TODO: make this view larger in order to display more player information gameLog.setPrefHeight(150); resourceLabel = new Label("Resources:\n" + inventory.displayResources()); // Shipyard UI Buttons + // TODO: utilize JavaFX CSS styling to add more detail and differentiation between these buttons + // TODO: display all buttons if the GameState is menu, paused, or gameover Button buildFighterBtn = new Button("Build Fighter (10 Minerals, 5 Energy)"); Button buildCruiserBtn = new Button("Build Cruiser (15 Minerals, 7 Energy)"); Button buildBattleshipBtn = new Button("Build Battleship (20 Minerals, 10 Energy)"); @@ -114,6 +122,7 @@ public void start (Stage primaryStage) { // Main window HBox moveRow2 = new HBox(10, leftBtn, downBtn, rightBtn); VBox movementControls = new VBox(5, moveRow1, moveRow2); + // TODO: add UI component to display amount of minerals, energy of user within the javafx UI // Layout for the UI VBox layout = new VBox(10); @@ -121,13 +130,14 @@ public void start (Stage primaryStage) { // Main window statusLabel, locationLabel, fleetListView, buildFighterBtn, buildCruiserBtn, buildBattleshipBtn, upgradeShipBtn, gatherDilithiumBtn, planetSelector, exploreBtn, movementControls, gameLog, resourceLabel - );; + ); Scene scene = new Scene(layout, 500, 600); // Keyboard controls for game state changes scene.setOnKeyPressed(event -> handleKeyPress(event.getCode())); + primaryStage.setTitle("Galactic Strategy"); // Set Title window (Primary stage) primaryStage.setScene(scene); // Attach the scene to the primary stage primaryStage.show(); // Displays primary stage (Opens window) @@ -148,16 +158,17 @@ public void handle(long now) { // 'now' is the current timestamp in nanoseconds } // Handles keyboard input for game state management + // TODO: remap buttons, ENTER and ESCAPE for start and ending respectively don't appear to work, at least on Mac private void handleKeyPress(KeyCode key) { switch (key) { - case ENTER: + case A: if (gameState == GameState.MENU) gameState = GameState.PLAYING; break; case P: if (gameState == GameState.PLAYING) gameState = GameState.PAUSED; else if (gameState == GameState.PAUSED) gameState = GameState.PLAYING; break; - case ESCAPE: + case E: gameState = GameState.GAME_OVER; break; } @@ -195,12 +206,13 @@ private void handleMove(String direction) { locationLabel.setText("Location: (" + r + "," + c + ")"); statusLabel.setText(planet.equals("Unknown") ? "Empty space" : "Arrived at " + planet); resourceLabel.setText("Resource:\n" + inventory.displayResources()); - gameLog.appendText("Moved " + direction + " to (" + r + "," + c + ")\n"); + gameUI.appendMessage("Moved " + direction + " to (" + r + "," + c + ")\n"); } else { statusLabel.setText("Move failed (no fuel or out of bounds)"); } } + // TODO: delete this method to test combat that is never used private void runCombatExample() { GalacticShip playerShip = new GalacticShip("Enterprise", 100, 20); GalacticShip enemyShip = new GalacticShip("Klingon Raider", 80, 18); @@ -212,7 +224,6 @@ private void runCombatExample() { // Optionally, display result in the UI if gameUI is available if (gameUI != null) { if (playerShip.isDestroyed()) { - gameUI.appendMessage(playerShip.getName() + "was destroyed! GAME OVER!"); } else if (enemyShip.isDestroyed()) { gameUI.appendMessage(playerShip.getName() + "was destroyed! Victory!"); @@ -220,6 +231,7 @@ private void runCombatExample() { } } + // TODO: delete this method to load UI that was never used private void setupUI(Stage stage) { gameUI = new GameUI(); StackPane root = new StackPane(); @@ -238,6 +250,7 @@ private void setupUI(Stage stage) { * @param shipType The Type of ship to build */ private void buildShip(String shipType, int mineralsCost, int energyCost) { + System.out.println(mineralsCost + " " + energyCost + " " + shipType); if (inventory == null || !inventory.useResource("Minerals", mineralsCost) || !inventory.useResource("Energy", energyCost)) { statusLabel.setText("Not enough resources to build " + shipType); return; diff --git a/src/main/java/edu/sdccd/cisc191/game/GameBoard.java b/src/main/java/edu/sdccd/cisc191/game/GameBoard.java index 03d3c0c..9b05b72 100644 --- a/src/main/java/edu/sdccd/cisc191/game/GameBoard.java +++ b/src/main/java/edu/sdccd/cisc191/game/GameBoard.java @@ -1,6 +1,7 @@ package edu.sdccd.cisc191.game; public class GameBoard { + // TODO: planets and resourceCosts could be final, since they are never changed after initialization private int[][] planets; // Represents planets in the galaxy (0 = empty, other values = planet IDs) private int[][] resourceCosts; // Represents resource cost to traverse each cell private final int rows = 5; @@ -63,6 +64,7 @@ public int getPlanetId(int row, int col) { return planets[row][col]; } + // TODO: write javadocs for the remaining methods within the class public int getResourceCost(int row, int col) { return resourceCosts[row][col]; } @@ -71,6 +73,7 @@ public boolean inBounds(int row, int col) { return row >= 0 && row < rows && col >= 0 && col < cols; } + // TODO: delete or implement unused displayBoard method public void displayBoard() { System.out.println("Planets:"); for (int i = 0; i < rows; i++) { diff --git a/src/main/java/edu/sdccd/cisc191/game/Planet.java b/src/main/java/edu/sdccd/cisc191/game/Planet.java index 77d9258..1eb72fb 100644 --- a/src/main/java/edu/sdccd/cisc191/game/Planet.java +++ b/src/main/java/edu/sdccd/cisc191/game/Planet.java @@ -9,6 +9,7 @@ public class Planet { public final String neptune; // Existing 5-argument constructor + // TODO: remove extra unused constructor public Planet(String mars, String jupiter, String earth, String andromeda, String neptune) { this.mars = mars; this.earth = earth; @@ -26,6 +27,8 @@ public Planet(String planetName) { this.neptune = "Neptune".equalsIgnoreCase(planetName) ? planetName : null; } + // TODO: implement or delete unused methods + // TODO: for these methods, if the planet is not found, return a default value of null. public String getEarth() { return earth != null ? earth : "Earth"; } diff --git a/src/main/java/edu/sdccd/cisc191/game/Player.java b/src/main/java/edu/sdccd/cisc191/game/Player.java index cc5b386..c059e66 100644 --- a/src/main/java/edu/sdccd/cisc191/game/Player.java +++ b/src/main/java/edu/sdccd/cisc191/game/Player.java @@ -9,7 +9,9 @@ * Each player has a name and a fleet of GalacticShips. */ public class Player { + // TODO: set the name and fleet fields to final, since they are never changed after initialization private String name; + // TODO: make fleet a LinkedList (video explanation says that this should be a LinkedList but is type List) private List fleet; /** @@ -22,6 +24,7 @@ public Player(String name) { this.fleet = new ArrayList<>(); } + // TODO: use a library like lombok to auto generate getters and setters public String getName() { return name; } @@ -35,6 +38,7 @@ public List getFleet() { * * @param ship The GalacticShip to add. */ + // TODO: remove the duplicate ship addition to the ArrayList public void addShip(GalacticShip ship) { fleet.add(ship); fleet.add(ship); @@ -52,4 +56,6 @@ public int getTotalFleetHealth() { } return totalHealth; } + + // TODO: implement a method to use a Linear Search to find ships within the fleet List } \ No newline at end of file diff --git a/src/main/java/edu/sdccd/cisc191/game/PlayerInventory.java b/src/main/java/edu/sdccd/cisc191/game/PlayerInventory.java index 86f71f9..5066c34 100644 --- a/src/main/java/edu/sdccd/cisc191/game/PlayerInventory.java +++ b/src/main/java/edu/sdccd/cisc191/game/PlayerInventory.java @@ -5,12 +5,14 @@ import java.util.Map; // Manages player's inventory of resources +// TODO: implement PlayerInventory to a database public class PlayerInventory implements Serializable { private Map resources; public PlayerInventory() { resources = new HashMap<>(); resources.put("Fuel", new Resource("Dilithium")); + // TODO: remove duplicate "Minerals" entry, or rename the first minerals to be Fuel resources.put("Minerals", new Resource("Fuel")); resources.put("Minerals", new Resource("Minerals")); resources.put("Energy", new Resource("Energy")); diff --git a/src/main/java/edu/sdccd/cisc191/game/Resource.java b/src/main/java/edu/sdccd/cisc191/game/Resource.java index 774e1ea..a12ff1f 100644 --- a/src/main/java/edu/sdccd/cisc191/game/Resource.java +++ b/src/main/java/edu/sdccd/cisc191/game/Resource.java @@ -14,6 +14,7 @@ public class Resource implements Serializable { public Resource(String name) { this.name = name; + // TODO: no parameter in the constructor for amount, either remove it from the constructor or set it to 0 by default this.amount = amount; } diff --git a/src/main/java/edu/sdccd/cisc191/game/Shipyard.java b/src/main/java/edu/sdccd/cisc191/game/Shipyard.java index 108b9bc..ab9a9c9 100644 --- a/src/main/java/edu/sdccd/cisc191/game/Shipyard.java +++ b/src/main/java/edu/sdccd/cisc191/game/Shipyard.java @@ -28,7 +28,7 @@ public class Shipyard { // Constructs a Shipyard with predefined ship options public Shipyard() { this.availableShips = new HashMap<>(); - this.playerFleet = new ArrayList<>(); + this.playerFleet = new ArrayList<>(); // TODO: integrate with the Player by allowing a Shipyard to take in a Player object, and initializing playerFleet to the the player's fleet object this.shipBuilderPool = Executors.newFixedThreadPool(2); // Allows 2 ships to be built at a time initializeShipyard(); @@ -110,6 +110,7 @@ public void displayPlayerFleet() { } } + // TODO: add a method to be used in saveShipyardState() and loadShipyardState() to check first if the file exists, and if it doesn't to create a file ships.json in the resources folder /* * Retrieves the player's fleet * @return List of GalacticShips in the player's fleet @@ -124,6 +125,7 @@ private void saveShipyardState() { out.writeObject(playerFleet); System.out.println("Shipyard state saved."); } catch (IOException e) { + // TODO: if file doesn't exist, create it. System.err.println("Error saving shipyard state: " + e.getMessage()); } } diff --git a/src/main/java/edu/sdccd/cisc191/network/MultiplayerHandler.java b/src/main/java/edu/sdccd/cisc191/network/MultiplayerHandler.java index edf2f56..63dfbfd 100644 --- a/src/main/java/edu/sdccd/cisc191/network/MultiplayerHandler.java +++ b/src/main/java/edu/sdccd/cisc191/network/MultiplayerHandler.java @@ -14,6 +14,7 @@ * - Provides utility methods for managing game state */ +// TODO: delete or implement unused Server code public class MultiplayerHandler { public final Map players; // Map to store player data by unique ID diff --git a/src/main/java/edu/sdccd/cisc191/network/MultiplayerServer.java b/src/main/java/edu/sdccd/cisc191/network/MultiplayerServer.java index 62d7b12..756dec7 100644 --- a/src/main/java/edu/sdccd/cisc191/network/MultiplayerServer.java +++ b/src/main/java/edu/sdccd/cisc191/network/MultiplayerServer.java @@ -15,8 +15,10 @@ public class MultiplayerServer { private static final int PORT = 5000; // Port for communication + // TODO: clientWriters never changed, so it could be final private static Set clientWriters = new HashSet<>(); + // TODO: replace System.out.println calls with loggers public static void main(String[] args) { System.out.println("Multiplayer Server Started..."); try (ServerSocket serverSocket = new ServerSocket (PORT)) { diff --git a/src/main/java/edu/sdccd/cisc191/subsystems/ResourceManagement.java b/src/main/java/edu/sdccd/cisc191/subsystems/ResourceManagement.java index d4d8db9..db331cc 100644 --- a/src/main/java/edu/sdccd/cisc191/subsystems/ResourceManagement.java +++ b/src/main/java/edu/sdccd/cisc191/subsystems/ResourceManagement.java @@ -10,12 +10,14 @@ public class ResourceManagement { private final Lock lock = new ReentrantLock(); + // TODO: clean up multiple different gatherResources methods public void gatherResources(Player player, String resourceName, PlayerInventory inventory) { lock.lock(); try { int collectedAmount = (int) (Math.random() * 10 + 5); // Random between 5-15 inventory.addResource(resourceName, collectedAmount); - System.out.println(player.getName() + " collcted " + collectedAmount + " " + resourceName + "!"); + // TODO: replace System.out.println with logging this information to the in-game UI log + System.out.println(player.getName() + " collected " + collectedAmount + " " + resourceName + "!"); } finally { lock.unlock(); } @@ -25,7 +27,8 @@ public void gatherResources(Player player2, Resource dilithium) { lock.lock(); try { int collectedAmount = (int) (Math.random() * 10 + 5); - System.out.println(player2.getName() + " collcted " + collectedAmount + " " + player2.getName() + "!"); + // TODO: replace System.out.println with logging this information to the in-game UI log + System.out.println(player2.getName() + " collected " + collectedAmount + " " + player2.getName() + "!"); } finally { lock.unlock(); } diff --git a/src/main/java/edu/sdccd/cisc191/utilities/Leaderboard.java b/src/main/java/edu/sdccd/cisc191/utilities/Leaderboard.java index 709727d..c1127b2 100644 --- a/src/main/java/edu/sdccd/cisc191/utilities/Leaderboard.java +++ b/src/main/java/edu/sdccd/cisc191/utilities/Leaderboard.java @@ -1,4 +1,5 @@ package edu.sdccd.cisc191.utilities; +// TODO: delete or implement unused Leaderboard class public class Leaderboard { }