Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #100 from CSC207-2022F-UofT/cleanup/solid-i-to-mapgen
Browse files Browse the repository at this point in the history
Ensure all map-related components follow the I of SOLID
  • Loading branch information
6167656e74323431 authored Dec 8, 2022
2 parents 64590cc + 4964c3d commit c20640a
Show file tree
Hide file tree
Showing 44 changed files with 644 additions and 184 deletions.
26 changes: 18 additions & 8 deletions src/main/java/com/mg105/Application.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
package com.mg105;

import com.mg105.interface_adapters.battle.BattlePresenter;
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.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;
import com.mg105.use_cases.set_up.data_system_creator.CreateDataStorage;
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;

Expand Down Expand Up @@ -69,8 +79,8 @@ public void start(Stage primaryStage) {
MapGeneratorButton generateMapButton = new MapGeneratorButton(mapGeneratorInterpreter, sceneController);
MainMenu mainMenu = new MainMenu(generateMapButton);

RoomGetter roomGetter = new RoomGetter(state);
RoomInterpreter roomInterpreter = new RoomInterpreter(roomGetter);
RoomGetterInterface roomGetter = new RoomGetter(state);
RoomInterpreterInterface roomInterpreter = new RoomInterpreter(roomGetter);
MapDrawer mapDrawer = new MapDrawer(roomInterpreter);
drawableComponents.put(Toggler.ToggleableComponent.MAIN_MENU, mainMenu);
drawableComponents.put(Toggler.ToggleableComponent.MAP, mapDrawer);
Expand Down Expand Up @@ -130,7 +140,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 2 additions & 25 deletions src/main/java/com/mg105/entities/GameState.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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
* <p>
* This class has all attributes that the game relies on
*/

public class GameState {
private Room firstRoom;
private Room lastRoom;
private Room currentRoom;

Expand Down Expand Up @@ -64,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<BattleCharacter> charactersList() {
return this.party;
}

/**
* Returns the character in party based on the given name
* Only returns a party member that is not fainted
Expand Down Expand Up @@ -174,7 +164,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;
}
Expand Down Expand Up @@ -260,18 +249,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.
*
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/mg105/interface_adapters/InputInterpreter.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.mg105.interface_adapters;

import com.mg105.use_cases.ChestInteractor;
import com.mg105.interface_adapters.tutorial.TutorialTextController;
import com.mg105.use_cases.CharacterMover;
import com.mg105.use_cases.ChestInteractor;
import com.mg105.use_cases.OpponentSetInteractor;
import com.mg105.use_cases.map.CharacterMoverInterface;
import com.mg105.utils.TutorialTexts;
import org.jetbrains.annotations.NotNull;

Expand All @@ -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;
Expand All @@ -23,13 +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 interactor used to interact 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;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/mg105/interface_adapters/WinDisplay.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.mg105.interface_adapters;

import com.mg105.use_cases.map.RoomGetterInterface;
import com.mg105.use_cases.ReplayGenerator;
import com.mg105.use_cases.RoomGetter;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

Expand All @@ -11,7 +10,7 @@
*/
public class WinDisplay implements PropertyChangeListener {
private final Toggler toggler;
private final RoomGetter roomGetter;
private final RoomGetterInterface roomGetter;
private final ReplayGenerator replayGenerator;

/**
Expand All @@ -21,7 +20,7 @@ public class WinDisplay implements PropertyChangeListener {
* @param roomGetter gets the current room of the player
* @param replayGenerator generates a replay
*/
public WinDisplay(Toggler toggler, RoomGetter roomGetter, ReplayGenerator replayGenerator) {
public WinDisplay(Toggler toggler, RoomGetterInterface roomGetter, ReplayGenerator replayGenerator) {
this.toggler = toggler;
this.roomGetter = roomGetter;
this.replayGenerator = replayGenerator;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.mg105.interface_adapters;
package com.mg105.interface_adapters.map;

import com.mg105.use_cases.MapGenerator;
import com.mg105.use_cases.map.MapGeneratorInterface;
import org.jetbrains.annotations.NotNull;

/**
* 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 {
private final @NotNull MapGenerator generator;
public class MapGeneratorInterpreter implements MapGeneratorInterpreterInterface {
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;
}

/**
* Generate (or re-generate) the map.
*/
@Override
public void generateMap() {
generator.generateMap();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mg105.interface_adapters.map;

/**
* An interface for map generation.
*/
public interface MapGeneratorInterpreterInterface {
/**
* Generate the map.
*/
void generateMap();
}
Original file line number Diff line number Diff line change
@@ -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.RoomGetterInterface;
import com.mg105.use_cases.outputds.RoomLayout;
import com.mg105.utils.MapConstants;
import com.mg105.utils.PointComparator;
Expand All @@ -15,19 +15,19 @@
/**
* The MinimapInterpreter processes room change data an interprets its implicit position.
*/
public class MinimapInterpreter implements PropertyChangeListener, Resetable {
private final @NotNull RoomGetter getter;
public class MinimapInterpreter implements PropertyChangeListener, Resetable, MinimapInterpreterInterface {
private final @NotNull RoomGetterInterface getter;

private @Nullable Point lastPosition;
private @NotNull RoomState[][] mapSoFar;
private @NotNull MinimapRoomState[][] mapSoFar;
private final @NotNull Point currentRoom;

/**
* Create a new MinimapInterpreter.
*
* @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();

Expand All @@ -40,8 +40,8 @@ public MinimapInterpreter(@NotNull RoomGetter 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;
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
}
}
Expand All @@ -103,7 +103,8 @@ public void propertyChange(PropertyChangeEvent evt) {
*
* @return the currently explored map.
*/
public @NotNull RoomState[][] getMapSoFar() {
@Override
public @NotNull MinimapRoomState[][] getMapSoFar() {
return mapSoFar;
}

Expand All @@ -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);
}
Expand All @@ -128,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;
Expand All @@ -142,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;
Expand All @@ -162,16 +164,4 @@ private void autoBumpMapSoFarBecauseOf(@NotNull Point next, @NotNull Point... to
mapSoFar = nextMap;
}
}

/**
* Possible knowledge states of a room.
* <p>
* 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
}
}
Loading

0 comments on commit c20640a

Please sign in to comment.