Skip to content

Commit

Permalink
Merge pull request #101 from tannerlie/branch-simplify-inventory
Browse files Browse the repository at this point in the history
Simplify player inventory
  • Loading branch information
tannerlie committed Apr 11, 2024
2 parents d8bb938 + 8564bd9 commit a0e2b03
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 287 deletions.
98 changes: 77 additions & 21 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,36 @@

{list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the original source as well}

## Design & implementation
## Design

### Architecture

Given below is a higher-level overview of the main components for the app to work.

```Main``` has methods which are responsible for:
1. App launch: Initialises the various classes needed and starting up the game
2. App running: Calls the various methods in other Classes to run the game
3. App shutdown: Saves the game state

listed below are a collection of classes used by multiple components which will be generalised as ```Commons```.
1. ```TextBox``` which is used to set all the messages and narrations for the user.
2. ```FileReader``` to read our design.txt files in order to print certain screens.
3. ```PlayerStatus``` which stores the status and inventory of the player.

```Ui``` responsible for displaying the game's UI, interactions and narrations to the user.<br>
```Storage``` responsible for saving the current state of the game when quitting the app.<br>
```Parser``` is a collection of classes that converts the user's commands and starts the command execution process. <br>
<br>
Below is how some of the architecture components would interact with each other when the user inputs the command to move.
![architecture_sequence_diagram](../picture/ArchitectureSequenceDiagram.png)
The section below gives more details of each component.
### UI Component

# UserCommand feature
### Parser

## Implementation

### User Command Component

User can type command to do things on the Map.

Expand All @@ -20,8 +43,6 @@ Command back to the main based on the command type. The Final step is to call th
is the type of `fightCommand`, we will call the execute function with one parameter `Scanner`. For all other
conditions, we will call the execute function with no parameter.

