Skip to content

Inventory Code (Team 6)

katherinegray97 edited this page Sep 23, 2017 · 2 revisions

What it Does

An inventory is a TreeMap of resources mapped to their quantities. Inventories are used in many areas in the game, for example each player has an inventory representing all of the items they are able to collect and have collected in the game. Inventories may be used to also hold the items that a resource tree has available to harvest or an enemy squirrel has to drop when killed.

How it does it

The inventory class has broad functionality to enable integration with other features. Methods include:

  • getInventoryResources() - returns the set of resources stored
  • addInventoryResource() - adds a resource to the inventory
  • removeInventoryResource() - removes a resource to the inventory
  • getMap() - returns the mapping of resources stored and the quantity of each
  • getQuantity(Resource resource) - returns the mapped quantity of a given resource
  • updateQuantity(Resource resource, int amount) - adds amount to the current quantity of a given resource and updates the inventory GUI
  • updateInventory(Inventory extraItems) - adds an entire inventory of items to the current inventory
  • toString() - returns a String representation of the inventory

How it integrates with other features

GUI

At any time the inventory count is displayed in the top right-hand corner of the screen. This visual representation shows a list of images representing the resources the player has collected and, to the right of each image, the number of resources a player has already collected.

Resource Collection/Removal

It is obviously vital that the inventory class integrates with the game's resources. A player may collect any resources that they find in the various worlds. Each world has three native resources which can be collected to plant the trees native to that world. As soon as a player first picks up one of these items, it will be added to their inventory.

Items are used to plant trees which will help the player. To plant a tree, a player must click on a surrounding tile and make their tree selection. If they do not have enough resources or they are attempting to plant a tree too far away, they will not be able to make the purchase.

Examples of Usage

Currently, when gameplay starts the player is initialised with an inventory count of 0 for the three resources in the first world level. This is done using the following code:

/** * Initialises the inventory with all the resources in the game. */ private void addResources() { HashSet<Resource> startingResources = new HashSet<Resource>(); this.inventory = new Inventory(startingResources); }

Havesting resources from trees for example is then done by calling:

otherInventory.updateInventory(this.getInventory()); where otherInventory is the inventory of the player and this.getInventory() is the inventory of the tree.


Gameplay

Design

Asset Creation

User Testing

Code Guidelines


http://cultofthepartyparrot.com/parrots/partyparrot.gifhttp://cultofthepartyparrot.com/parrots/partyparrot.gifhttp://cultofthepartyparrot.com/parrots/partyparrot.gifhttp://cultofthepartyparrot.com/parrots/partyparrot.gifhttp://cultofthepartyparrot.com/parrots/partyparrot.gif

Clone this wiki locally