Skip to content

Game Model

Tripp312 edited this page Apr 12, 2022 · 29 revisions

World

The singleton that holds all levels in the game model and updates all entities within. One of two central classes in the game model.

Variables:

  • campaign: holds all levels to be played
  • currentLevel: index of the current level in the campaign
  • difficulty: integer equivalent of the selected difficulty
  • world: private static variable of the world
  • observer: Screenobserver used to update the view on every timer tick

Methods:

  • reset(): creates a new instance of world
  • instance(): calls the current instance of world
  • World(): constructor
  • passLevel(): increases currentLevel by one and moves the player accordingly
  • getCurrentEntities(): obtains all entities on the current screen
  • getCurrentLevel(): returns currentLevel in the campaign
  • getPlayer(): returns the current instance of player
  • populate(): creates the base gameState without the level builder
  • updater(): contains the timer that prompts all movement in the game
  • update(): called by updater, calls all on-screen entities' performMovement() method
  • save(): saves the current state of the game
  • load(): loads the saved state of the game

Level

The other central class of the game model. Displays all the player will interact with, class that View is most entwined with.

Variables:

  • screens: this holds an arraylist of screens which the player travels between.
  • totalEnemies: holds an arraylist of enemies within each level
  • currentScreen: screen that the player currently inhabits
  • currentRow: row of the currentScreen in the imaginary Array[][] of screens
  • currentCol: column of the currentScreen in the imaginary Array[][] of screens
  • currentLevel: level that the player is on
  • observer: ScreenObserver used to update the View whenever player enters a new screen
  • rand: Random object used to generate screen obstacles

Methods:

  • Level(): Level constructor
  • setObserver(): sets the passed ScreenObserver to the observer variable
  • findScreen(): finds the screen with the given row and column parameters
  • placeEntity(): places the entity in the screen with the given row, column
  • goLeft(): sets the currentScreen to the one to its left, updates View
  • goRight(): sets the currentScreen to the one to its right, updates View
  • goUp(): sets the currentScreen to the one above, updates View
  • goDown(): sets the currentScreen to the one below, updates View
  • getScreens(): returns screens
  • setScreens(): sets screens to passed parameter
  • addScreen(): adds the param screen to screens
  • getCurrentRow(): returns currentRow
  • setCurrentRow(): sets currentRow to the passed param
  • getCurrentCol(): returns currentCol
  • setCurrentCol(): sets currentCol to the passed param
  • getCurrentScreen(): returns currentScreen

Screen

The object containing all that is displayed to the View at any given time

Variables:

  • grid: the Array[][] of cells in each screen that tells whether an obstacle, enemy, player, or nothing is there
  • entities: tells which entities inhabit the screen at any given time
  • location: gives the screen's location within the world and its level (row, column, level)
  • left: screen immediately to the screen's left
  • right: screen immediately to the screen's right
  • up: screen immediately above the screen
  • down: screen immediately below the screen
  • rand: Random object to populate the grid with obstacles

Methods:

  • Screen(): constructor for the screen
  • getLeft(): returns left
  • getRight(): returns right
  • getUp(): returns up
  • getDown(): returns down
  • getLocation(): returns location
  • randomize(): randomly places obstacles in the screen
  • addEnemyGroup(): adds an entire group of enemies to entities
  • addEntity(): adds a single entity to entities
  • findObstacles(): returns all obstacles in the screen
  • removePlayer(): removes the player from the current screen, returns the player that was removed

Location

Gives the unique ID of each screen in each level

Variables:

  • row: row in the imaginary Array[][] of screens in each level
  • col: column in the imaginary Array[][] of screens in each level
  • level: home level of each screen

Methods:

  • Location(): constructor for Location
  • getRow(): returns row
  • setRow(): sets row to the passed param
  • getCol(): returns col
  • setCol(): sets col to the passed param
  • getLevel(): returns level
  • setLevel(): sets level to the passed param

ScreenObserver

Observer to update the View in the case of a change to the model

Methods:

  • Initialize(): Method inside the view to be indirectly executed my the model

Cell

Used by model to represent hitboxes for attacking and collisions

Enums:

  • empty: nothing occupies this cell
  • rock: a rock occupies this cell
  • tree: a tree occupies this cell
  • plant: a plant occupies this cell
  • enemy: an enemy occupies this cell

Direction

Used by enemies to represent where they face in pathfinding

enums:

  • up: object faces up
  • down: object faces down
  • right: object faces right
  • left: object faces left

Obstacle

used by View to display obstacles from the model to itself

Variables:

  • row: row location in the screen's grid
  • col: column location in the screen's grid
  • type: Cell type of the cell

Methods:

  • Obstacle(): constructor of obstacle
  • getX(): returns X interpretation of col
  • getY(): returns Y interpretation of row
  • getImage(): returns Image interpretation of type

Coordinates

  • Utilized by all entities to represent their location within their home screen

Properties:

  • xCoord: property that represents the entity's x location within its screen
  • yCoord: property that represents teh entity's y location within its screen

Methods:

  • Coordinates(): constructor of Coordinates
  • randomCoordinates(): randomizes the creation of coordinates
  • getXCoord(): returns the integer value of the property xCoord
  • getYCoord(): returns the integer value of the property yCoord
  • setxCoord(): sets the integer value of the property xCoord to the passed param
  • setyCoord(): sets the integer value of the property yCoord to the passed param
  • addXCoord(): adds the passed param to the integer value of the xCoord
  • subXCoord(): subtracts the passed param to the integer value of the xCoord
  • addYCoord(): adds the passed param to the integer value of the yCoord
  • subYCoord(): subtracts the passed param to the integer value of the yCoord
  • getXProperty(): returns xCoord
  • getYProperty(): returns yCoord

