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 #77 from CSC207-2022F-UofT/features/InventorySaveMisc
Browse files Browse the repository at this point in the history
Added Inventory to Input Listener and Scene Controller, did battle end, and misc (tests, java doc, etc)
  • Loading branch information
siddharthgowda authored Dec 4, 2022
2 parents 46c0da3 + 9cc5e82 commit c56bf4e
Show file tree
Hide file tree
Showing 46 changed files with 446 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ gradle-app.setting
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

# CSV files
.csv
26 changes: 17 additions & 9 deletions src/main/java/com/mg105/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
import com.mg105.interface_adapters.inventory.InventoryPresenter;
import com.mg105.use_cases.*;
import com.mg105.use_cases.inventory.InventoryInteractor;
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 com.mg105.user_interface.inventory.InventoryDisplay;
import com.mg105.user_interface.InventoryDisplay;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
import java.awt.*;
Expand Down Expand Up @@ -52,13 +55,6 @@ public void start(Stage primaryStage) {
GameStateSetter setter = new GameStateSetter(partyCreator);
setter.setState(state);

// InventoryDisplay set up
InventoryPresenter inventoryPresenter = new InventoryPresenter();
InventoryInteractor inventoryInteractor = new InventoryInteractor(state, inventoryPresenter);
InventoryDisplay inventoryDisplay = new InventoryDisplay(new InventoryController(
inventoryInteractor));
inventoryPresenter.setView(inventoryDisplay);

Map<Toggler.ToggleableComponent, Toggleable> drawableComponents = new HashMap<>();
// We fill this map in later because of the ordering of parameters
SceneController sceneController = new SceneController(
Expand All @@ -77,6 +73,14 @@ public void start(Stage primaryStage) {
drawableComponents.put(Toggler.ToggleableComponent.MAIN_MENU, mainMenu);
drawableComponents.put(Toggler.ToggleableComponent.MAP, mapDrawer);

// InventoryDisplay set up
InventoryPresenter inventoryPresenter = new InventoryPresenter();
InventoryInteractor inventoryInteractor = new InventoryInteractor(state, inventoryPresenter);
InventoryDisplay inventoryDisplay = new InventoryDisplay(new InventoryController(
inventoryInteractor));
inventoryPresenter.setView(inventoryDisplay);
drawableComponents.put(Toggler.ToggleableComponent.INVENTORY, inventoryDisplay);

/////Tutorial scene////
TutorialTextController textChanger = new TutorialTextController(false);
TutorialTextDisplay textDisplay = new TutorialTextDisplay();
Expand All @@ -95,8 +99,12 @@ public void start(Stage primaryStage) {
//OpponentSet setup
OpponentSetInteractor opponentInteractor = new OpponentSetInteractor(state);

// Creating Saver
Save[] savers = {new PartySaver(state, new PartyDataAccess(new MoveDataAccess()))};
Saver saver = new Saver(savers);

//Battle setup
BattleInteractor battleInteractor = new BattleInteractor(state);
BattleInteractor battleInteractor = new BattleInteractor(state, inventoryInteractor, saver);
BattlePresenter battlePresenter = new BattlePresenter(battleInteractor);
BattleMenu battleMenu = new BattleMenu(battlePresenter);
drawableComponents.put(Toggler.ToggleableComponent.BATTLE, battleMenu);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mg105.data_control.access;

import com.mg105.outputds.MoveDetails;
import com.mg105.use_cases.outputds.MoveDetails;
import com.opencsv.CSVParser;
import com.opencsv.CSVParserBuilder;
import com.opencsv.CSVReader;
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/com/mg105/data_control/access/PartyDataAccess.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mg105.data_control.access;

import com.mg105.outputds.BattleCharacterDetails;
import com.mg105.outputds.MoveDetails;
import com.mg105.use_cases.outputds.BattleCharacterDetails;
import com.mg105.use_cases.outputds.MoveDetails;
import com.mg105.use_cases.save.PartyDataInterface;
import com.mg105.utils.PartyConstants;
import com.mg105.utils.StatConstants;
Expand All @@ -21,12 +21,6 @@ public class PartyDataAccess implements PartyDataInterface {
private final static int NUMBER_OF_MOVES_PER_CHARACTER = 2;
private final MoveDataAccess moveDataAccess;

public static void main(String[] args){
PartyDataAccess p = new PartyDataAccess(new MoveDataAccess());

System.out.println(p.getPartyBattleDetails()[0].getName());
}


public PartyDataAccess(MoveDataAccess moveDataAccess) {
// Could define a new moveDataAccess here but it is passed in to follow dependency inversion
Expand Down Expand Up @@ -56,7 +50,6 @@ public void changeCharacterStat(@NotNull String name, @NotNull String stat, int
for (String[] memberStats : partyStats) {
if (memberStats[0].equals(name)) {
int i = getColumnNumber(stat);
System.out.println(i);
if (i == -1) {
// Occurs when an invalid stat argument is passed
reader.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

public abstract class DataStorageCreator implements CreateDataStorage {

private final String path;
@NotNull private final String path;

private final String[][] initialData;
@NotNull private final String[][] initialData;

public DataStorageCreator(@NotNull String path, @NotNull String[][] initialData){
this.path = path;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/mg105/entities/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ public void setCurrEncounter(Battle currEncounter) {
this.currEncounter = currEncounter;
}

/**
* Removes the current active battle from the game state.
*/

public void removeCurrEncounter(){
this.currEncounter = null;
}


/**
* Returns an ArrayList of the player's characters.
*
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/mg105/entities/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
*/

public abstract class Item {
final private String NAME;
final private String DESCRIPTION;
@NotNull final private String NAME;

public Item(@NotNull String name, @NotNull String description) {
/**
* Creates a new instance of item
* @param name the name of the item
*/
public Item(@NotNull String name) {

this.NAME = name;
this.DESCRIPTION = description;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/mg105/entities/items/HealthPotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public class HealthPotion extends Item implements Consumable {

private final static int HEALING_POINTS = 25;

/**
* Creates a new instance of health potion
*/
public HealthPotion() {
super(ItemConstants.HEALTH_POTION_NAME, ItemConstants.HEALTH_POTION_DESCRIPTION);
super(ItemConstants.HEALTH_POTION_NAME);
}

public static int getHealingPoints() {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/mg105/entities/items/MegaPotion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public class MegaPotion extends Item implements Consumable {

private final static int HEALING_POINTS = 40;

/**
* Creates a new instance of mega potion
*/
public MegaPotion() {
super(ItemConstants.MEGA_POTION_NAME, ItemConstants.MEGA_POTION_DESCRIPTION);
super(ItemConstants.MEGA_POTION_NAME);
}

public static int getHealingPoints() {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/mg105/entities/items/UpgradeToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
*/
public class UpgradeToken extends Item implements Consumable {

/**
* Creates a new instance of upgrade token
*/
public UpgradeToken() {
super(ItemConstants.UPGRADE_TOKEN_NAME, ItemConstants.UPGRADE_TOKEN_DESCRIPTION);
super(ItemConstants.UPGRADE_TOKEN_NAME);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public InputInterpreter(@NotNull CharacterMover mover, @NotNull Toggler toggler,
this.toggler = toggler;
this.textChanger = textChanger;
this.opponentInteractor = opponentInteractor;
this.chestInteractor = chestInteractor;
}
this.chestInteractor = chestInteractor;}

/**
* Interpret key being pressed as an action.
Expand Down Expand Up @@ -108,6 +107,12 @@ public void interpret(String key) {
toggler.toggle(Toggler.ToggleableComponent.WALK_MENU);
}
}

case INVENTORY -> {
if(key.equals("i")){
toggler.toggle(Toggler.ToggleableComponent.INVENTORY);
}
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mg105.interface_adapters;

import com.mg105.use_cases.RoomGetter;
import com.mg105.use_cases.RoomLayout;
import com.mg105.use_cases.outputds.RoomLayout;
import com.mg105.utils.MapConstants;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package com.mg105.interface_adapters.inventory;

import com.mg105.use_cases.inventory.InventoryInteractor;
import org.jetbrains.annotations.NotNull;

/**
* A class that serves the UI and allows users to make the desired changes to the Inventory
*/

public class InventoryController {

InventoryInteractor interactor;
@NotNull private final InventoryInteractor interactor;

public InventoryController(InventoryInteractor interactor) {

/**
* Creates a new instance of inventory controller
* @param interactor an object that interacts directly with the inventory
*/

public InventoryController(@NotNull InventoryInteractor interactor) {
this.interactor = interactor;
}

Expand All @@ -22,7 +29,7 @@ public InventoryController(InventoryInteractor interactor) {
* @see InventoryInteractor
*/

public void removeItem(String itemName) {
public void removeItem(@NotNull String itemName) {
interactor.removeItem(itemName);
}

Expand All @@ -34,7 +41,7 @@ public void removeItem(String itemName) {
* @param characterName the character to use the item on
* @see InventoryInteractor
*/
public void useItem(String itemName, String characterName) {
public void useItem(@NotNull String itemName, @NotNull String characterName) {
interactor.useItem(itemName, characterName);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mg105.interface_adapters.inventory;

import com.mg105.outputds.ItemDetails;
import com.mg105.use_cases.outputds.ItemDetails;
import com.mg105.use_cases.inventory.InventoryPresenterInterface;
import org.jetbrains.annotations.NotNull;

Expand All @@ -17,7 +17,7 @@ public class InventoryPresenter implements InventoryPresenterInterface {
* Sets the view of the of this presenter
* This should be called right after the presenter is created
*
* @param view
* @param view an object that is used to display information to the user
*/
public void setView(@NotNull InventoryViewInterface view) {
this.display = view;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mg105.interface_adapters.inventory;

import com.mg105.user_interface.Alert;
import com.mg105.user_interface.Alert.Alert;

/**
* The interface defines all the functions that should be called to update the ui to add or
Expand Down
Loading

0 comments on commit c56bf4e

Please sign in to comment.