ResourceSpecification - UQdeco2800/2022-studio-3 GitHub Wiki

Introduction

As resources in the game are procedurally generated, it was important to provide a prospective developer with tools to both add resources or modify the qualities of them. ResourceSpecification is a medium to do so, as it contains all the information required to procedurally generate a resource on the island, as well as all of a Resource's placements (allocated by Resource Generator).

The variables a developer may control when adding or modifying resources in the game are outlined in Adding Resources to the game and coincide with the fields necessary to initialise a ResourceSpecification.

Function

When created, provide a ResourceSpecification with variables : Resource width, resource height, preferred distance from city, name, max amount, min amount. This will create a new ResourceSpecification, holding this data, alongside an integer amount, which is the amount to add to the game - randomly chosen between the ranges min and max amount. ResourceGenerator automatically fills the placement list of each ResourceSpecification, so only this function is necessary to understand when adding resources to the game, as it will provide the tile location to spawn an entity at using a Resource Factory

A ResourceSpecification's getPlacements() function will return a list of Coordinate, corresponding to tiles on the map where this resource is to be placed.

Test Plan

Given the concise nature of the class, it was deemed sufficient to only run unit tests on it, to verify its limited functionality was correct.

The unit tests verify the following:

  1. A ResourceSpecification will throw an exception if initialised with bad data (i.e. the size of a resource is provided as negative, or the minAmount to generate is greater than the maxAmount, etc...)
  2. A ResourceSpecification correctly chooses an amount to place between maxAmount and minAmount
  3. A ResourceSpecification correctly returns all associated variables using getter methods
  4. A ResourceSpecification's placement data can be set and cleared using the associated functions