Entity

Overarching ancestor class of all that populates the World, its levels, and their screens

Variables:

  • image: View representation of the model object
  • coordinates: represents the x and y coordinates of the entity

Methods:

  • Entity(): constructor for the entity
  • performMovement(): moves every entity according to its own Overriding method
  • getX(): returns integer value of xCoord in coordinates
  • getY(): returns integer value of yCoord in coordinates
  • getXProperty(): returns xCoord in coordinates
  • getYProperty(): returns yCoord in coordinates
  • getImage(): returns image

Enemy

Collection of all entities that oppose the player throughout the game; inherits from entity

Variables:

  • homeScreen: screen an enemy currently inhabits
  • cellWithin: cell an enemy currently inhabits
  • size: determines the speed, strength, and health of each enemy
  • sides: determines which polygon each enemy will be
  • vision: how far each enemy can see
  • stats: speed, strength, and health of each enemy
  • type: what each enemy is
  • direction: where the enemy is currently facing
  • weapon: what weapon the enemy wields

Methods:

  • Enemy(): constructor for enemy
  • PlayerInVision(): checks if the player is within the distance vision
  • generateEnemy(): creates an enemy based on the supplied size and sides parameters
  • cellWithin(): checks which cell the enemy is currently within
  • performMovement(): unique method of movement called on all entities, state machine that utilizes enemyState
  • complexMovement(): occurs if the enemy is in "charging mode"
  • obstacleInPath(): checks if the enemy is about to run into an obstacle
  • changeDirection(): changes the direction of the enemy based on its position relative to the player whenever the enemy leaves a cell

Triangle

Most basic enemy, wields a spear; inherits from enemy

Constants:

  • weapon: triangle weapon, a spear

Methods:

  • Triangle(): constructor for triangle
  • sizeToStats(): converts supplied size parameter to stats
  • performAttack(): executes performAttack() on the weapon it wields

Square

Second most basic enemy, wields a mace; inherits from enemy

Constants:

  • weapon: square weapon, a mace

Methods:

  • Square(): constructor for square
  • sizeToStats(): converts supplied size parameter to stats
  • performAttack(): executes performAttack() on the weapon it wields

Hexagon

Least basic enemy, wields a magic staff; inherits from enemy

Constants:

  • weapon: hexagon weapon, a magic staff

Methods:

  • Hexagon(): constructor for hexagon
  • sizeToStats(): converts supplied size parameter to stats
  • performAttack(): executes performAttack() on the weapon it wields

Octagon

Second least basic enemy, wields a battle axe; inherits from enemy

Constants:

  • weapon: octagon weapon, a battel axe

Methods:

  • Octagon(): constructor for Octagon
  • sizeToStats(): converts supplied size parameter to stats
  • performAttack(): executes performAttack() on the weapon it wields

Projectile

Moves in a straight line along a specified range at a specified speed. Carries damage from a ranged weapon to its target; inherits from entity

Variables:

  • damage: how much health the projectile decrements upon impact with a hitable entity
  • speed: how quickly the projectile moves through its range
  • range: how far the projectile will move
  • width: how wide the margin of error is for damage occurring within an entity's hitbox
  • direction: where the projectile was aimed upon its creation

Methods:

  • Projectile(): constructor for the projectile
  • performMovement(): moves in a straight line along its direction at the specified speed, until its range is decremented to 0 or it impacts an entity
  • checkIfHit(): checks if the projectile is inside a hittable entity's hitbox

Swing

Moves in a curved path along a specified radius at a specified speed. Carries damage from a melee weapon to its target; inherits from entity

Variables:

  • damage: how much health the swing decrements upon impact with a hittable entity
  • speed: how quickly the swing moves through its arc
  • radius: how for out the swing slices
  • arc: how many degrees/radians the swing moves through

Methods:

  • Swing(): constructor for the swing
  • performMovement(): moves along a curved path at its specified radius at a specified speed, until the arc is completed
  • checkIfHit(): checks if the swing is inside a hittable entity's hitbox

Player

The main character which the user manipulates throughout the game and keyboard inputs; inherits from entity

Variables:

  • inventory: array of all items the player holds
  • equipedItem: single selected item the player has
  • armor: whatever armor the player has selected to wear
  • stats: the speed, strength, and health of the player
  • playerImage: image of the player displayed to the View
  • keys: arraylist of all keys currently pressed

Methods:

  • Player(): constructor of the player
  • addKey(): adds a key to keys
  • removeKey(): removes a key from the keys
  • getKeysSize(): returns the number of keys in keys
  • performMovement(): overriden method of entity, calls keyPressed() if keys.size() > 0
  • keyPressed(): uses keys to control player movement
  • CheckifOutOfBounds(): checks if the player has gone off screen, to call the next screen
  • performAttack(): called whenever the mouse is clicked, calls the performAttack() method of whatever item the player holds

PlayerRelation

Used by all enemies to determine where they are in relation to the player on the current screen

Variables:

  • xDifference: difference between the enemy's xCoord and the player's
  • yDifference: difference between teh enemy's yCoord and the player's
  • distance: actual distance between the enemy and the player
  • player: which player object the PlayerRelation object references

Methods:

  • PlayerRelation(): constructor of the PlayerRelation

Clone this wiki locally