![dummy test](https://raw.githubusercontent.com/AY2324S2-CS2113-W12-3/tp/67ccf80caff928cb70c37b213cf55248b909e02b/picture/Command.svg)

### Map Component

The API of this component is defined in BaseMap.java.
Expand All @@ -41,21 +62,15 @@ At the moment the `MapGenerator` class allows the positions of enemies to be pla
The reason why the player's map(FirstMap), the shop's interface and the battle interface all extend off of the `BaseMap`
class is because during the game loop, these maps are being cycled through as the main screen the user will view.




{Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.}

### Interacting with Environment Component

The API of this component is defined in InteractingCommand.java

![Interaction UML](https://raw.githubusercontent.com/AY2324S2-CS2113-W12-3/tp/master/picture/Interaction.png)

This component happens when the user chooses to key the interact command. <br>
This component happens when the user chooses to key the interact command ```e```. <br>
Here is how it works:
1. When the command is passed by the user, the ```CalculaChroniclesOfTheAlgorithmicKingdom``` object calls the ```Parser``` object
to parse the command to call the respective commands. Here, the ```InteractingCommand``` object is created.
1. When the user chooses to fight, the command is parsed.
2. The ```CalculaChroniclesOfTheAlgorithmicKingdom``` component then calls the execute() method in ```InteractingCommand```.
3. It executes the method and creates other objects like ```Enemy``` and ```ShopKeaper``` components which are responsible for the
entity classes in the game and also ```BattleInterface``` and ```ShopMap``` which are responsible for displaying these entities among other things.
Expand All @@ -69,10 +84,10 @@ The API of this component is defined in FightCommand.java.

![BattleInterface UML](https://raw.githubusercontent.com/AY2324S2-CS2113-W12-3/tp/master/picture/BattleInterface.png)

This component happens when the user chooses to fight an enemy. <br>
This component occurs when the user chooses to fight an enemy after interacting with it using the command
```f``` or ```fight```. <br>
Here is how it works:
1. When the user chooses to fight, the ```CalculaChroniclesOfTheAlgorithmicKingdom``` object calls the ```Parser``` object
to parse the command to call the respective commands. Here, the ```FightCommand``` object is created.
1. When the user chooses to fight, the command is parsed.
2. The ```CalculaChroniclesOfTheAlgorithmicKingdom``` object then calls the execute() method in ```FightCommand``` and enables the fighting.
3. The ```MathPool``` object is created, which is responsible for the math questions to answer and another ```Ui``` object is created to interact with the user.
4. In the enableFight() method, it has a loop which asks the user math questions to answer until the player or enemy dies. The player takes damage for
Expand All @@ -82,21 +97,62 @@ until the user gives an answer which is a valid integer.
6. Once either the player or enemy dies, it then exits and runs the relevant checks to eventually print the output to be shown to
the user after battle, handled by ```CalculaChroniclesOfTheAlgorithmicKingdom```.

### Item Usage Component

The API of the following component is defined in OpenInventoryCommand.java.
![OpenInventory_UML](../picture/OpenInventory.png)
This component occurs when the user decides to open up the inventory. The user opens up the inventory using the command ```i```
or ```inventory```.<br>
Here is how it works:
1. When the user chooses to open the inventory, the command is parsed.
2. The ```CalculaChroniclesOfTheAlgorithmicKingdom``` object then calls the execute() method in ```OpenInventoryCommand```to get
the inventory from the stored maps in ```BaseMap```.
3. The inventory would then be printed on the Ui for display.

The API of the following component is defined in UseCommand.java.
![UseItem_UML](../picture/ItemUsage.png)
This component occurs when the user decides to use an item after navigating to the inventory page containing consumable items.
Here is how it works:
1. When the user chooses to use an item after navigating to the consumable items page, the command is parsed.
2. The ```CalculaChroniclesOfTheAlgorithmicKingdom``` object then calls the execute() method
3. The method goes through the necessary checks to check if the item intended to use has been indicated as stated in the UserGuide.
4. If any of the checks fail, an error message would be displayed to flag out what went wrong.
5. If all the checks passes, the inventory is obtained from the ```PlayerStatus``` object. The inventory is then searched to check if it
contains the item.
6. The method useItem(item) in the ```PlayerInventory``` object is called if the item is found. Subsequently,
an error message is printed outlining the error.

## Product scope
### Target user profile

{Describe the target user profile}
Our target users are young students who are hoping the revise their mathematical skills.

### Value proposition

{Describe the value proposition: what problem does it solve?}
It allows the target user to supplement their existing revision with a more fun and interacting way to revise their mathematics knowledge.

## User Stories

| Version | As a ... | I want to ... | So that I can ... |
|---------|----------|---------------------------|-------------------------------------------------------------|
| v1.0 | new user | see usage instructions | refer to them when I forget how to use the application |
| v2.0 | user | find a to-do item by name | locate a to-do without having to go through the entire list |
| Priority | As a ... | I want to ... | So that I can ... |
|----------|----------------|-------------------------------------------------------------|---------------------------------------------------------|
| *** | new player | to get access to a help menu | refer to them when I don't know the commands to proceed |
| *** | player | to see a map of the play area | see the map and location in real-time |
| *** | player | to move around at will | explore the world as I want to |
| *** | player | to have an ending to the game | win the game |
| *** | player | to be able to track stats/items | gauge how my characters progress |
| *** | player | save my game | come back and finish it when I have time |
| *** | player | To have a death and restart mechanic | add challenge to the game |
| ** | player | To be able to fight entities | battle in and interactive way |
| ** | player | To collect items | enhance my character |
| ** | player | To interact with things in the environment | be more immersed into the game |
| ** | player | See an actual image of the characters | know what I am fighting against |
| ** | student player | To have variations in the questions asked | revise more stuff rather than the same questions |
| ** | player | to have clear distinctions between entities I interact with | have a clearer picture of what I'm doing |
| ** | student player | refresh my knowledge of math | revise as I play at the same time |
| * | player | To know the background of this game | follow the storyline |
| * | player | to see funny and engaging dialogue | enjoy the story |
| * | player | To have access to hints to the questions | make calculations easier |


## Non-Functional Requirements

Expand Down
40 changes: 13 additions & 27 deletions graph/BattleInterface.puml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@startuml

box Battle Component
participant "CalculaChroniclesOfTheAlgorithmicKingdom" as main
participant ":CalculaChroniclesOfTheAlgorithmicKingdom" as main
participant ":UI" as ui
participant ":Parser" as parser
participant ":TextBox" as text
Expand All @@ -13,17 +13,17 @@ participant ":FileReader" as fileReader
participant ":Map" as map
participant ":MathPool" as mathpool

activate main
main -> parser : parseCommand(userCommandText)
activate parser
create f
parser -> f
activate f
f --> parser
deactivate f
parser --> main : command class
deactivate parser
main -> main : executeCommand()
'activate main
'main -> parser : parseCommand(userCommandText)
'activate parser
'create f
'parser -> f
'activate f
'f --> parser
'deactivate f
'parser --> main : command class
'deactivate parser
'main -> main : executeCommand()
activate main
main -> f : execute()
activate f
Expand Down Expand Up @@ -116,21 +116,7 @@ end
f --> main
deactivate f
deactivate main
main -> main : printMessageUnderMap(userCommand, ui, playerStatus, textBox)
activate main
alt not calling help menu or quitting game
alt show battle interface
main -> ui : printEnemy(currentMap)
activate ui
ui --> main
deactivate ui
else
main -> ui : printMap(currentMap)
activate ui
ui --> main
deactivate ui
end
end


end box

Expand Down
56 changes: 28 additions & 28 deletions graph/Interaction.puml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@startuml

box Battle Component
participant "CalculaChroniclesOfTheAlgorithmicKingdom" as main
participant ":CalculaChroniclesOfTheAlgorithmicKingdom" as main
participant ":UI" as ui
participant ":Parser" as parser
participant ":TextBox" as text
Expand All @@ -14,17 +14,17 @@ participant ":FileReader" as fileReader
participant ":Map" as map

activate main
main -> parser : parseCommand(userCommandText)
activate parser
create iCommand
parser -> iCommand
activate iCommand
iCommand --> parser
deactivate iCommand
parser --> main : command class
deactivate parser
main -> main : executeCommand()
activate main
'main -> parser : parseCommand(userCommandText)
'activate parser
'create iCommand
'parser -> iCommand
'activate iCommand
'iCommand --> parser
'deactivate iCommand
'parser --> main : command class
'deactivate parser
'main -> main : executeCommand()
'activate main
main -> iCommand : execute()
activate iCommand
iCommand -> map : handleInteract()
Expand Down Expand Up @@ -96,22 +96,22 @@ else is a shop
end
iCommand --> main
deactivate iCommand
deactivate main
main -> main : printMessageUnderMap(userCommand, ui, playerStatus, textBox)
activate main
alt not calling help menu or quitting game
alt show battle interface
main -> ui : printEnemy(currentMap)
activate ui
ui --> main
deactivate ui
else
main -> ui : printMap(currentMap)
activate ui
ui --> main
deactivate ui
end
end
'deactivate main
'main -> main : printMessageUnderMap(userCommand, ui, playerStatus, textBox)
'activate main
'alt not calling help menu or quitting game
' alt show battle interface
' main -> ui : printEnemy(currentMap)
' activate ui
' ui --> main
' deactivate ui
' else
' main -> ui : printMap(currentMap)
' activate ui
' ui --> main
' deactivate ui
' end
'end

end box

Expand Down
18 changes: 1 addition & 17 deletions graph/ItemUsage.puml
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,11 @@ text --> use
deactivate text
use --> main
end
opt item name was provided
use -> use : findItem(itemString)
activate use
use -> status : getPlayerInventory()
activate status

status --> use : inventory
deactivate status
alt item is in list
use -> inventory : useItem(item)
activate inventory
inventory --> use
deactivate inventory
else
opt item index was not a valid integer
use -> text : setNextError(error)
activate text
text --> use
deactivate text
deactivate use
end
use --> main
end
use -> status : getPlayerInventory()
activate status
Expand Down
Binary file modified picture/BattleInterface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified picture/Interaction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified picture/ItemUsage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions src/main/java/command/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ public enum CommandType {
INTERACT("(?i)\\h*(e)\\h*"),
QUIT("(?i)\\h*(q|quit)\\h*"),
HELP("(?i)\\h*(h|help)\\h*"),
EXIT("(?i)\\h*(exit)\\h*"), // New command: EXIT
EXIT("(?i)\\h*(exit)\\h*"),
ERROR(""),
INVENTORY("(?i)\\h*(i|inventory)\\h*"),
INV_NEXT("(?i)\\h*(n|next)\\h*"),
INV_PREV("(?i)\\h*(p|prev|previous)\\h*"),
USE_ITEM("(?i)\\h*(use)(\\h+\\d+|\\h+\\w+)?\\h*"),
SELL_ITEM("(?i)\\h*(sell)(\\h+\\d+|\\h+\\w+)?\\h*"),
CLOSE_INV("(?i)\\h*(c|close)\\h*"); // to delete aft sihan implements
CLOSE_INV("(?i)\\h*(close)\\h*");
final String regExpression;

CommandType(String regExpression) {
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/command/inventory/NextPageCommand.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/java/command/inventory/OpenInventoryCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public OpenInventoryCommand() {
@Override
public void execute() {
BaseMap.currentMap = mapIndex.get(INVENTORY_IDENTITY);
textBox.setNextNarration("Here's your inventory. Navigate the pages using [next] or [prev]");
textBox.setNextNarration("Here's your inventory! You can use an item by keying in [use] followed by it's " +
"index with a space between them.");
}
}
10 changes: 0 additions & 10 deletions src/main/java/command/inventory/PrevPageCommand.java

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/java/command/inventory/SellCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public void findItem(String item, ArrayList<Item> itemList) {
@Override
public void execute() {
PlayerInventory inventory = playerStatus.getPlayerInventory();
int listIndex = inventory.getCurrentItemPageNumber();
ArrayList<Item> list = playerStatus.getPlayerInventory().getAllItemsList().get(listIndex);
ArrayList<Item> list = playerStatus.getPlayerInventory().getGeneralItems();
if (list.isEmpty()) {
textBox.setNextError("The item does not exist");
return;
Expand Down
Loading

0 comments on commit a0e2b03

Please sign in to comment.