From e93ac33ce6ccd6f214d314c50f5076a14561b991 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 11:49:14 -0500 Subject: [PATCH 01/11] Move map use cases into their own folder --- src/main/java/com/mg105/Application.java | 4 +++ .../interface_adapters/InputInterpreter.java | 2 +- .../ReplayGeneratorInterpreter.java | 2 +- .../mg105/interface_adapters/WinDisplay.java | 2 +- .../{ => map}/MapGeneratorInterpreter.java | 4 +-- .../{ => map}/MinimapInterpreter.java | 4 +-- .../{ => map}/RoomInterpreter.java | 5 +-- .../com/mg105/use_cases/ChestInteractor.java | 1 + .../use_cases/{ => map}/CharacterMover.java | 3 +- .../use_cases/{ => map}/MapGenerator.java | 34 +++++++++---------- .../use_cases/{ => map}/ReplayGenerator.java | 5 +-- .../mg105/use_cases/{ => map}/RoomGetter.java | 6 ++-- .../use_cases/{ => map}/RoomUpdater.java | 2 +- .../com/mg105/user_interface/MapDrawer.java | 2 +- .../user_interface/MapGeneratorButton.java | 2 +- .../mg105/user_interface/MinimapDrawer.java | 2 +- .../java/com/mg105/entities/ChestTest.java | 2 +- .../mg105/use_cases/CharacterMoverTest.java | 2 ++ .../mg105/use_cases/ReplayGeneratorTest.java | 1 + .../use_cases/{ => map}/MapGeneratorTest.java | 5 +-- .../use_cases/{ => map}/RoomGetterTest.java | 4 +-- .../use_cases/{ => map}/RoomLayoutTest.java | 6 ++-- .../use_cases/{ => map}/RoomUpdaterTest.java | 4 +-- 23 files changed, 57 insertions(+), 47 deletions(-) rename src/main/java/com/mg105/interface_adapters/{ => map}/MapGeneratorInterpreter.java (89%) rename src/main/java/com/mg105/interface_adapters/{ => map}/MinimapInterpreter.java (98%) rename src/main/java/com/mg105/interface_adapters/{ => map}/RoomInterpreter.java (95%) rename src/main/java/com/mg105/use_cases/{ => map}/CharacterMover.java (99%) rename src/main/java/com/mg105/use_cases/{ => map}/MapGenerator.java (93%) rename src/main/java/com/mg105/use_cases/{ => map}/ReplayGenerator.java (93%) rename src/main/java/com/mg105/use_cases/{ => map}/RoomGetter.java (96%) rename src/main/java/com/mg105/use_cases/{ => map}/RoomUpdater.java (97%) rename src/test/java/com/mg105/use_cases/{ => map}/MapGeneratorTest.java (90%) rename src/test/java/com/mg105/use_cases/{ => map}/RoomGetterTest.java (98%) rename src/test/java/com/mg105/use_cases/{ => map}/RoomLayoutTest.java (94%) rename src/test/java/com/mg105/use_cases/{ => map}/RoomUpdaterTest.java (95%) diff --git a/src/main/java/com/mg105/Application.java b/src/main/java/com/mg105/Application.java index 6ad16f7a..80189ecc 100644 --- a/src/main/java/com/mg105/Application.java +++ b/src/main/java/com/mg105/Application.java @@ -1,6 +1,9 @@ package com.mg105; import com.mg105.interface_adapters.battle.BattlePresenter; +import com.mg105.interface_adapters.map.MapGeneratorInterpreter; +import com.mg105.interface_adapters.map.MinimapInterpreter; +import com.mg105.interface_adapters.map.RoomInterpreter; import com.mg105.interface_adapters.tutorial.TutorialTextController; import com.mg105.data_control.access.MoveDataAccess; import com.mg105.data_control.access.PartyDataAccess; @@ -11,6 +14,7 @@ import com.mg105.interface_adapters.inventory.InventoryController; import com.mg105.interface_adapters.inventory.InventoryPresenter; import com.mg105.use_cases.battle.BattleInteractor; +import com.mg105.use_cases.map.*; import com.mg105.user_interface.*; import com.mg105.use_cases.*; import com.mg105.use_cases.inventory.InventoryInteractor; diff --git a/src/main/java/com/mg105/interface_adapters/InputInterpreter.java b/src/main/java/com/mg105/interface_adapters/InputInterpreter.java index ab3db2de..4d02a94c 100644 --- a/src/main/java/com/mg105/interface_adapters/InputInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/InputInterpreter.java @@ -2,7 +2,7 @@ import com.mg105.use_cases.ChestInteractor; import com.mg105.interface_adapters.tutorial.TutorialTextController; -import com.mg105.use_cases.CharacterMover; +import com.mg105.use_cases.map.CharacterMover; import com.mg105.use_cases.OpponentSetInteractor; import com.mg105.utils.TutorialTexts; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java b/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java index 4f708934..79d14cc8 100644 --- a/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java @@ -1,6 +1,6 @@ package com.mg105.interface_adapters; -import com.mg105.use_cases.ReplayGenerator; +import com.mg105.use_cases.map.ReplayGenerator; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/com/mg105/interface_adapters/WinDisplay.java b/src/main/java/com/mg105/interface_adapters/WinDisplay.java index 8e98af35..95a08401 100644 --- a/src/main/java/com/mg105/interface_adapters/WinDisplay.java +++ b/src/main/java/com/mg105/interface_adapters/WinDisplay.java @@ -1,6 +1,6 @@ package com.mg105.interface_adapters; -import com.mg105.use_cases.RoomGetter; +import com.mg105.use_cases.map.RoomGetter; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; diff --git a/src/main/java/com/mg105/interface_adapters/MapGeneratorInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java similarity index 89% rename from src/main/java/com/mg105/interface_adapters/MapGeneratorInterpreter.java rename to src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java index f15d5be6..1524a164 100644 --- a/src/main/java/com/mg105/interface_adapters/MapGeneratorInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java @@ -1,6 +1,6 @@ -package com.mg105.interface_adapters; +package com.mg105.interface_adapters.map; -import com.mg105.use_cases.MapGenerator; +import com.mg105.use_cases.map.MapGenerator; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/com/mg105/interface_adapters/MinimapInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java similarity index 98% rename from src/main/java/com/mg105/interface_adapters/MinimapInterpreter.java rename to src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java index 682b1c70..acb2b614 100644 --- a/src/main/java/com/mg105/interface_adapters/MinimapInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java @@ -1,7 +1,7 @@ -package com.mg105.interface_adapters; +package com.mg105.interface_adapters.map; import com.mg105.use_cases.Resetable; -import com.mg105.use_cases.RoomGetter; +import com.mg105.use_cases.map.RoomGetter; import com.mg105.use_cases.outputds.RoomLayout; import com.mg105.utils.MapConstants; import com.mg105.utils.PointComparator; diff --git a/src/main/java/com/mg105/interface_adapters/RoomInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java similarity index 95% rename from src/main/java/com/mg105/interface_adapters/RoomInterpreter.java rename to src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java index 51713cdf..9d2c91a4 100644 --- a/src/main/java/com/mg105/interface_adapters/RoomInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java @@ -1,6 +1,7 @@ -package com.mg105.interface_adapters; +package com.mg105.interface_adapters.map; -import com.mg105.use_cases.RoomGetter; +import com.mg105.interface_adapters.TileType; +import com.mg105.use_cases.map.RoomGetter; import com.mg105.use_cases.outputds.RoomLayout; import com.mg105.utils.MapConstants; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/mg105/use_cases/ChestInteractor.java b/src/main/java/com/mg105/use_cases/ChestInteractor.java index 114beec8..801fc184 100644 --- a/src/main/java/com/mg105/use_cases/ChestInteractor.java +++ b/src/main/java/com/mg105/use_cases/ChestInteractor.java @@ -8,6 +8,7 @@ import com.mg105.entities.Room; import com.mg105.entities.TreasureChest; import com.mg105.use_cases.inventory.InventoryInteractor; +import com.mg105.use_cases.map.RoomUpdater; import org.jetbrains.annotations.NotNull; public class ChestInteractor { diff --git a/src/main/java/com/mg105/use_cases/CharacterMover.java b/src/main/java/com/mg105/use_cases/map/CharacterMover.java similarity index 99% rename from src/main/java/com/mg105/use_cases/CharacterMover.java rename to src/main/java/com/mg105/use_cases/map/CharacterMover.java index 4279992d..3ae7320b 100644 --- a/src/main/java/com/mg105/use_cases/CharacterMover.java +++ b/src/main/java/com/mg105/use_cases/map/CharacterMover.java @@ -1,4 +1,4 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import com.mg105.entities.*; import com.mg105.utils.MapConstants; @@ -94,7 +94,6 @@ public void generateMapMoveBy(Point direction) { * * @param currentRoom the current room you are in * @param nextRoom the room you will be in. - * * @return the position you would be in nextRoom if just exiting from currentRoom. */ private @NotNull Point getNextRoomPosition(@NotNull Room currentRoom, @NotNull Room nextRoom) { diff --git a/src/main/java/com/mg105/use_cases/MapGenerator.java b/src/main/java/com/mg105/use_cases/map/MapGenerator.java similarity index 93% rename from src/main/java/com/mg105/use_cases/MapGenerator.java rename to src/main/java/com/mg105/use_cases/map/MapGenerator.java index 96af050d..46c68fc8 100644 --- a/src/main/java/com/mg105/use_cases/MapGenerator.java +++ b/src/main/java/com/mg105/use_cases/map/MapGenerator.java @@ -1,4 +1,4 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import com.mg105.entities.*; import com.mg105.entities.items.HealthPotion; @@ -53,7 +53,7 @@ public MapGenerator(@NotNull GameState state, @NotNull Random random) { */ public void generateMap() { Room firstRoom = generateEmptyRoom(); - Room lastRoom = generateEmptyRoom(); + Room lastRoom = generateEmptyRoom(); // Randomly generate the in between rooms generateBetweenRooms(firstRoom, lastRoom); @@ -86,7 +86,6 @@ public void generateMap() { * @param map the map to reference. * @param target the point whose neighbours we're looking for. * @param filter a predicate saying which points should be excluded. - * * @return a list of all the neighbours satisfying the precondition. */ private @NotNull List getNeighbours(@NotNull Room[][] map, @@ -120,7 +119,6 @@ public void generateMap() { * @param map the map to draw adjacency from (basically the adjacency matrix). * @param start the starting point. * @param end the target. - * * @return the closet point to end that is graph-connected to start. */ private @NotNull Point getClosestPointTo(@NotNull Room[][] map, @NotNull Point start, @NotNull Point end) { @@ -163,7 +161,7 @@ public void generateMap() { */ private void generateBetweenRooms(@NotNull Room firstRoom, @NotNull Room lastRoom) { final int mapHeight = random.nextInt(MapConstants.MAPGEN_MIN_MAP_HEIGHT, MapConstants.MAPGEN_MAX_MAP_HEIGHT); - final int mapWidth = random.nextInt(MapConstants.MAPGEN_MIN_MAP_WIDTH, MapConstants.MAPGEN_MAX_MAP_WIDTH); + final int mapWidth = random.nextInt(MapConstants.MAPGEN_MIN_MAP_WIDTH, MapConstants.MAPGEN_MAX_MAP_WIDTH); Room[][] map = new Room[mapHeight][mapWidth]; // First fill in some random 'anchor' rooms @@ -176,11 +174,11 @@ private void generateBetweenRooms(@NotNull Room firstRoom, @NotNull Room lastRoo } // Next we manually place the first and last room - Point startPos = new Point(random.nextInt(mapWidth), mapHeight-1); - Point endPos = new Point(random.nextInt(mapWidth), 0); + Point startPos = new Point(random.nextInt(mapWidth), mapHeight - 1); + Point endPos = new Point(random.nextInt(mapWidth), 0); map[startPos.y][startPos.x] = firstRoom; - map[endPos.y][endPos.x] = lastRoom; + map[endPos.y][endPos.x] = lastRoom; // Next we connect the anchors together Point closest = getClosestPointTo(map, startPos, endPos); @@ -200,7 +198,7 @@ private void generateBetweenRooms(@NotNull Room firstRoom, @NotNull Room lastRoo List neighbours = getNeighbours(map, new Point(x, y), Objects::isNull); for (Point neighbour : neighbours) { Room neighbourRoom = map[neighbour.y][neighbour.x]; - int wallPosition = 3 + random.nextInt(MapConstants.ROOM_SIZE-6); + int wallPosition = 3 + random.nextInt(MapConstants.ROOM_SIZE - 6); Doorway doorway; if (neighbour.y < y) { @@ -208,13 +206,13 @@ private void generateBetweenRooms(@NotNull Room firstRoom, @NotNull Room lastRoo doorway = new Doorway(new Point(wallPosition, 0), neighbourRoom); } else if (neighbour.y > y) { // neighbourRoom is below the currentRoom - doorway = new Doorway(new Point(wallPosition, MapConstants.ROOM_SIZE-1), neighbourRoom); + doorway = new Doorway(new Point(wallPosition, MapConstants.ROOM_SIZE - 1), neighbourRoom); } else if (neighbour.x < x) { // neighbourRoom is to the left of the currentRoom doorway = new Doorway(new Point(0, wallPosition), neighbourRoom); } else { // neighbourRoom is to the right of the currentRoom\ - doorway = new Doorway(new Point(MapConstants.ROOM_SIZE-1, wallPosition), neighbourRoom); + doorway = new Doorway(new Point(MapConstants.ROOM_SIZE - 1, wallPosition), neighbourRoom); } currentRoom.getDoorways().add(doorway); } @@ -238,13 +236,13 @@ private void populateRoomWithChests(@NotNull Room room) { Point[] possibleLocations = { new Point( - MapConstants.ROOM_SIZE/2 - 1 + random.nextInt(2), - MapConstants.ROOM_SIZE/2 - 1 + random.nextInt(2) + MapConstants.ROOM_SIZE / 2 - 1 + random.nextInt(2), + MapConstants.ROOM_SIZE / 2 - 1 + random.nextInt(2) ), new Point(1, 1), - new Point(1, MapConstants.ROOM_SIZE-2), - new Point(MapConstants.ROOM_SIZE-2, 1), - new Point(MapConstants.ROOM_SIZE-2, MapConstants.ROOM_SIZE-2) + new Point(1, MapConstants.ROOM_SIZE - 2), + new Point(MapConstants.ROOM_SIZE - 2, 1), + new Point(MapConstants.ROOM_SIZE - 2, MapConstants.ROOM_SIZE - 2) }; for (Point chestLocation : possibleLocations) { @@ -299,7 +297,7 @@ private void populateRoomWithChests(@NotNull Room room) { Point battlePosition = new Point(door.getPosition()); if (battlePosition.x == 0) { battlePosition.x += 1; - } else if (battlePosition.x == MapConstants.ROOM_SIZE-1) { + } else if (battlePosition.x == MapConstants.ROOM_SIZE - 1) { battlePosition.x -= 1; } else if (battlePosition.y == 0) { battlePosition.y += 1; @@ -361,7 +359,7 @@ private void populateBetweenRooms(@NotNull Room firstRoom, @NotNull Room lastRoo while (!unpopulatedRooms.isEmpty()) { Room current = unpopulatedRooms.remove(); - for (Doorway door: current.getDoorways()) { + for (Doorway door : current.getDoorways()) { if (!visited.contains(door.getNextRoom())) { unpopulatedRooms.add(door.getNextRoom()); visited.add(door.getNextRoom()); diff --git a/src/main/java/com/mg105/use_cases/ReplayGenerator.java b/src/main/java/com/mg105/use_cases/map/ReplayGenerator.java similarity index 93% rename from src/main/java/com/mg105/use_cases/ReplayGenerator.java rename to src/main/java/com/mg105/use_cases/map/ReplayGenerator.java index c9a54ae6..a96c3598 100644 --- a/src/main/java/com/mg105/use_cases/ReplayGenerator.java +++ b/src/main/java/com/mg105/use_cases/map/ReplayGenerator.java @@ -1,7 +1,8 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import com.mg105.entities.BattleCharacter; import com.mg105.entities.GameState; +import com.mg105.use_cases.Resetable; import org.jetbrains.annotations.NotNull; @@ -16,7 +17,7 @@ public class ReplayGenerator { /** * Create a new replaygenerator * - * @param state the game state. + * @param state the game state. * @param resetables resetable things. */ public ReplayGenerator(@NotNull GameState state, @NotNull Resetable... resetables) { diff --git a/src/main/java/com/mg105/use_cases/RoomGetter.java b/src/main/java/com/mg105/use_cases/map/RoomGetter.java similarity index 96% rename from src/main/java/com/mg105/use_cases/RoomGetter.java rename to src/main/java/com/mg105/use_cases/map/RoomGetter.java index 38abd41f..db4675eb 100644 --- a/src/main/java/com/mg105/use_cases/RoomGetter.java +++ b/src/main/java/com/mg105/use_cases/map/RoomGetter.java @@ -1,4 +1,4 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import com.mg105.entities.Doorway; import com.mg105.entities.GameState; @@ -59,6 +59,7 @@ public RoomGetter(@NotNull GameState state) { /** * Retrieves the WalkingCharacter sprite name String, returns a file name/location corresponding to the name. + * * @return a String representing the file name/location for the selected character sprite. */ public String getWalkingSprite() { @@ -67,9 +68,10 @@ public String getWalkingSprite() { /** * Checks if the player is in the final room + * * @return whether the player is in the final room */ - public boolean isFinalRoom(){ + public boolean isFinalRoom() { return state.isCurrentRoomLastRoom(); } } diff --git a/src/main/java/com/mg105/use_cases/RoomUpdater.java b/src/main/java/com/mg105/use_cases/map/RoomUpdater.java similarity index 97% rename from src/main/java/com/mg105/use_cases/RoomUpdater.java rename to src/main/java/com/mg105/use_cases/map/RoomUpdater.java index 1133bfd3..f9a43834 100644 --- a/src/main/java/com/mg105/use_cases/RoomUpdater.java +++ b/src/main/java/com/mg105/use_cases/map/RoomUpdater.java @@ -1,4 +1,4 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/mg105/user_interface/MapDrawer.java b/src/main/java/com/mg105/user_interface/MapDrawer.java index 82fea5a5..0a4dcca1 100644 --- a/src/main/java/com/mg105/user_interface/MapDrawer.java +++ b/src/main/java/com/mg105/user_interface/MapDrawer.java @@ -1,6 +1,6 @@ package com.mg105.user_interface; -import com.mg105.interface_adapters.RoomInterpreter; +import com.mg105.interface_adapters.map.RoomInterpreter; import com.mg105.interface_adapters.TileType; import com.mg105.utils.MapConstants; import javafx.scene.Group; diff --git a/src/main/java/com/mg105/user_interface/MapGeneratorButton.java b/src/main/java/com/mg105/user_interface/MapGeneratorButton.java index 444de45d..7f099187 100644 --- a/src/main/java/com/mg105/user_interface/MapGeneratorButton.java +++ b/src/main/java/com/mg105/user_interface/MapGeneratorButton.java @@ -1,6 +1,6 @@ package com.mg105.user_interface; -import com.mg105.interface_adapters.MapGeneratorInterpreter; +import com.mg105.interface_adapters.map.MapGeneratorInterpreter; import com.mg105.interface_adapters.Toggler; import javafx.event.ActionEvent; import javafx.event.EventHandler; diff --git a/src/main/java/com/mg105/user_interface/MinimapDrawer.java b/src/main/java/com/mg105/user_interface/MinimapDrawer.java index 00cc4140..419516c8 100644 --- a/src/main/java/com/mg105/user_interface/MinimapDrawer.java +++ b/src/main/java/com/mg105/user_interface/MinimapDrawer.java @@ -1,6 +1,6 @@ package com.mg105.user_interface; -import com.mg105.interface_adapters.MinimapInterpreter; +import com.mg105.interface_adapters.map.MinimapInterpreter; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Line; diff --git a/src/test/java/com/mg105/entities/ChestTest.java b/src/test/java/com/mg105/entities/ChestTest.java index 4d527e5f..b0d20bc9 100644 --- a/src/test/java/com/mg105/entities/ChestTest.java +++ b/src/test/java/com/mg105/entities/ChestTest.java @@ -1,7 +1,7 @@ package com.mg105.entities; import com.mg105.entities.items.HealthPotion; import com.mg105.entities.items.MegaPotion; -import com.mg105.use_cases.RoomUpdater; +import com.mg105.use_cases.map.RoomUpdater; import com.mg105.use_cases.outputds.ItemDetails; import com.mg105.use_cases.ChestInteractor; import com.mg105.use_cases.inventory.InventoryInteractor; diff --git a/src/test/java/com/mg105/use_cases/CharacterMoverTest.java b/src/test/java/com/mg105/use_cases/CharacterMoverTest.java index 134eede2..33414c83 100644 --- a/src/test/java/com/mg105/use_cases/CharacterMoverTest.java +++ b/src/test/java/com/mg105/use_cases/CharacterMoverTest.java @@ -2,6 +2,8 @@ import com.mg105.entities.*; import com.mg105.entities.items.UpgradeToken; +import com.mg105.use_cases.map.CharacterMover; +import com.mg105.use_cases.map.RoomUpdater; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java b/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java index b95216d5..e0d4adf2 100644 --- a/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java +++ b/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java @@ -1,5 +1,6 @@ package com.mg105.use_cases; +import com.mg105.use_cases.map.ReplayGenerator; import org.junit.jupiter.api.Test; import com.mg105.entities.*; import com.mg105.entities.items.UpgradeToken; diff --git a/src/test/java/com/mg105/use_cases/MapGeneratorTest.java b/src/test/java/com/mg105/use_cases/map/MapGeneratorTest.java similarity index 90% rename from src/test/java/com/mg105/use_cases/MapGeneratorTest.java rename to src/test/java/com/mg105/use_cases/map/MapGeneratorTest.java index 7bf8175f..81753d0a 100644 --- a/src/test/java/com/mg105/use_cases/MapGeneratorTest.java +++ b/src/test/java/com/mg105/use_cases/map/MapGeneratorTest.java @@ -1,4 +1,4 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import com.mg105.entities.*; import org.junit.jupiter.api.BeforeEach; @@ -10,7 +10,8 @@ import java.util.Queue; import java.util.Set; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; class MapGeneratorTest { private GameState state; diff --git a/src/test/java/com/mg105/use_cases/RoomGetterTest.java b/src/test/java/com/mg105/use_cases/map/RoomGetterTest.java similarity index 98% rename from src/test/java/com/mg105/use_cases/RoomGetterTest.java rename to src/test/java/com/mg105/use_cases/map/RoomGetterTest.java index 948fac1d..0029fbae 100644 --- a/src/test/java/com/mg105/use_cases/RoomGetterTest.java +++ b/src/test/java/com/mg105/use_cases/map/RoomGetterTest.java @@ -1,4 +1,4 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import com.mg105.entities.*; import com.mg105.entities.items.UpgradeToken; @@ -7,8 +7,8 @@ import org.junit.jupiter.api.Test; import java.awt.*; -import java.util.List; import java.util.ArrayList; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/com/mg105/use_cases/RoomLayoutTest.java b/src/test/java/com/mg105/use_cases/map/RoomLayoutTest.java similarity index 94% rename from src/test/java/com/mg105/use_cases/RoomLayoutTest.java rename to src/test/java/com/mg105/use_cases/map/RoomLayoutTest.java index f2b4d7f0..4f717d79 100644 --- a/src/test/java/com/mg105/use_cases/RoomLayoutTest.java +++ b/src/test/java/com/mg105/use_cases/map/RoomLayoutTest.java @@ -1,13 +1,13 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import com.mg105.use_cases.outputds.RoomLayout; import org.junit.jupiter.api.Test; -import java.util.List; import java.awt.*; import java.util.ArrayList; +import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RoomLayoutTest { @Test diff --git a/src/test/java/com/mg105/use_cases/RoomUpdaterTest.java b/src/test/java/com/mg105/use_cases/map/RoomUpdaterTest.java similarity index 95% rename from src/test/java/com/mg105/use_cases/RoomUpdaterTest.java rename to src/test/java/com/mg105/use_cases/map/RoomUpdaterTest.java index d88ee491..66aa4643 100644 --- a/src/test/java/com/mg105/use_cases/RoomUpdaterTest.java +++ b/src/test/java/com/mg105/use_cases/map/RoomUpdaterTest.java @@ -1,11 +1,11 @@ -package com.mg105.use_cases; +package com.mg105.use_cases.map; import org.junit.jupiter.api.Test; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RoomUpdaterTest { @Test From 915b303c3546546b8722ebaa4850221aa4551d80 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 12:27:58 -0500 Subject: [PATCH 02/11] Extract map interface adapters to follow the I SOLID principle --- src/main/java/com/mg105/Application.java | 3 +- .../map/MapGeneratorInterpreter.java | 3 +- .../map/MapGeneratorInterpreterInterface.java | 11 +++++++ .../map/MinimapInterpreter.java | 16 ++-------- .../map/MinimapInterpreterInterface.java | 28 +++++++++++++++++ .../map/RoomInterpreter.java | 8 +++-- .../map/RoomInterpreterInterface.java | 31 +++++++++++++++++++ .../interface_adapters/map/RoomState.java | 13 ++++++++ .../{ => map}/TileType.java | 2 +- .../com/mg105/user_interface/MapDrawer.java | 10 +++--- .../user_interface/MapGeneratorButton.java | 6 ++-- .../mg105/user_interface/MinimapDrawer.java | 11 ++++--- 12 files changed, 110 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterInterface.java create mode 100644 src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java create mode 100644 src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java create mode 100644 src/main/java/com/mg105/interface_adapters/map/RoomState.java rename src/main/java/com/mg105/interface_adapters/{ => map}/TileType.java (91%) diff --git a/src/main/java/com/mg105/Application.java b/src/main/java/com/mg105/Application.java index 80189ecc..4c582704 100644 --- a/src/main/java/com/mg105/Application.java +++ b/src/main/java/com/mg105/Application.java @@ -4,6 +4,7 @@ import com.mg105.interface_adapters.map.MapGeneratorInterpreter; import com.mg105.interface_adapters.map.MinimapInterpreter; import com.mg105.interface_adapters.map.RoomInterpreter; +import com.mg105.interface_adapters.map.RoomInterpreterInterface; import com.mg105.interface_adapters.tutorial.TutorialTextController; import com.mg105.data_control.access.MoveDataAccess; import com.mg105.data_control.access.PartyDataAccess; @@ -73,7 +74,7 @@ public void start(Stage primaryStage) { MainMenu mainMenu = new MainMenu(generateMapButton); RoomGetter roomGetter = new RoomGetter(state); - RoomInterpreter roomInterpreter = new RoomInterpreter(roomGetter); + RoomInterpreterInterface roomInterpreter = new RoomInterpreter(roomGetter); MapDrawer mapDrawer = new MapDrawer(roomInterpreter); drawableComponents.put(Toggler.ToggleableComponent.MAIN_MENU, mainMenu); drawableComponents.put(Toggler.ToggleableComponent.MAP, mapDrawer); diff --git a/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java index 1524a164..8fb2db3c 100644 --- a/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java @@ -7,7 +7,7 @@ * MapGeneratorInterpreter asks as a thin interface adapter whose sole purpose is to maintain clean architecture. * All it does is pass control on to the use case component of map generation. */ -public class MapGeneratorInterpreter { +public class MapGeneratorInterpreter implements MapGeneratorInterpreterInterface { private final @NotNull MapGenerator generator; /** @@ -22,6 +22,7 @@ public MapGeneratorInterpreter(@NotNull MapGenerator generator) { /** * Generate (or re-generate) the map. */ + @Override public void generateMap() { generator.generateMap(); } diff --git a/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterInterface.java b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterInterface.java new file mode 100644 index 00000000..bd98ef62 --- /dev/null +++ b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterInterface.java @@ -0,0 +1,11 @@ +package com.mg105.interface_adapters.map; + +/** + * An interface for map generation. + */ +public interface MapGeneratorInterpreterInterface { + /** + * Generate the map. + */ + void generateMap(); +} diff --git a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java index acb2b614..2fd8e920 100644 --- a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java @@ -15,7 +15,7 @@ /** * The MinimapInterpreter processes room change data an interprets its implicit position. */ -public class MinimapInterpreter implements PropertyChangeListener, Resetable { +public class MinimapInterpreter implements PropertyChangeListener, Resetable, MinimapInterpreterInterface { private final @NotNull RoomGetter getter; private @Nullable Point lastPosition; @@ -103,6 +103,7 @@ public void propertyChange(PropertyChangeEvent evt) { * * @return the currently explored map. */ + @Override public @NotNull RoomState[][] getMapSoFar() { return mapSoFar; } @@ -112,6 +113,7 @@ public void propertyChange(PropertyChangeEvent evt) { * * @return the current room you are in. */ + @Override public @NotNull Point getCurrentPosition() { return new Point(currentRoom); } @@ -162,16 +164,4 @@ private void autoBumpMapSoFarBecauseOf(@NotNull Point next, @NotNull Point... to mapSoFar = nextMap; } } - - /** - * Possible knowledge states of a room. - *

- * Note that we treat 'null' as a roomm state being unknown. - */ - public enum RoomState { - /** The room is implied to exist but is unexplored. */ - UNEXPLORED, - /** The room has been visited at least once */ - EXPLORED - } } diff --git a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java new file mode 100644 index 00000000..d1c376a3 --- /dev/null +++ b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java @@ -0,0 +1,28 @@ +package com.mg105.interface_adapters.map; + +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** + * A class that handles the interpretation of the minimaps internal state. + */ +public interface MinimapInterpreterInterface { + /** + * Get the current state of the minimap. + * + * @return the current state of the minimap. + * + * @see MinimapInterpreterInterface#getCurrentPosition() + */ + @NotNull RoomState[][] getMapSoFar(); + + /** + * Get the current room position + * + * @return the current room indexes in the result of getMapSoFar(). + * + * @see MinimapInterpreterInterface#getMapSoFar() + */ + @NotNull Point getCurrentPosition(); +} diff --git a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java index 9d2c91a4..cf3d27e0 100644 --- a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java @@ -1,6 +1,5 @@ package com.mg105.interface_adapters.map; -import com.mg105.interface_adapters.TileType; import com.mg105.use_cases.map.RoomGetter; import com.mg105.use_cases.outputds.RoomLayout; import com.mg105.utils.MapConstants; @@ -11,7 +10,7 @@ /** * RoomInterpreter interprets the current room in a format that is easier to draw from. */ -public class RoomInterpreter { +public class RoomInterpreter implements RoomInterpreterInterface { private final @NotNull RoomGetter getter; /** @@ -30,6 +29,7 @@ public RoomInterpreter(@NotNull RoomGetter getter) { * represents the top-left corner and (MapConstants.ROOM_SIZE, MapConstants.ROOM_SIZE) represents the bottom * right corner. */ + @Override public TileType[][] getCurrentRoom() { TileType[][] canvas = new TileType[MapConstants.ROOM_SIZE][MapConstants.ROOM_SIZE]; @@ -79,6 +79,7 @@ public TileType[][] getCurrentRoom() { * * @return the current player position in the room. */ + @Override public @NotNull Point getPlayer() { return getter.getCurrentRoomLayout().getPlayer(); } @@ -87,7 +88,8 @@ public TileType[][] getCurrentRoom() { * Retrieves the sprite String currently associated with the WalkingCharacter. * @return a file name/location as a String for the desired character sprite. */ - public String updateCharacterSprite() { + @Override + public @NotNull String getCharacterSprite() { return this.getter.getWalkingSprite(); } } diff --git a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java new file mode 100644 index 00000000..28c47303 --- /dev/null +++ b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java @@ -0,0 +1,31 @@ +package com.mg105.interface_adapters.map; + +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** + * Layout the current room. + */ +public interface RoomInterpreterInterface { + /** + * Lay out the current room as a square of tiles to be displayed. + * + * @return the state of the current room. + */ + TileType[][] getCurrentRoom(); + + /** + * Get the position of the player within the room. + * + * @return the position of the player within the room. + */ + @NotNull Point getPlayer(); + + /** + * Get the path of the current character sprite. + * + * @return the path of the current character sprite + */ + @NotNull String getCharacterSprite(); +} diff --git a/src/main/java/com/mg105/interface_adapters/map/RoomState.java b/src/main/java/com/mg105/interface_adapters/map/RoomState.java new file mode 100644 index 00000000..e67a69ac --- /dev/null +++ b/src/main/java/com/mg105/interface_adapters/map/RoomState.java @@ -0,0 +1,13 @@ +package com.mg105.interface_adapters.map; + +/** + * Possible knowledge states of a room. + *

+ * Note that we treat 'null' as a roomm state being unknown. + */ +public enum RoomState { + /** The room is implied to exist but is unexplored. */ + UNEXPLORED, + /** The room has been visited at least once */ + EXPLORED +} diff --git a/src/main/java/com/mg105/interface_adapters/TileType.java b/src/main/java/com/mg105/interface_adapters/map/TileType.java similarity index 91% rename from src/main/java/com/mg105/interface_adapters/TileType.java rename to src/main/java/com/mg105/interface_adapters/map/TileType.java index 1cb79338..4f0765b1 100644 --- a/src/main/java/com/mg105/interface_adapters/TileType.java +++ b/src/main/java/com/mg105/interface_adapters/map/TileType.java @@ -1,4 +1,4 @@ -package com.mg105.interface_adapters; +package com.mg105.interface_adapters.map; /** * Types of tiles that can appear within a room. diff --git a/src/main/java/com/mg105/user_interface/MapDrawer.java b/src/main/java/com/mg105/user_interface/MapDrawer.java index 0a4dcca1..e492b063 100644 --- a/src/main/java/com/mg105/user_interface/MapDrawer.java +++ b/src/main/java/com/mg105/user_interface/MapDrawer.java @@ -1,7 +1,7 @@ package com.mg105.user_interface; -import com.mg105.interface_adapters.map.RoomInterpreter; -import com.mg105.interface_adapters.TileType; +import com.mg105.interface_adapters.map.RoomInterpreterInterface; +import com.mg105.interface_adapters.map.TileType; import com.mg105.utils.MapConstants; import javafx.scene.Group; import javafx.scene.Scene; @@ -20,7 +20,7 @@ * MapDrawer draws the map as a grid of tiles. */ public class MapDrawer implements PropertyChangeListener, Toggleable { - private final @NotNull RoomInterpreter interpreter; + private final @NotNull RoomInterpreterInterface interpreter; private final @NotNull Scene scene; private final @NotNull Group group; @@ -34,7 +34,7 @@ public class MapDrawer implements PropertyChangeListener, Toggleable { * * @param interpreter the room interpreter used to format the data in an acceptable way for this class. */ - public MapDrawer(@NotNull RoomInterpreter interpreter) { + public MapDrawer(@NotNull RoomInterpreterInterface interpreter) { this.interpreter = interpreter; group = new Group(); @@ -113,7 +113,7 @@ public void updateRoom() { } Point player = interpreter.getPlayer(); - ImageView playerTile = new ImageView(playerSprites.getOrDefault(interpreter.updateCharacterSprite(), missingTile)); + ImageView playerTile = new ImageView(playerSprites.getOrDefault(interpreter.getCharacterSprite(), missingTile)); playerTile.setPreserveRatio(true); playerTile.setX(player.x * MapConstants.TILE_SIZE); playerTile.setY(player.y * MapConstants.TILE_SIZE); diff --git a/src/main/java/com/mg105/user_interface/MapGeneratorButton.java b/src/main/java/com/mg105/user_interface/MapGeneratorButton.java index 7f099187..8340b881 100644 --- a/src/main/java/com/mg105/user_interface/MapGeneratorButton.java +++ b/src/main/java/com/mg105/user_interface/MapGeneratorButton.java @@ -1,7 +1,7 @@ package com.mg105.user_interface; -import com.mg105.interface_adapters.map.MapGeneratorInterpreter; import com.mg105.interface_adapters.Toggler; +import com.mg105.interface_adapters.map.MapGeneratorInterpreterInterface; import javafx.event.ActionEvent; import javafx.event.EventHandler; import org.jetbrains.annotations.NotNull; @@ -10,7 +10,7 @@ * MapGeneratorButton acts as the event handler for the actual JavaFX button that will generate a map. */ public class MapGeneratorButton implements EventHandler { - private final @NotNull MapGeneratorInterpreter interpreter; + private final @NotNull MapGeneratorInterpreterInterface interpreter; private final @NotNull Toggler toggler; @@ -20,7 +20,7 @@ public class MapGeneratorButton implements EventHandler { * @param interpreter the interpreter for the map generator button * @param toggler the toggler used to close the user interface once pressed. */ - public MapGeneratorButton(@NotNull MapGeneratorInterpreter interpreter, @NotNull Toggler toggler) { + public MapGeneratorButton(@NotNull MapGeneratorInterpreterInterface interpreter, @NotNull Toggler toggler) { this.interpreter = interpreter; this.toggler = toggler; } diff --git a/src/main/java/com/mg105/user_interface/MinimapDrawer.java b/src/main/java/com/mg105/user_interface/MinimapDrawer.java index 419516c8..c6d70962 100644 --- a/src/main/java/com/mg105/user_interface/MinimapDrawer.java +++ b/src/main/java/com/mg105/user_interface/MinimapDrawer.java @@ -1,6 +1,7 @@ package com.mg105.user_interface; -import com.mg105.interface_adapters.map.MinimapInterpreter; +import com.mg105.interface_adapters.map.MinimapInterpreterInterface; +import com.mg105.interface_adapters.map.RoomState; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Line; @@ -16,7 +17,7 @@ public class MinimapDrawer implements Toggleable { private static final int CANVAS_SIZE = 400; - private final @NotNull MinimapInterpreter interpreter; + private final @NotNull MinimapInterpreterInterface interpreter; private final @NotNull Scene scene; private final @NotNull Group group; @@ -31,7 +32,7 @@ public class MinimapDrawer implements Toggleable { * * @param interpreter the MinimapInterpreter that will process room change data. */ - public MinimapDrawer(@NotNull MinimapInterpreter interpreter) { + public MinimapDrawer(@NotNull MinimapInterpreterInterface interpreter) { this.interpreter = interpreter; group = new Group(); @@ -58,7 +59,7 @@ public MinimapDrawer(@NotNull MinimapInterpreter interpreter) { @Override public void toggle(boolean isVisible) { if (isVisible) { - MinimapInterpreter.RoomState[][] map = interpreter.getMapSoFar(); + RoomState[][] map = interpreter.getMapSoFar(); Point currentPosition = interpreter.getCurrentPosition(); final int cellDimension = CANVAS_SIZE / Math.max(map.length, map[0].length); @@ -82,7 +83,7 @@ public void toggle(boolean isVisible) { } // Rectangle for each room - if (map[y][x] == MinimapInterpreter.RoomState.EXPLORED) { + if (map[y][x] == RoomState.EXPLORED) { // First we draw the middle square Rectangle r = new Rectangle(); r.setX(leftPadding + innerCellPadding + x * cellDimension); From c0afa3996c245af65458f77f32518a9f3f7b2099 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 12:48:29 -0500 Subject: [PATCH 03/11] Extract map use cases to follow the I SOLID principle --- src/main/java/com/mg105/Application.java | 4 +-- .../interface_adapters/InputInterpreter.java | 15 +++++----- .../ReplayGeneratorInterpreter.java | 2 +- .../mg105/interface_adapters/WinDisplay.java | 6 ++-- .../map/MapGeneratorInterpreter.java | 6 ++-- .../map/MinimapInterpreter.java | 6 ++-- .../map/RoomInterpreter.java | 6 ++-- .../com/mg105/use_cases/ChestInteractor.java | 6 ++-- .../use_cases/{map => }/ReplayGenerator.java | 4 +-- .../mg105/use_cases/map/CharacterMover.java | 7 +++-- .../map/CharacterMoverInterface.java | 16 ++++++++++ .../com/mg105/use_cases/map/MapGenerator.java | 3 +- .../use_cases/map/MapGeneratorInterface.java | 11 +++++++ .../com/mg105/use_cases/map/RoomGetter.java | 7 +++-- .../use_cases/map/RoomGetterInterface.java | 30 +++++++++++++++++++ .../com/mg105/use_cases/map/RoomUpdater.java | 3 +- .../use_cases/map/RoomUpdaterInterface.java | 14 +++++++++ .../mg105/use_cases/CharacterMoverTest.java | 3 +- .../mg105/use_cases/ReplayGeneratorTest.java | 1 - .../mg105/use_cases/map/RoomGetterTest.java | 2 +- 20 files changed, 115 insertions(+), 37 deletions(-) rename src/main/java/com/mg105/use_cases/{map => }/ReplayGenerator.java (95%) create mode 100644 src/main/java/com/mg105/use_cases/map/CharacterMoverInterface.java create mode 100644 src/main/java/com/mg105/use_cases/map/MapGeneratorInterface.java create mode 100644 src/main/java/com/mg105/use_cases/map/RoomGetterInterface.java create mode 100644 src/main/java/com/mg105/use_cases/map/RoomUpdaterInterface.java diff --git a/src/main/java/com/mg105/Application.java b/src/main/java/com/mg105/Application.java index 4c582704..93457034 100644 --- a/src/main/java/com/mg105/Application.java +++ b/src/main/java/com/mg105/Application.java @@ -73,7 +73,7 @@ public void start(Stage primaryStage) { MapGeneratorButton generateMapButton = new MapGeneratorButton(mapGeneratorInterpreter, sceneController); MainMenu mainMenu = new MainMenu(generateMapButton); - RoomGetter roomGetter = new RoomGetter(state); + RoomGetterInterface roomGetter = new RoomGetter(state); RoomInterpreterInterface roomInterpreter = new RoomInterpreter(roomGetter); MapDrawer mapDrawer = new MapDrawer(roomInterpreter); drawableComponents.put(Toggler.ToggleableComponent.MAIN_MENU, mainMenu); @@ -134,7 +134,7 @@ public void start(Stage primaryStage) { RoomUpdater roomUpdater = new RoomUpdater(); roomUpdater.addObserver(mapDrawer); roomUpdater.addObserver(minimapInterpreter); - CharacterMover characterMover = new CharacterMover(state, roomUpdater); + CharacterMoverInterface characterMover = new CharacterMover(state, roomUpdater); /////WinGame Scene///// ReplayGeneratorButton winButton = new ReplayGeneratorButton(replayGeneratorInterpreter, sceneController, Toggler.ToggleableComponent.WIN_MENU); diff --git a/src/main/java/com/mg105/interface_adapters/InputInterpreter.java b/src/main/java/com/mg105/interface_adapters/InputInterpreter.java index 4d02a94c..825c4e17 100644 --- a/src/main/java/com/mg105/interface_adapters/InputInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/InputInterpreter.java @@ -2,8 +2,8 @@ import com.mg105.use_cases.ChestInteractor; import com.mg105.interface_adapters.tutorial.TutorialTextController; -import com.mg105.use_cases.map.CharacterMover; import com.mg105.use_cases.OpponentSetInteractor; +import com.mg105.use_cases.map.CharacterMoverInterface; import com.mg105.utils.TutorialTexts; import org.jetbrains.annotations.NotNull; @@ -13,7 +13,7 @@ * InputInterpreter takes in keyboard inputs and distributes them to their appropriate use cases. */ public class InputInterpreter { - private final @NotNull CharacterMover mover; + private final @NotNull CharacterMoverInterface mover; private final @NotNull Toggler toggler; private final @NotNull ChestInteractor chestInteractor; private final @NotNull TutorialTextController textChanger; @@ -23,12 +23,13 @@ public class InputInterpreter { /** * Create a new InputInterpreter that translates keyboard inputs to appropriate function invocations. * - * @param mover the character mover. - * @param toggler the toggler used to change the displayed interface. - * @param textChanger the text controller for tutorial - * @param chestInteractor the ChestInteractor used to interact with chests. + * @param mover the character mover. + * @param toggler the toggler used to change the displayed interface. + * @param textChanger the text controller for tutorial + * @param chestInteractor the ChestInteractor used to interact with chests. + * @param opponentInteractor the opponentInteractor used to ineract with opponents. */ - public InputInterpreter(@NotNull CharacterMover mover, @NotNull Toggler toggler, + public InputInterpreter(@NotNull CharacterMoverInterface mover, @NotNull Toggler toggler, @NotNull TutorialTextController textChanger, @NotNull ChestInteractor chestInteractor, @NotNull OpponentSetInteractor opponentInteractor) { this.mover = mover; diff --git a/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java b/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java index 79d14cc8..4f708934 100644 --- a/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/ReplayGeneratorInterpreter.java @@ -1,6 +1,6 @@ package com.mg105.interface_adapters; -import com.mg105.use_cases.map.ReplayGenerator; +import com.mg105.use_cases.ReplayGenerator; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/com/mg105/interface_adapters/WinDisplay.java b/src/main/java/com/mg105/interface_adapters/WinDisplay.java index 95a08401..ea0e5937 100644 --- a/src/main/java/com/mg105/interface_adapters/WinDisplay.java +++ b/src/main/java/com/mg105/interface_adapters/WinDisplay.java @@ -1,6 +1,6 @@ package com.mg105.interface_adapters; -import com.mg105.use_cases.map.RoomGetter; +import com.mg105.use_cases.map.RoomGetterInterface; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -10,14 +10,14 @@ */ public class WinDisplay implements PropertyChangeListener { private final Toggler toggler; - private final RoomGetter roomGetter; + private final RoomGetterInterface roomGetter; /** * Construction for the WinDisplay interface adapter * @param toggler toggles the win screen * @param roomGetter gets the current room of the player */ - public WinDisplay(Toggler toggler, RoomGetter roomGetter){ + public WinDisplay(Toggler toggler, RoomGetterInterface roomGetter){ this.toggler = toggler; this.roomGetter = roomGetter; } diff --git a/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java index 8fb2db3c..9ba29e6d 100644 --- a/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/MapGeneratorInterpreter.java @@ -1,6 +1,6 @@ package com.mg105.interface_adapters.map; -import com.mg105.use_cases.map.MapGenerator; +import com.mg105.use_cases.map.MapGeneratorInterface; import org.jetbrains.annotations.NotNull; /** @@ -8,14 +8,14 @@ * All it does is pass control on to the use case component of map generation. */ public class MapGeneratorInterpreter implements MapGeneratorInterpreterInterface { - private final @NotNull MapGenerator generator; + private final @NotNull MapGeneratorInterface generator; /** * Create a new MapGeneratorInterpreter. * * @param generator the generator that will be used to generate a new map. */ - public MapGeneratorInterpreter(@NotNull MapGenerator generator) { + public MapGeneratorInterpreter(@NotNull MapGeneratorInterface generator) { this.generator = generator; } diff --git a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java index 2fd8e920..19419a14 100644 --- a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java @@ -1,7 +1,7 @@ package com.mg105.interface_adapters.map; import com.mg105.use_cases.Resetable; -import com.mg105.use_cases.map.RoomGetter; +import com.mg105.use_cases.map.RoomGetterInterface; import com.mg105.use_cases.outputds.RoomLayout; import com.mg105.utils.MapConstants; import com.mg105.utils.PointComparator; @@ -16,7 +16,7 @@ * The MinimapInterpreter processes room change data an interprets its implicit position. */ public class MinimapInterpreter implements PropertyChangeListener, Resetable, MinimapInterpreterInterface { - private final @NotNull RoomGetter getter; + private final @NotNull RoomGetterInterface getter; private @Nullable Point lastPosition; private @NotNull RoomState[][] mapSoFar; @@ -27,7 +27,7 @@ public class MinimapInterpreter implements PropertyChangeListener, Resetable, Mi * * @param getter the RoomGetter that will get room information. */ - public MinimapInterpreter(@NotNull RoomGetter getter) { + public MinimapInterpreter(@NotNull RoomGetterInterface getter) { this.getter = getter; currentRoom = new Point(); diff --git a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java index cf3d27e0..094f5359 100644 --- a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java @@ -1,6 +1,6 @@ package com.mg105.interface_adapters.map; -import com.mg105.use_cases.map.RoomGetter; +import com.mg105.use_cases.map.RoomGetterInterface; import com.mg105.use_cases.outputds.RoomLayout; import com.mg105.utils.MapConstants; import org.jetbrains.annotations.NotNull; @@ -11,14 +11,14 @@ * RoomInterpreter interprets the current room in a format that is easier to draw from. */ public class RoomInterpreter implements RoomInterpreterInterface { - private final @NotNull RoomGetter getter; + private final @NotNull RoomGetterInterface getter; /** * Create a new RoomInterpreter that will get its information from getter. * * @param getter the information source for the RoomInterpreter. */ - public RoomInterpreter(@NotNull RoomGetter getter) { + public RoomInterpreter(@NotNull RoomGetterInterface getter) { this.getter = getter; } diff --git a/src/main/java/com/mg105/use_cases/ChestInteractor.java b/src/main/java/com/mg105/use_cases/ChestInteractor.java index 801fc184..8a163be8 100644 --- a/src/main/java/com/mg105/use_cases/ChestInteractor.java +++ b/src/main/java/com/mg105/use_cases/ChestInteractor.java @@ -8,14 +8,14 @@ import com.mg105.entities.Room; import com.mg105.entities.TreasureChest; import com.mg105.use_cases.inventory.InventoryInteractor; -import com.mg105.use_cases.map.RoomUpdater; +import com.mg105.use_cases.map.RoomUpdaterInterface; import org.jetbrains.annotations.NotNull; public class ChestInteractor { private final @NotNull GameState gameState; private final @NotNull InventoryInteractor interactor; - private final @NotNull RoomUpdater updater; + private final @NotNull RoomUpdaterInterface updater; /** * Creates a ChestInteractor to interact with chests in a GameState. @@ -26,7 +26,7 @@ public class ChestInteractor { */ public ChestInteractor(@NotNull GameState gameState, @NotNull InventoryInteractor interactor, - @NotNull RoomUpdater updater) { + @NotNull RoomUpdaterInterface updater) { this.gameState = gameState; this.interactor = interactor; this.updater = updater; diff --git a/src/main/java/com/mg105/use_cases/map/ReplayGenerator.java b/src/main/java/com/mg105/use_cases/ReplayGenerator.java similarity index 95% rename from src/main/java/com/mg105/use_cases/map/ReplayGenerator.java rename to src/main/java/com/mg105/use_cases/ReplayGenerator.java index a96c3598..c2532e9b 100644 --- a/src/main/java/com/mg105/use_cases/map/ReplayGenerator.java +++ b/src/main/java/com/mg105/use_cases/ReplayGenerator.java @@ -1,8 +1,8 @@ -package com.mg105.use_cases.map; +package com.mg105.use_cases; import com.mg105.entities.BattleCharacter; import com.mg105.entities.GameState; -import com.mg105.use_cases.Resetable; +import com.mg105.use_cases.map.MapGenerator; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/mg105/use_cases/map/CharacterMover.java b/src/main/java/com/mg105/use_cases/map/CharacterMover.java index 3ae7320b..f460270f 100644 --- a/src/main/java/com/mg105/use_cases/map/CharacterMover.java +++ b/src/main/java/com/mg105/use_cases/map/CharacterMover.java @@ -9,9 +9,9 @@ /** * Move the player within a room. */ -public class CharacterMover { +public class CharacterMover implements CharacterMoverInterface { private final @NotNull GameState state; - private final @NotNull RoomUpdater updater; + private final @NotNull RoomUpdaterInterface updater; /** * Create a CharacterMover to operate on state and to update the room visuals via the updater @@ -19,7 +19,7 @@ public class CharacterMover { * @param state the current game state. * @param updater something that will update the visual representation of the room on change. */ - public CharacterMover(@NotNull GameState state, @NotNull RoomUpdater updater) { + public CharacterMover(@NotNull GameState state, @NotNull RoomUpdaterInterface updater) { this.state = state; this.updater = updater; } @@ -30,6 +30,7 @@ public CharacterMover(@NotNull GameState state, @NotNull RoomUpdater updater) { * @param direction the direction to move. The direction must have a magnitude of 1 and be in exactly one * cardinal direction. */ + @Override public void generateMapMoveBy(Point direction) { // Because direction.x and direction.y are integers, the precondition for direction is satisfied iff the // magnitude of the vector is 1 which is true iff the sum of the absolute value of the components is 1. diff --git a/src/main/java/com/mg105/use_cases/map/CharacterMoverInterface.java b/src/main/java/com/mg105/use_cases/map/CharacterMoverInterface.java new file mode 100644 index 00000000..3078eaf5 --- /dev/null +++ b/src/main/java/com/mg105/use_cases/map/CharacterMoverInterface.java @@ -0,0 +1,16 @@ +package com.mg105.use_cases.map; + +import java.awt.*; + +/** + * A interface that represents a class that moves a character. + */ +public interface CharacterMoverInterface { + /** + * Move the character by direction. + * + * @param direction the direction to move in. The magnitude of direction must be 1 and must be in exactly one + * direction. + */ + void generateMapMoveBy(Point direction); +} diff --git a/src/main/java/com/mg105/use_cases/map/MapGenerator.java b/src/main/java/com/mg105/use_cases/map/MapGenerator.java index 46c68fc8..88b1c50f 100644 --- a/src/main/java/com/mg105/use_cases/map/MapGenerator.java +++ b/src/main/java/com/mg105/use_cases/map/MapGenerator.java @@ -24,7 +24,7 @@ *

* Alas, this is just a complex algorithm and must necessarily be somewhat long. */ -public class MapGenerator { +public class MapGenerator implements MapGeneratorInterface { private final @NotNull GameState state; private final @NotNull Random random; @@ -51,6 +51,7 @@ public MapGenerator(@NotNull GameState state, @NotNull Random random) { /** * Generates a map. */ + @Override public void generateMap() { Room firstRoom = generateEmptyRoom(); Room lastRoom = generateEmptyRoom(); diff --git a/src/main/java/com/mg105/use_cases/map/MapGeneratorInterface.java b/src/main/java/com/mg105/use_cases/map/MapGeneratorInterface.java new file mode 100644 index 00000000..77904a25 --- /dev/null +++ b/src/main/java/com/mg105/use_cases/map/MapGeneratorInterface.java @@ -0,0 +1,11 @@ +package com.mg105.use_cases.map; + +/** + * Something that generates the map. + */ +public interface MapGeneratorInterface { + /** + * Generate the map. + */ + void generateMap(); +} diff --git a/src/main/java/com/mg105/use_cases/map/RoomGetter.java b/src/main/java/com/mg105/use_cases/map/RoomGetter.java index db4675eb..7f31ad73 100644 --- a/src/main/java/com/mg105/use_cases/map/RoomGetter.java +++ b/src/main/java/com/mg105/use_cases/map/RoomGetter.java @@ -14,7 +14,7 @@ /** * RoomGetter is responsible for getting the state current room. */ -public class RoomGetter { +public class RoomGetter implements RoomGetterInterface { private final @NotNull GameState state; /** @@ -33,6 +33,7 @@ public RoomGetter(@NotNull GameState state) { * * @return the current room. */ + @Override public @NotNull RoomLayout getCurrentRoomLayout() { List closedChests = new ArrayList<>(); List openChests = new ArrayList<>(); @@ -62,7 +63,8 @@ public RoomGetter(@NotNull GameState state) { * * @return a String representing the file name/location for the selected character sprite. */ - public String getWalkingSprite() { + @Override + public @NotNull String getWalkingSprite() { return "/sprites/" + state.getWalkingCharacter().getSpriteName() + ".png"; } @@ -71,6 +73,7 @@ public String getWalkingSprite() { * * @return whether the player is in the final room */ + @Override public boolean isFinalRoom() { return state.isCurrentRoomLastRoom(); } diff --git a/src/main/java/com/mg105/use_cases/map/RoomGetterInterface.java b/src/main/java/com/mg105/use_cases/map/RoomGetterInterface.java new file mode 100644 index 00000000..b4e08c39 --- /dev/null +++ b/src/main/java/com/mg105/use_cases/map/RoomGetterInterface.java @@ -0,0 +1,30 @@ +package com.mg105.use_cases.map; + +import com.mg105.use_cases.outputds.RoomLayout; +import org.jetbrains.annotations.NotNull; + +/** + * Get attributes about the current room. + */ +public interface RoomGetterInterface { + /** + * Get the current room as a layout. + * + * @return the layout of the current room. + */ + @NotNull RoomLayout getCurrentRoomLayout(); + + /** + * Get the current walking sprite. + * + * @return the path of the current walking sprite + */ + @NotNull String getWalkingSprite(); + + /** + * Get whether the current room is the last room. + * + * @return if the current room is the last room. + */ + boolean isFinalRoom(); +} diff --git a/src/main/java/com/mg105/use_cases/map/RoomUpdater.java b/src/main/java/com/mg105/use_cases/map/RoomUpdater.java index f9a43834..96fd3d41 100644 --- a/src/main/java/com/mg105/use_cases/map/RoomUpdater.java +++ b/src/main/java/com/mg105/use_cases/map/RoomUpdater.java @@ -12,7 +12,7 @@ *

* RoomUpdater makes use of the Java9+ Observable pattern. */ -public class RoomUpdater { +public class RoomUpdater implements RoomUpdaterInterface { private final @NotNull PropertyChangeSupport observable; /** @@ -25,6 +25,7 @@ public RoomUpdater() { /** * Trigger an update on all the components that need updating on a room state change. */ + @Override public void updateRoom() { observable.firePropertyChange("", null, null); } diff --git a/src/main/java/com/mg105/use_cases/map/RoomUpdaterInterface.java b/src/main/java/com/mg105/use_cases/map/RoomUpdaterInterface.java new file mode 100644 index 00000000..4f099158 --- /dev/null +++ b/src/main/java/com/mg105/use_cases/map/RoomUpdaterInterface.java @@ -0,0 +1,14 @@ +package com.mg105.use_cases.map; + +/** + * RoomUpdaterInterface is the smallest possible interface to be used by anything that changes anything relating to the + * current map. + *

+ * Anything includes: changing position, opening a chest, ending a battle, changing rooms, etc. + */ +public interface RoomUpdaterInterface { + /** + * Notify all components when something has changed in the room. + */ + void updateRoom(); +} diff --git a/src/test/java/com/mg105/use_cases/CharacterMoverTest.java b/src/test/java/com/mg105/use_cases/CharacterMoverTest.java index 33414c83..599fa26d 100644 --- a/src/test/java/com/mg105/use_cases/CharacterMoverTest.java +++ b/src/test/java/com/mg105/use_cases/CharacterMoverTest.java @@ -3,6 +3,7 @@ import com.mg105.entities.*; import com.mg105.entities.items.UpgradeToken; import com.mg105.use_cases.map.CharacterMover; +import com.mg105.use_cases.map.CharacterMoverInterface; import com.mg105.use_cases.map.RoomUpdater; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -15,7 +16,7 @@ public class CharacterMoverTest { private GameState state; - private CharacterMover mover; + private CharacterMoverInterface mover; @BeforeEach void setup() { diff --git a/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java b/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java index e0d4adf2..b95216d5 100644 --- a/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java +++ b/src/test/java/com/mg105/use_cases/ReplayGeneratorTest.java @@ -1,6 +1,5 @@ package com.mg105.use_cases; -import com.mg105.use_cases.map.ReplayGenerator; import org.junit.jupiter.api.Test; import com.mg105.entities.*; import com.mg105.entities.items.UpgradeToken; diff --git a/src/test/java/com/mg105/use_cases/map/RoomGetterTest.java b/src/test/java/com/mg105/use_cases/map/RoomGetterTest.java index 0029fbae..3065ecbb 100644 --- a/src/test/java/com/mg105/use_cases/map/RoomGetterTest.java +++ b/src/test/java/com/mg105/use_cases/map/RoomGetterTest.java @@ -14,7 +14,7 @@ class RoomGetterTest { private GameState state; - private RoomGetter getter; + private RoomGetterInterface getter; @BeforeEach void setup() { From bb106df61ec6ea3f91a574f9ed721f018e34ce8f Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 12:51:47 -0500 Subject: [PATCH 04/11] Optimize all the imports --- src/main/java/com/mg105/Application.java | 26 ++++++++++++------- .../data_control/access/MoveDataAccess.java | 3 ++- .../java/com/mg105/entities/GameState.java | 3 ++- .../interface_adapters/InputInterpreter.java | 2 +- .../battle/BattlePresenter.java | 2 +- .../inventory/InventoryPresenter.java | 2 +- .../com/mg105/use_cases/ChestInteractor.java | 6 ++--- .../use_cases/OpponentSetInteractor.java | 5 ++-- .../use_cases/battle/BattleInteractor.java | 5 +++- .../mg105/use_cases/outputds/RoomLayout.java | 2 +- .../set_up/state_setter/PartyCreator.java | 1 - .../com/mg105/user_interface/AlertBox.java | 5 +--- .../mg105/user_interface/MinimapDrawer.java | 2 +- .../user_interface/ReplayGeneratorButton.java | 4 +-- 14 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/mg105/Application.java b/src/main/java/com/mg105/Application.java index 93457034..207abeba 100644 --- a/src/main/java/com/mg105/Application.java +++ b/src/main/java/com/mg105/Application.java @@ -1,24 +1,28 @@ package com.mg105; -import com.mg105.interface_adapters.battle.BattlePresenter; -import com.mg105.interface_adapters.map.MapGeneratorInterpreter; -import com.mg105.interface_adapters.map.MinimapInterpreter; -import com.mg105.interface_adapters.map.RoomInterpreter; -import com.mg105.interface_adapters.map.RoomInterpreterInterface; -import com.mg105.interface_adapters.tutorial.TutorialTextController; import com.mg105.data_control.access.MoveDataAccess; import com.mg105.data_control.access.PartyDataAccess; import com.mg105.data_control.creator.MoveDataCreator; import com.mg105.data_control.creator.PartyDataCreator; -import com.mg105.entities.*; +import com.mg105.entities.GameState; +import com.mg105.entities.Inventory; +import com.mg105.entities.WalkingCharacter; import com.mg105.interface_adapters.*; +import com.mg105.interface_adapters.battle.BattlePresenter; import com.mg105.interface_adapters.inventory.InventoryController; import com.mg105.interface_adapters.inventory.InventoryPresenter; +import com.mg105.interface_adapters.map.MapGeneratorInterpreter; +import com.mg105.interface_adapters.map.MinimapInterpreter; +import com.mg105.interface_adapters.map.RoomInterpreter; +import com.mg105.interface_adapters.map.RoomInterpreterInterface; +import com.mg105.interface_adapters.tutorial.TutorialTextController; +import com.mg105.use_cases.ChestInteractor; +import com.mg105.use_cases.OpponentSetInteractor; +import com.mg105.use_cases.ReplayGenerator; +import com.mg105.use_cases.WalkVisInteractor; import com.mg105.use_cases.battle.BattleInteractor; -import com.mg105.use_cases.map.*; -import com.mg105.user_interface.*; -import com.mg105.use_cases.*; import com.mg105.use_cases.inventory.InventoryInteractor; +import com.mg105.use_cases.map.*; import com.mg105.use_cases.save.PartySaver; import com.mg105.use_cases.save.Save; import com.mg105.use_cases.save.Saver; @@ -26,8 +30,10 @@ import com.mg105.use_cases.set_up.data_system_creator.DataStorageSystemCreator; import com.mg105.use_cases.set_up.state_setter.GameStateSetter; import com.mg105.use_cases.set_up.state_setter.PartyCreator; +import com.mg105.user_interface.*; import javafx.scene.input.KeyEvent; import javafx.stage.Stage; + import java.awt.*; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/com/mg105/data_control/access/MoveDataAccess.java b/src/main/java/com/mg105/data_control/access/MoveDataAccess.java index 2b56bc27..3d4becfd 100644 --- a/src/main/java/com/mg105/data_control/access/MoveDataAccess.java +++ b/src/main/java/com/mg105/data_control/access/MoveDataAccess.java @@ -13,7 +13,8 @@ import java.util.List; import java.util.NoSuchElementException; -import static com.mg105.utils.DataAccessConstants.*; +import static com.mg105.utils.DataAccessConstants.IS_TRUE; +import static com.mg105.utils.DataAccessConstants.MOVE_DATA_PATH; /** * This is a class mean to interact and get information about moves from a "database" diff --git a/src/main/java/com/mg105/entities/GameState.java b/src/main/java/com/mg105/entities/GameState.java index 5fca5c8c..7d7f4bf8 100644 --- a/src/main/java/com/mg105/entities/GameState.java +++ b/src/main/java/com/mg105/entities/GameState.java @@ -1,9 +1,10 @@ package com.mg105.entities; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; -import org.jetbrains.annotations.NotNull; /** * A class that represents the state of the game diff --git a/src/main/java/com/mg105/interface_adapters/InputInterpreter.java b/src/main/java/com/mg105/interface_adapters/InputInterpreter.java index 825c4e17..199b31c7 100644 --- a/src/main/java/com/mg105/interface_adapters/InputInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/InputInterpreter.java @@ -1,7 +1,7 @@ package com.mg105.interface_adapters; -import com.mg105.use_cases.ChestInteractor; import com.mg105.interface_adapters.tutorial.TutorialTextController; +import com.mg105.use_cases.ChestInteractor; import com.mg105.use_cases.OpponentSetInteractor; import com.mg105.use_cases.map.CharacterMoverInterface; import com.mg105.utils.TutorialTexts; diff --git a/src/main/java/com/mg105/interface_adapters/battle/BattlePresenter.java b/src/main/java/com/mg105/interface_adapters/battle/BattlePresenter.java index 3a9469ff..4d02dbe5 100644 --- a/src/main/java/com/mg105/interface_adapters/battle/BattlePresenter.java +++ b/src/main/java/com/mg105/interface_adapters/battle/BattlePresenter.java @@ -1,8 +1,8 @@ package com.mg105.interface_adapters.battle; import com.mg105.interface_adapters.Toggler; -import com.mg105.use_cases.battle.BattlePresenterInterface; import com.mg105.use_cases.battle.BattleInteractor; +import com.mg105.use_cases.battle.BattlePresenterInterface; import java.util.ArrayList; diff --git a/src/main/java/com/mg105/interface_adapters/inventory/InventoryPresenter.java b/src/main/java/com/mg105/interface_adapters/inventory/InventoryPresenter.java index a9c2b696..cbe936e2 100644 --- a/src/main/java/com/mg105/interface_adapters/inventory/InventoryPresenter.java +++ b/src/main/java/com/mg105/interface_adapters/inventory/InventoryPresenter.java @@ -1,7 +1,7 @@ package com.mg105.interface_adapters.inventory; -import com.mg105.use_cases.outputds.ItemDetails; import com.mg105.use_cases.inventory.InventoryPresenterInterface; +import com.mg105.use_cases.outputds.ItemDetails; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/com/mg105/use_cases/ChestInteractor.java b/src/main/java/com/mg105/use_cases/ChestInteractor.java index 8a163be8..e52e03da 100644 --- a/src/main/java/com/mg105/use_cases/ChestInteractor.java +++ b/src/main/java/com/mg105/use_cases/ChestInteractor.java @@ -1,8 +1,5 @@ package com.mg105.use_cases; -import java.awt.*; -import java.util.List; - import com.mg105.entities.GameState; import com.mg105.entities.Item; import com.mg105.entities.Room; @@ -11,6 +8,9 @@ import com.mg105.use_cases.map.RoomUpdaterInterface; import org.jetbrains.annotations.NotNull; +import java.awt.*; +import java.util.List; + public class ChestInteractor { private final @NotNull GameState gameState; diff --git a/src/main/java/com/mg105/use_cases/OpponentSetInteractor.java b/src/main/java/com/mg105/use_cases/OpponentSetInteractor.java index ecb6b8f4..2c88ca9c 100644 --- a/src/main/java/com/mg105/use_cases/OpponentSetInteractor.java +++ b/src/main/java/com/mg105/use_cases/OpponentSetInteractor.java @@ -1,8 +1,9 @@ package com.mg105.use_cases; -import com.mg105.entities.*; +import com.mg105.entities.GameState; +import com.mg105.entities.OpponentSet; -import java.awt.Point; +import java.awt.*; import java.util.List; /** diff --git a/src/main/java/com/mg105/use_cases/battle/BattleInteractor.java b/src/main/java/com/mg105/use_cases/battle/BattleInteractor.java index 40d17eeb..6e11490d 100644 --- a/src/main/java/com/mg105/use_cases/battle/BattleInteractor.java +++ b/src/main/java/com/mg105/use_cases/battle/BattleInteractor.java @@ -1,6 +1,9 @@ package com.mg105.use_cases.battle; -import com.mg105.entities.*; +import com.mg105.entities.Battle; +import com.mg105.entities.BattleCharacter; +import com.mg105.entities.GameState; +import com.mg105.entities.Move; import com.mg105.use_cases.inventory.InventoryInteractor; import com.mg105.use_cases.save.Saver; diff --git a/src/main/java/com/mg105/use_cases/outputds/RoomLayout.java b/src/main/java/com/mg105/use_cases/outputds/RoomLayout.java index 57c537e7..7b06f8e8 100644 --- a/src/main/java/com/mg105/use_cases/outputds/RoomLayout.java +++ b/src/main/java/com/mg105/use_cases/outputds/RoomLayout.java @@ -1,9 +1,9 @@ package com.mg105.use_cases.outputds; import org.jetbrains.annotations.NotNull; -import java.util.List; import java.awt.*; +import java.util.List; /** * The layout of a room. diff --git a/src/main/java/com/mg105/use_cases/set_up/state_setter/PartyCreator.java b/src/main/java/com/mg105/use_cases/set_up/state_setter/PartyCreator.java index 39465363..f1c4987b 100644 --- a/src/main/java/com/mg105/use_cases/set_up/state_setter/PartyCreator.java +++ b/src/main/java/com/mg105/use_cases/set_up/state_setter/PartyCreator.java @@ -7,7 +7,6 @@ import com.mg105.use_cases.outputds.MoveDetails; import com.mg105.use_cases.save.PartyDataInterface; import com.mg105.utils.PartyConstants; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; /** diff --git a/src/main/java/com/mg105/user_interface/AlertBox.java b/src/main/java/com/mg105/user_interface/AlertBox.java index f85f8742..2381bef7 100644 --- a/src/main/java/com/mg105/user_interface/AlertBox.java +++ b/src/main/java/com/mg105/user_interface/AlertBox.java @@ -3,14 +3,11 @@ import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; -import javafx.scene.layout.StackPane; +import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.stage.Modality; import javafx.stage.Stage; -import javafx.scene.control.Label; - -import java.awt.*; /** * AlertBox is a component that creates a new window and display a users a message. diff --git a/src/main/java/com/mg105/user_interface/MinimapDrawer.java b/src/main/java/com/mg105/user_interface/MinimapDrawer.java index c6d70962..5c653718 100644 --- a/src/main/java/com/mg105/user_interface/MinimapDrawer.java +++ b/src/main/java/com/mg105/user_interface/MinimapDrawer.java @@ -4,9 +4,9 @@ import com.mg105.interface_adapters.map.RoomState; import javafx.scene.Group; import javafx.scene.Scene; +import javafx.scene.paint.Color; import javafx.scene.shape.Line; import javafx.scene.shape.Rectangle; -import javafx.scene.paint.Color; import org.jetbrains.annotations.NotNull; import java.awt.*; diff --git a/src/main/java/com/mg105/user_interface/ReplayGeneratorButton.java b/src/main/java/com/mg105/user_interface/ReplayGeneratorButton.java index 53c4b3cc..de960402 100644 --- a/src/main/java/com/mg105/user_interface/ReplayGeneratorButton.java +++ b/src/main/java/com/mg105/user_interface/ReplayGeneratorButton.java @@ -1,10 +1,10 @@ package com.mg105.user_interface; import com.mg105.interface_adapters.ReplayGeneratorInterpreter; -import javafx.event.ActionEvent; -import org.jetbrains.annotations.NotNull; import com.mg105.interface_adapters.Toggler; +import javafx.event.ActionEvent; import javafx.event.EventHandler; +import org.jetbrains.annotations.NotNull; /** From 35372a75351743d6112b14ae67d51dcd114c318f Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 14:12:12 -0500 Subject: [PATCH 05/11] Remove unused code --- src/main/java/com/mg105/entities/GameState.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main/java/com/mg105/entities/GameState.java b/src/main/java/com/mg105/entities/GameState.java index 7d7f4bf8..d428cd27 100644 --- a/src/main/java/com/mg105/entities/GameState.java +++ b/src/main/java/com/mg105/entities/GameState.java @@ -13,7 +13,6 @@ */ public class GameState { - private Room firstRoom; private Room lastRoom; private Room currentRoom; @@ -160,7 +159,6 @@ public void removeFaintedPartyMember(@NotNull String characterName){ * @param lastRoom the end room of the map (where the game is won). */ public void setMap(@NotNull Room firstRoom, @NotNull Room lastRoom) { - this.firstRoom = firstRoom; this.currentRoom = firstRoom; this.lastRoom = lastRoom; } @@ -243,18 +241,6 @@ public void setCurrOpponent(OpponentSet currOpponent) { this.currOpponent = currOpponent; } - /** - * Get if the player is in the first room. - * - * @return true if the player is in the first room, false otherwise. - */ - public boolean isCurrentRoomFirstRoom() { - // NOTE: In this case it is actually ok to directly compare the two via == and not .equals()... This is because - // we actually care that this is exactly the same instance of the room, not just two rooms that happen to have - // the same configuration. - return currentRoom == firstRoom; - } - /** * Get if the player is in the last room. * From 2acdb71fd586fe072bbbdb5cf0fba110de7d27f9 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 18:28:46 -0500 Subject: [PATCH 06/11] Add tests to the MapGeneratorInterpreter --- .../map/MapGeneratorInterpreterTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterTest.java diff --git a/src/test/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterTest.java b/src/test/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterTest.java new file mode 100644 index 00000000..80a84c23 --- /dev/null +++ b/src/test/java/com/mg105/interface_adapters/map/MapGeneratorInterpreterTest.java @@ -0,0 +1,30 @@ +package com.mg105.interface_adapters.map; + +import com.mg105.use_cases.map.MapGeneratorInterface; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class MapGeneratorInterpreterTest { + @Test + void passthrough() { + CountingMapGenerator generator = new CountingMapGenerator(); + MapGeneratorInterpreter interpreter = new MapGeneratorInterpreter(generator); + assertEquals(0, generator.getCount()); + interpreter.generateMap(); + assertEquals(1, generator.getCount()); + } + + private static class CountingMapGenerator implements MapGeneratorInterface { + private int count = 0; + + public int getCount() { + return count; + } + + @Override + public void generateMap() { + count += 1; + } + } +} From a0e2e2cc6bb2dfa6c101364848767cc57c902c90 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 18:30:39 -0500 Subject: [PATCH 07/11] Rename enums to be more descriptive --- .../map/MinimapInterpreter.java | 18 ++++++------ .../map/MinimapInterpreterInterface.java | 2 +- .../{RoomState.java => MinimapRoomState.java} | 2 +- .../map/RoomInterpreter.java | 28 +++++++++---------- .../map/RoomInterpreterInterface.java | 2 +- .../map/{TileType.java => RoomTileType.java} | 2 +- .../com/mg105/user_interface/MapDrawer.java | 20 ++++++------- .../mg105/user_interface/MinimapDrawer.java | 6 ++-- 8 files changed, 40 insertions(+), 40 deletions(-) rename src/main/java/com/mg105/interface_adapters/map/{RoomState.java => MinimapRoomState.java} (90%) rename src/main/java/com/mg105/interface_adapters/map/{TileType.java => RoomTileType.java} (94%) diff --git a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java index 19419a14..539bd042 100644 --- a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreter.java @@ -19,7 +19,7 @@ public class MinimapInterpreter implements PropertyChangeListener, Resetable, Mi private final @NotNull RoomGetterInterface getter; private @Nullable Point lastPosition; - private @NotNull RoomState[][] mapSoFar; + private @NotNull MinimapRoomState[][] mapSoFar; private final @NotNull Point currentRoom; /** @@ -40,8 +40,8 @@ public MinimapInterpreter(@NotNull RoomGetterInterface getter) { @Override public void reset() { lastPosition = null; - mapSoFar = new RoomState[1][1]; - mapSoFar[0][0] = RoomState.EXPLORED; + mapSoFar = new MinimapRoomState[1][1]; + mapSoFar[0][0] = MinimapRoomState.EXPLORED; currentRoom.x = 0; currentRoom.y = 0; } @@ -73,7 +73,7 @@ public void propertyChange(PropertyChangeEvent evt) { } autoBumpMapSoFarBecauseOf(currentRoom); - mapSoFar[currentRoom.y][currentRoom.x] = RoomState.EXPLORED; + mapSoFar[currentRoom.y][currentRoom.x] = MinimapRoomState.EXPLORED; // Set look for potential next rooms for (Point nextDoowayPosition : layout.getDoorways()) { @@ -90,7 +90,7 @@ public void propertyChange(PropertyChangeEvent evt) { autoBumpMapSoFarBecauseOf(nextRoom, currentRoom); if (mapSoFar[nextRoom.y][nextRoom.x] == null) { - mapSoFar[nextRoom.y][nextRoom.x] = RoomState.UNEXPLORED; + mapSoFar[nextRoom.y][nextRoom.x] = MinimapRoomState.UNEXPLORED; } } } @@ -104,7 +104,7 @@ public void propertyChange(PropertyChangeEvent evt) { * @return the currently explored map. */ @Override - public @NotNull RoomState[][] getMapSoFar() { + public @NotNull MinimapRoomState[][] getMapSoFar() { return mapSoFar; } @@ -130,11 +130,11 @@ public void propertyChange(PropertyChangeEvent evt) { private void autoBumpMapSoFarBecauseOf(@NotNull Point next, @NotNull Point... toMaintain) { int yOffset = 0; int xOffset = 0; - RoomState[][] nextMap = new RoomState[0][0]; + MinimapRoomState[][] nextMap = new MinimapRoomState[0][0]; boolean needsBump = false; if (next.x < 0 || next.x >= mapSoFar[0].length) { - nextMap = new RoomState[mapSoFar.length][mapSoFar[0].length + 1]; + nextMap = new MinimapRoomState[mapSoFar.length][mapSoFar[0].length + 1]; if (next.x < 0) { xOffset = 1; next.x += 1; @@ -144,7 +144,7 @@ private void autoBumpMapSoFarBecauseOf(@NotNull Point next, @NotNull Point... to } needsBump = true; } else if (next.y < 0 || next.y >= mapSoFar.length) { - nextMap = new RoomState[mapSoFar.length + 1][mapSoFar[0].length]; + nextMap = new MinimapRoomState[mapSoFar.length + 1][mapSoFar[0].length]; if (next.y < 0) { yOffset = 1; next.y += 1; diff --git a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java index d1c376a3..d9495479 100644 --- a/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java +++ b/src/main/java/com/mg105/interface_adapters/map/MinimapInterpreterInterface.java @@ -15,7 +15,7 @@ public interface MinimapInterpreterInterface { * * @see MinimapInterpreterInterface#getCurrentPosition() */ - @NotNull RoomState[][] getMapSoFar(); + @NotNull MinimapRoomState[][] getMapSoFar(); /** * Get the current room position diff --git a/src/main/java/com/mg105/interface_adapters/map/RoomState.java b/src/main/java/com/mg105/interface_adapters/map/MinimapRoomState.java similarity index 90% rename from src/main/java/com/mg105/interface_adapters/map/RoomState.java rename to src/main/java/com/mg105/interface_adapters/map/MinimapRoomState.java index e67a69ac..d0596033 100644 --- a/src/main/java/com/mg105/interface_adapters/map/RoomState.java +++ b/src/main/java/com/mg105/interface_adapters/map/MinimapRoomState.java @@ -5,7 +5,7 @@ *

* Note that we treat 'null' as a roomm state being unknown. */ -public enum RoomState { +public enum MinimapRoomState { /** The room is implied to exist but is unexplored. */ UNEXPLORED, /** The room has been visited at least once */ diff --git a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java index 094f5359..e2a52943 100644 --- a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java +++ b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreter.java @@ -30,45 +30,45 @@ public RoomInterpreter(@NotNull RoomGetterInterface getter) { * right corner. */ @Override - public TileType[][] getCurrentRoom() { - TileType[][] canvas = new TileType[MapConstants.ROOM_SIZE][MapConstants.ROOM_SIZE]; + public RoomTileType[][] getCurrentRoom() { + RoomTileType[][] canvas = new RoomTileType[MapConstants.ROOM_SIZE][MapConstants.ROOM_SIZE]; for (int y = 1; y < MapConstants.ROOM_SIZE - 1; y++) { for (int x = 1; x < MapConstants.ROOM_SIZE - 1; x++) { - canvas[y][x] = TileType.FLOOR; + canvas[y][x] = RoomTileType.FLOOR; } } for (int i = 0; i < MapConstants.ROOM_SIZE; i++) { - canvas[i][MapConstants.ROOM_SIZE - 1] = TileType.WALL; - canvas[i][0] = TileType.WALL; + canvas[i][MapConstants.ROOM_SIZE - 1] = RoomTileType.WALL; + canvas[i][0] = RoomTileType.WALL; } for (int i = 1; i < MapConstants.ROOM_SIZE - 1; i++) { - canvas[MapConstants.ROOM_SIZE - 1][i] = TileType.WALL_WITH_FACE; - canvas[0][i] = TileType.WALL_WITH_FACE; + canvas[MapConstants.ROOM_SIZE - 1][i] = RoomTileType.WALL_WITH_FACE; + canvas[0][i] = RoomTileType.WALL_WITH_FACE; } - canvas[MapConstants.ROOM_SIZE - 1][0] = TileType.WALL_WITH_FACE; - canvas[MapConstants.ROOM_SIZE - 1][MapConstants.ROOM_SIZE - 1] = TileType.WALL_WITH_FACE; + canvas[MapConstants.ROOM_SIZE - 1][0] = RoomTileType.WALL_WITH_FACE; + canvas[MapConstants.ROOM_SIZE - 1][MapConstants.ROOM_SIZE - 1] = RoomTileType.WALL_WITH_FACE; RoomLayout room = getter.getCurrentRoomLayout(); for (Point doorway : room.getDoorways()) { - canvas[doorway.y][doorway.x] = TileType.EXIT; + canvas[doorway.y][doorway.x] = RoomTileType.EXIT; if (doorway.x == 0 || doorway.x == MapConstants.ROOM_SIZE - 1) { - canvas[doorway.y - 1][doorway.x] = TileType.WALL_WITH_FACE; + canvas[doorway.y - 1][doorway.x] = RoomTileType.WALL_WITH_FACE; } } for (Point chest : room.getClosedChests()) { - canvas[chest.y][chest.x] = TileType.CHEST; + canvas[chest.y][chest.x] = RoomTileType.CHEST; } for (Point chest : room.getOpenChests()) { - canvas[chest.y][chest.x] = TileType.CHEST_OPEN; + canvas[chest.y][chest.x] = RoomTileType.CHEST_OPEN; } for (Point opponents : room.getOpponents()) { - canvas[opponents.y][opponents.x] = TileType.OPPONENT_SET; + canvas[opponents.y][opponents.x] = RoomTileType.OPPONENT_SET; } return canvas; diff --git a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java index 28c47303..f97cde7d 100644 --- a/src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java +++ b/src/main/java/com/mg105/interface_adapters/map/RoomInterpreterInterface.java @@ -13,7 +13,7 @@ public interface RoomInterpreterInterface { * * @return the state of the current room. */ - TileType[][] getCurrentRoom(); + RoomTileType[][] getCurrentRoom(); /** * Get the position of the player within the room. diff --git a/src/main/java/com/mg105/interface_adapters/map/TileType.java b/src/main/java/com/mg105/interface_adapters/map/RoomTileType.java similarity index 94% rename from src/main/java/com/mg105/interface_adapters/map/TileType.java rename to src/main/java/com/mg105/interface_adapters/map/RoomTileType.java index 4f0765b1..8f9d4272 100644 --- a/src/main/java/com/mg105/interface_adapters/map/TileType.java +++ b/src/main/java/com/mg105/interface_adapters/map/RoomTileType.java @@ -3,7 +3,7 @@ /** * Types of tiles that can appear within a room. */ -public enum TileType { +public enum RoomTileType { /** Empty floor that can be walked on */ FLOOR, /** Wall that cannot be walked on. Mainly used for the border */ diff --git a/src/main/java/com/mg105/user_interface/MapDrawer.java b/src/main/java/com/mg105/user_interface/MapDrawer.java index e492b063..212f6e3a 100644 --- a/src/main/java/com/mg105/user_interface/MapDrawer.java +++ b/src/main/java/com/mg105/user_interface/MapDrawer.java @@ -1,7 +1,7 @@ package com.mg105.user_interface; import com.mg105.interface_adapters.map.RoomInterpreterInterface; -import com.mg105.interface_adapters.map.TileType; +import com.mg105.interface_adapters.map.RoomTileType; import com.mg105.utils.MapConstants; import javafx.scene.Group; import javafx.scene.Scene; @@ -24,7 +24,7 @@ public class MapDrawer implements PropertyChangeListener, Toggleable { private final @NotNull Scene scene; private final @NotNull Group group; - private final @NotNull Map tiles; + private final @NotNull Map tiles; private final @NotNull Map playerSprites; private final @NotNull Image missingTile; private boolean isVisible; @@ -48,13 +48,13 @@ public MapDrawer(@NotNull RoomInterpreterInterface interpreter) { missingTile = new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/missing.png"))); tiles = new HashMap<>(6); - tiles.put(TileType.FLOOR, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/floor.png")))); - tiles.put(TileType.WALL, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/wall.png")))); - tiles.put(TileType.WALL_WITH_FACE, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/wall_face.png")))); - tiles.put(TileType.EXIT, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/exit.png")))); - tiles.put(TileType.CHEST, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/chest.png")))); - tiles.put(TileType.CHEST_OPEN, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/chest_open.png")))); - tiles.put(TileType.OPPONENT_SET, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/battle.png")))); + tiles.put(RoomTileType.FLOOR, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/floor.png")))); + tiles.put(RoomTileType.WALL, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/wall.png")))); + tiles.put(RoomTileType.WALL_WITH_FACE, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/wall_face.png")))); + tiles.put(RoomTileType.EXIT, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/exit.png")))); + tiles.put(RoomTileType.CHEST, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/chest.png")))); + tiles.put(RoomTileType.CHEST_OPEN, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/chest_open.png")))); + tiles.put(RoomTileType.OPPONENT_SET, new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/tiles/battle.png")))); playerSprites = new HashMap<>(4); playerSprites.put("/sprites/A.png", new Image(Objects.requireNonNull(MapDrawer.class.getResourceAsStream("/sprites/A.png")))); @@ -94,7 +94,7 @@ public void toggle(boolean isVisible) { * current room. */ public void updateRoom() { - TileType[][] room = interpreter.getCurrentRoom(); + RoomTileType[][] room = interpreter.getCurrentRoom(); group.getChildren().clear(); diff --git a/src/main/java/com/mg105/user_interface/MinimapDrawer.java b/src/main/java/com/mg105/user_interface/MinimapDrawer.java index 5c653718..f0be5d87 100644 --- a/src/main/java/com/mg105/user_interface/MinimapDrawer.java +++ b/src/main/java/com/mg105/user_interface/MinimapDrawer.java @@ -1,7 +1,7 @@ package com.mg105.user_interface; import com.mg105.interface_adapters.map.MinimapInterpreterInterface; -import com.mg105.interface_adapters.map.RoomState; +import com.mg105.interface_adapters.map.MinimapRoomState; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; @@ -59,7 +59,7 @@ public MinimapDrawer(@NotNull MinimapInterpreterInterface interpreter) { @Override public void toggle(boolean isVisible) { if (isVisible) { - RoomState[][] map = interpreter.getMapSoFar(); + MinimapRoomState[][] map = interpreter.getMapSoFar(); Point currentPosition = interpreter.getCurrentPosition(); final int cellDimension = CANVAS_SIZE / Math.max(map.length, map[0].length); @@ -83,7 +83,7 @@ public void toggle(boolean isVisible) { } // Rectangle for each room - if (map[y][x] == RoomState.EXPLORED) { + if (map[y][x] == MinimapRoomState.EXPLORED) { // First we draw the middle square Rectangle r = new Rectangle(); r.setX(leftPadding + innerCellPadding + x * cellDimension); From 6fc791eba39f19a85fae9ced39b1d1f3ee5c1e28 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 19:08:17 -0500 Subject: [PATCH 08/11] Add tests to the RoomInterpreter --- .../map/RoomInterpreterTest.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/java/com/mg105/interface_adapters/map/RoomInterpreterTest.java diff --git a/src/test/java/com/mg105/interface_adapters/map/RoomInterpreterTest.java b/src/test/java/com/mg105/interface_adapters/map/RoomInterpreterTest.java new file mode 100644 index 00000000..c51505cd --- /dev/null +++ b/src/test/java/com/mg105/interface_adapters/map/RoomInterpreterTest.java @@ -0,0 +1,81 @@ +package com.mg105.interface_adapters.map; + +import com.mg105.use_cases.map.RoomGetterInterface; +import com.mg105.use_cases.outputds.RoomLayout; +import com.mg105.utils.MapConstants; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Test; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class RoomInterpreterTest { + @Test + void getLayout() { + RoomTileType[][] expected = new RoomTileType[][]{ + {RoomTileType.WALL, RoomTileType.EXIT, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL}, + {RoomTileType.WALL_WITH_FACE, RoomTileType.OPPONENT_SET, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.WALL}, + {RoomTileType.EXIT, RoomTileType.CHEST_OPEN, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.WALL_WITH_FACE}, + {RoomTileType.WALL, RoomTileType.CHEST, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.EXIT}, + {RoomTileType.WALL, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.WALL}, + {RoomTileType.WALL, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.WALL}, + {RoomTileType.WALL, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.FLOOR, RoomTileType.WALL}, + {RoomTileType.WALL_WITH_FACE, RoomTileType.EXIT, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE, RoomTileType.WALL_WITH_FACE}, + }; + RoomInterpreter interpreter = new RoomInterpreter(new FakeRoomGetter()); + RoomTileType[][] actual = interpreter.getCurrentRoom(); + + for (int y = 0; y < MapConstants.ROOM_SIZE; y++) { + for (int x = 0; x < MapConstants.ROOM_SIZE; x++) { + assertEquals(expected[y][x], actual[y][x]); + } + } + } + + @Test + void getPlayer() { + RoomInterpreter interpreter = new RoomInterpreter(new FakeRoomGetter()); + assertEquals(new Point(4, 4), interpreter.getPlayer()); + } + + @Test + void getSprite() { + RoomInterpreter interpreter = new RoomInterpreter(new FakeRoomGetter()); + assertEquals("/sprites/B.png", interpreter.getCharacterSprite()); + } + + private static class FakeRoomGetter implements RoomGetterInterface { + @Override + public @NotNull RoomLayout getCurrentRoomLayout() { + List closedChests = new ArrayList<>(); + closedChests.add(new Point(1, 3)); + + List openChests = new ArrayList<>(); + openChests.add(new Point(1, 2)); + + List opponents = new ArrayList<>(); + opponents.add(new Point(1, 1)); + + List doorways = new ArrayList<>(); + doorways.add(new Point(0, 2)); + doorways.add(new Point(1, 0)); + doorways.add(new Point(MapConstants.ROOM_SIZE-1, 3)); + doorways.add(new Point(1, MapConstants.ROOM_SIZE-1)); + + return new RoomLayout(closedChests, openChests, opponents, doorways, new Point(4, 4)); + } + + @Override + public @NotNull String getWalkingSprite() { + return "/sprites/B.png"; + } + + @Override + public boolean isFinalRoom() { + return false; + } + } +} From 3828a5244e3e0d44ecbb2078ef407b713ffcc623 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 19:29:52 -0500 Subject: [PATCH 09/11] Add tests to the MinimapInterpreter --- .../map/MinimapInterpreterTest.java | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/test/java/com/mg105/interface_adapters/map/MinimapInterpreterTest.java diff --git a/src/test/java/com/mg105/interface_adapters/map/MinimapInterpreterTest.java b/src/test/java/com/mg105/interface_adapters/map/MinimapInterpreterTest.java new file mode 100644 index 00000000..5f2b6782 --- /dev/null +++ b/src/test/java/com/mg105/interface_adapters/map/MinimapInterpreterTest.java @@ -0,0 +1,147 @@ +package com.mg105.interface_adapters.map; + +import com.mg105.use_cases.map.RoomGetterInterface; +import com.mg105.use_cases.outputds.RoomLayout; +import com.mg105.utils.MapConstants; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Test; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class MinimapInterpreterTest { + @Test + void getInitialPosition() { + MinimapInterpreter interpreter = new MinimapInterpreter(new FakeRoomGetter()); + assertEquals(new Point(), interpreter.getCurrentPosition()); + } + + @Test + void getInitialMinimap() { + MinimapInterpreter interpreter = new MinimapInterpreter(new FakeRoomGetter()); + MinimapRoomState[][] minimap = interpreter.getMapSoFar(); + assertEquals(1, minimap.length); + assertEquals(1, minimap[0].length); + assertEquals(MinimapRoomState.EXPLORED, minimap[0][0]); + } + + @Test + void exploreRoomTop() { + FakeRoomGetter getter = new FakeRoomGetter(); + MinimapInterpreter interpreter = new MinimapInterpreter(getter); + interpreter.propertyChange(null); + getter.setCurrentPosition(new Point(5, 0)); + interpreter.propertyChange(null); + MinimapRoomState[][] minimap = interpreter.getMapSoFar(); + assertEquals(3, minimap.length); + assertEquals(3, minimap[0].length); + MinimapRoomState[][] expected = new MinimapRoomState[][]{ + {null, MinimapRoomState.EXPLORED, null}, + {MinimapRoomState.UNEXPLORED, MinimapRoomState.EXPLORED, MinimapRoomState.UNEXPLORED}, + {null, MinimapRoomState.UNEXPLORED, null} + }; + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + assertEquals(expected[y][x], minimap[y][x]); + } + } + } + + @Test + void exploreRoomBottom() { + FakeRoomGetter getter = new FakeRoomGetter(); + MinimapInterpreter interpreter = new MinimapInterpreter(getter); + interpreter.propertyChange(null); + getter.setCurrentPosition(new Point(5, MapConstants.ROOM_SIZE - 1)); + interpreter.propertyChange(null); + MinimapRoomState[][] minimap = interpreter.getMapSoFar(); + assertEquals(3, minimap.length); + assertEquals(3, minimap[0].length); + MinimapRoomState[][] expected = new MinimapRoomState[][]{ + {null, MinimapRoomState.UNEXPLORED, null}, + {MinimapRoomState.UNEXPLORED, MinimapRoomState.EXPLORED, MinimapRoomState.UNEXPLORED}, + {null, MinimapRoomState.EXPLORED, null} + }; + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + assertEquals(expected[y][x], minimap[y][x]); + } + } + } + + @Test + void exploreRoomLeft() { + FakeRoomGetter getter = new FakeRoomGetter(); + MinimapInterpreter interpreter = new MinimapInterpreter(getter); + interpreter.propertyChange(null); + getter.setCurrentPosition(new Point(0, 5)); + interpreter.propertyChange(null); + MinimapRoomState[][] minimap = interpreter.getMapSoFar(); + assertEquals(3, minimap.length); + assertEquals(3, minimap[0].length); + MinimapRoomState[][] expected = new MinimapRoomState[][]{ + {null, MinimapRoomState.UNEXPLORED, null}, + {MinimapRoomState.EXPLORED, MinimapRoomState.EXPLORED, MinimapRoomState.UNEXPLORED}, + {null, MinimapRoomState.UNEXPLORED, null} + }; + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + assertEquals(expected[y][x], minimap[y][x]); + } + } + } + + @Test + void exploreRoomRight() { + FakeRoomGetter getter = new FakeRoomGetter(); + MinimapInterpreter interpreter = new MinimapInterpreter(getter); + interpreter.propertyChange(null); + getter.setCurrentPosition(new Point(MapConstants.ROOM_SIZE - 1, 5)); + interpreter.propertyChange(null); + MinimapRoomState[][] minimap = interpreter.getMapSoFar(); + assertEquals(3, minimap.length); + assertEquals(3, minimap[0].length); + MinimapRoomState[][] expected = new MinimapRoomState[][]{ + {null, MinimapRoomState.UNEXPLORED, null}, + {MinimapRoomState.UNEXPLORED, MinimapRoomState.EXPLORED, MinimapRoomState.EXPLORED}, + {null, MinimapRoomState.UNEXPLORED, null} + }; + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 3; x++) { + assertEquals(expected[y][x], minimap[y][x]); + } + } + } + + private static class FakeRoomGetter implements RoomGetterInterface { + private Point currentPosition = new Point(4, 4); + + public void setCurrentPosition(Point currentPosition) { + this.currentPosition = currentPosition; + } + + @Override + public @NotNull RoomLayout getCurrentRoomLayout() { + List doorways = new ArrayList<>(); + doorways.add(new Point(0, 2)); + doorways.add(new Point(1, 0)); + doorways.add(new Point(MapConstants.ROOM_SIZE-1, 3)); + doorways.add(new Point(1, MapConstants.ROOM_SIZE-1)); + + return new RoomLayout(new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), doorways, currentPosition); + } + + @Override + public @NotNull String getWalkingSprite() { + return "/sprites/A.png"; + } + + @Override + public boolean isFinalRoom() { + return false; + } + } +} From 71af6336584f0bca5e02ef0c6cd4bd802a118c06 Mon Sep 17 00:00:00 2001 From: Theodore Date: Tue, 6 Dec 2022 19:48:05 -0500 Subject: [PATCH 10/11] Add some GameState tests --- .../com/mg105/entities/GameStateTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/com/mg105/entities/GameStateTest.java b/src/test/java/com/mg105/entities/GameStateTest.java index e871cc99..417442d3 100644 --- a/src/test/java/com/mg105/entities/GameStateTest.java +++ b/src/test/java/com/mg105/entities/GameStateTest.java @@ -1,5 +1,6 @@ package com.mg105.entities; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.awt.*; @@ -8,4 +9,34 @@ import static org.junit.jupiter.api.Assertions.*; public class GameStateTest { + private Room firstRoom; + private Room lastRoom; + private WalkingCharacter walkingCharacter; + private GameState state; + + @BeforeEach + void setup() { + firstRoom = new Room(new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); + lastRoom = new Room(new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); + walkingCharacter = new WalkingCharacter(new Point()); + state = new GameState(new Inventory(), walkingCharacter); + } + + @Test + void lastRoomFalse() { + state.setMap(firstRoom, lastRoom); + assertFalse(state.isCurrentRoomLastRoom()); + } + + @Test + void lastRoomTrue() { + state.setMap(firstRoom, lastRoom); + state.setCurrentRoom(lastRoom); + assertTrue(state.isCurrentRoomLastRoom()); + } + + @Test + void getWalkingCharacter() { + assertEquals(walkingCharacter, state.getWalkingCharacter()); + } } From 4964c3de226907652806be9d6b39066c94dc57f1 Mon Sep 17 00:00:00 2001 From: Theodore Date: Wed, 7 Dec 2022 19:17:40 -0500 Subject: [PATCH 11/11] Add more GameState tests --- src/main/java/com/mg105/entities/GameState.java | 9 --------- .../java/com/mg105/use_cases/ReplayGenerator.java | 4 ++-- src/test/java/com/mg105/entities/GameStateTest.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/mg105/entities/GameState.java b/src/main/java/com/mg105/entities/GameState.java index a508c43d..1d197824 100644 --- a/src/main/java/com/mg105/entities/GameState.java +++ b/src/main/java/com/mg105/entities/GameState.java @@ -63,15 +63,6 @@ public Inventory getInventory() { return this.inventory; } - /** - * Returns the list of characters in the party - * - * @return a list of all characters in party - */ - public ArrayList charactersList() { - return this.party; - } - /** * Returns the character in party based on the given name * Only returns a party member that is not fainted diff --git a/src/main/java/com/mg105/use_cases/ReplayGenerator.java b/src/main/java/com/mg105/use_cases/ReplayGenerator.java index ab646077..d4e9478a 100644 --- a/src/main/java/com/mg105/use_cases/ReplayGenerator.java +++ b/src/main/java/com/mg105/use_cases/ReplayGenerator.java @@ -54,8 +54,8 @@ public void reviveCharacters() { potion4.consume(state, PartyConstants.ALL_PARTY_MEMBER_NAMES[3]); // set the characters to max health - for (int i = 0; i < state.charactersList().size(); i++) { - state.charactersList().get(i).fullHealCharacter(); + for (int i = 0; i < state.getParty().size(); i++) { + state.getParty().get(i).fullHealCharacter(); } } diff --git a/src/test/java/com/mg105/entities/GameStateTest.java b/src/test/java/com/mg105/entities/GameStateTest.java index 417442d3..2e0fd3ee 100644 --- a/src/test/java/com/mg105/entities/GameStateTest.java +++ b/src/test/java/com/mg105/entities/GameStateTest.java @@ -39,4 +39,17 @@ void lastRoomTrue() { void getWalkingCharacter() { assertEquals(walkingCharacter, state.getWalkingCharacter()); } + + @Test + void getParty() { + assertEquals(0, state.getParty().size()); + } + + @Test + void removeCurrEncounter() { + state.setCurrEncounter(new Battle(new ArrayList<>(), new ArrayList<>())); + assertTrue(state.hasCurrEncounter()); + state.removeCurrEncounter(); + assertFalse(state.hasCurrEncounter()); + } }