Skip to content

Game Model

Sintfoap edited this page Apr 7, 2022 · 18 revisions

Game

The central class of the Game Model. Manages and updates all of the entities.

Variables:

  • timer: the tick system that calls the update method every tick
  • entityList: the central list of entities
  • fileName: the filename to be loading and saving to
  • gameSpeed: the speed of the current game being played
  • score: the current score of the game
  • computer: the computer associated with this game

Methods

  • update(): iterates through the entity list and calls update on each entity object
  • stopTimer(): pauses the timer, halting the update loop and thus pausing the game
  • startTimer(): starts timer, thus starting the update loop and resuming the game
  • save(): pauses the game, and saves all of the objects in entityList to the game file
  • load(): loads the saved game from gamefile, populating entityList with the saved game's state
  • innitialize(Difficulty difficulty, String lvlName): starts a new game instance from the inputs given
  • selectTroops(Coordinate coord1, Coordinate coord2, Nationality nationality): selects troops within a certain coordiante box of a certain nationality

Computer

A class which creates methods used by the three different computer difficulties.

Variables:

  • difficulty: the difficulty stored as an enum
  • turnCount: number of ticks elapsed

Methods:

  • executeAction(Game game): looks at current state of game, and depending on what difficulty the computer is, will determine an action and execute said action

EasyComputer, MediumComputer, HardComputer

Each of these classes will extend computer and create an executeAction method that will vary depending on their difficulty level

Difficulty

An enum which represents the difficulty of a computer

Entity

The class which all game entities extend

Variables:

  • turnCount: number of ticks elapsed
  • location: the x, y coordinate pair for where the object is on the screen
  • observer: EntityObserver that is paired to an object so that an object can update the position of its image while maintaining model/view separation

Methods:

  • update(): update method which updates attributes of object
  • serialize(DataOutputStream wr): a method to package and save an
  • update(): entity

Entity Observer

Each entity will have an observer associated with it that will update the position of it's image upon being called

Coordinate

Objects that consist of x, y coordinate points

Variables:

  • x: x-position on coordinate plane
  • y: y-position on coordinate plane

Methods:

  • isEqual(Coordinate c): checks if coordinate that is passed in is equal to coordinate
  • round(double value, int places): rounds double to places number of digits

City

A structure that creates troops and deploys them

Variables:

  • population: number of troops in a city
  • incrementRate: the speed at which a city produces population
  • type: states whether city is friendly, enemy, or neutral
  • selected: boolean value that determines if a city is selected for deploying troops or not
  • fireRate: rate at which city will fire arrows to defend itself, increases over time
  • serialize(): a method to package and save an entity

Methods:

  • update(): hijacks the entity update method to update certain attributes of this
  • sendTroops(double percentage, Coordinate destination): sends troops according to the amount that the user has selected and decrements population accordingly
  • fireProjectile(): generates a projectile that will kill an oncoming enemy within a range

MobileEntity

A class that extends Entity to create moving entities

Variables:

  • speed: the speed at which the entity traverses the screen
  • heading: the angle at which the entity as in the fourth Cartesian plane
  • destination: the coordinate point that is the endpoint for the entity

Methods:

  • update(): hijacks the entity update method to update certain attributes of this

Weather

An event that happens at random and has a random effect on troops

Variables:

  • type: the type of weather

Methods:

  • update(): hijacks the entity update method to update certain attributes of this
  • serialize(): a method to package and save an entity

WeatherType

An enum representing the various types of possible weathers

Projectile

Damaging projectiles sent out of cities to kill troops

Variables:

  • damage: the damage of an projectile, typically set to one

Methods:

  • collisionDetection(): triggers when the projectile collides with a troop of the opposite nation
  • update(): hijacks the entity update method to update certain attributes of this
  • serialize(): a method to package and save an entity

Troop

Units which are sent to attack enemy cities and defend friendly cities

Variables:

  • health: amount of damage that the troop can take
  • nationality: the side that this troop is on
  • selected: boolean value depicting if unit is in selected or not

Methods:

  • update(): hijacks the entity update method to update certain attributes of this
  • serialize(): a method to package and save an entity
  • collisionDetection(): checks if troop has collided with either another troop of the opposite nationality
Clone this wiki locally