Skip to content

Inventory and Hotbar

PRATUL WADHWA edited this page Sep 12, 2024 · 3 revisions

Inventory

Overview

The Inventory class and InventoryInterface manage a player's item collection in the game. They handle adding, removing, and using items, as well as checking inventory status. In future this InventoryInterface can be generalised to model all containers (e.g. chests etc.) in the game and the current Inventory class can be abstracted as a base class for all containers (ie useItem would be moved to a concrete subclass, since a general container would not support this functionality).

Next, the PlayerInventoryDisplay handles the UI for the items. This is what users can interact with during game play. The display can be toggled on or off by pressing E. Items can be used from the inventory by clicking them (currently just removes item with no effect on game), and items can be picked up from the game via button press P.

Class locations

Package: com.csse3200.game.inventory Package: com/csse3200/game/components/player/PlayerInventoryDisplay.java

Inventory Interface

Methods:

  • int getCapacity(): Returns the total capacity of the inventory.
  • int numFreeSlots(): Returns the number of free slots.
  • boolean isFull(): Checks if the inventory is full.
  • boolean hasItem(int itemCode): Checks if an item with the specified code is in the inventory.
  • int getIndex(int itemCode): Retrieves the index of an item with the specified code.
  • AbstractItem getAt(int index): Retrieves the item at the specified index.
  • void deleteItem(int itemCode): Deletes an item with the specified code.
  • void deleteItemAt(int index): Deletes the item at the specified index.
  • void clearInventory(): Clears all items from the inventory.
  • void useItem(int itemCode, ItemUsageContext context): Uses an item with the specified code.
  • void useItemAt(int index, ItemUsageContext context): Uses the item at the specified index.
  • void sortByName(): Sorts the inventory by item name.
  • void sortByCode(): Sorts the inventory by item code.
  • void add(AbstractItem item): Adds an item to the inventory.
  • void addAt(int index, AbstractItem item): Adds an item to a specific index in the inventory.

Package: com.csse3200.game.inventory

The Inventory class implements InventoryInterface, providing the core functionality for managing items within the player's inventory.

The test plan for inventory is detailed in Item and Inventory Test Plan

Inventory Hotbar:

it is shortcut to first 5 items in inventory and is supposed to help the player in quick selection of items thoughout gameplay. It is executed in player inventory display and had access the inventory class passed as an arguement.

PLayerInventoryHotbarDisplay is the only class for Inventory Hotbar's functioning. It displays the hotbar to the main game screen and toggle is required to remove it when main inventory is opened. the UML for this class

Class locations

Package: com/csse3200/game/components/player/PlayerInventoryHotbarDisplay.java

Sequence Diagram

image

Clone this wiki locally