Skip to content

Game Model

PaulAlger05 edited this page Apr 13, 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
  • isPaused: boolean value to indicate whether the game is paused
  • cheatMode: boolean value to indicate whether cheat mode is on

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
  • obstacle: an obstacle inhabits 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

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

DroppedItem

Counterpart of item class distributed within the screens, level, world, and shown on the View; inherits from entity

Variables:

  • unDroppedItem: item counterpart of DroppedItem

Methods:

  • pickUp(): appends the chosen item to the player's inventory, and removes it from the World

Item

Useable functions within the gamespace utilized by enemies and players

Variable:

  • name: string representation of the item
  • cooldown: how long before it can be used again

Methods:

  • Item(): constructor for the item
  • performAction(): performs an item's designated function

UseableItem

Items which are used by the player, but contain a duration, essentially powerups; inherits from Item

Variables:

  • useCount: integer which tells how many uses an item has
  • duration: integer which tells how long its buffs last
  • buffs: boost the user's strength, health, speed in some linear combination for some length of time

Methods:

  • UseableItem(): constructor for UseableItem
  • performAction(): activates the item's effects, begins a timer until the effects end, decrements the item's useCount by one, if it reaches 0 deletes the item

Equipment

Class of items which have more permanent effects; inherits from Item

Variables:

  • type: which EquipentType the equipment is
  • buffs: how the equipment affects the bearing entity's strenght, speed, health

Methods:

  • Equipment(): constructor for the equipment
  • applyBuffs(): applies the status boosts to whichever entity bears the equipment
  • performAction(): deals damage according to the descendant equipment's Overriding method

EquipmentType

what descendant class each equipment falls into

Enums:

  • ARMOR
  • MELEE_WEAPON
  • RANGED_WEAPON

Armor

Class of equipment worn by entities for its buffs; inherits from Equipment

Methods:

  • Armor(): constructor for armor

MeleeWeapon

Class of equipment used as a Player's or Enemy's selected item to deal damage to others through swinging; inherits from Equipment

Variables:

  • range: how long the radius of the created swing is

Methods:

  • MeleeWeapon(): constructor of the melee weapon
  • performAction(): creates a swing object at the coordinates of the performing entity with inherent damage

RangedWeapon

Class of equipment used as a Player's or Enemy's selected item to deal damage to others through projectiles; inherits from Equipment

Variables:

  • range: how far the created projectile will go
  • projectileType: which projectile the weapon creates

Methods:

  • RangedWeapon(): constructor for the ranged weapon
  • performAction(): constructs a projectile based on projectileType and range

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

EnemyState

What state each enemy is in at any time, used for the movement of each enemy state machine

Enums:

  • stunned
  • patrolling
  • attacking
  • charging

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

Boss

Most difficult enemy type, basically larger more complex regular enemies; inherits from enemy

Variables:

  • weapon: changes with each boss shape

Methods:

  • Boss(): constructor for Boss
  • performAttack1(): executes its first attack, overridden by each unique boss
  • performAttack2(): executes its second attack, overridden by each unique boss
  • performAttack3(): executes its third attack, overridden by each unique boss

Pyramid

Triangle Boss; inherits from boss

Methods:

  • performAttack1(): Overrides Boss method
  • performAttack2(): Overrides Boss method
  • performAttack3(): Overrides Boss method

Cube

Square Boss; inherits from boss

Methods:

  • performAttack1(): Overrides Boss method
  • performAttack2(): Overrides Boss method
  • performAttack3(): Overrides Boss method

Dodecahedron

Most powerful polyhedron Boss; inherits from boss

Methods:

  • performAttack1(): Overrides Boss method
  • performAttack2(): Overrides Boss method *performAttack3(): Overrides Boss method

Circle

Most powerful Boss; inherits from boss

Methods:

  • performAttack1(): Overrides Boss method
  • performAttack2(): Overrides Boss method
  • performAttack3(): Overrides Boss method

ProjectileType

which type of projectile is created

Enums:

  • arrow
  • magicBlast
  • fireball
  • bullet

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 with 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

PlayerState

description of the player used in state machine

Enums:

  • walking: the player is walking
  • attacking: the player is attacking
  • blocking: the player is blocking
  • dodging: the player is dodging
  • idle: the player is idle

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

Stats

keeps track of health, strength, speed, and any additions or subtractions from them

Variables:

  • strength: integer value of how much damage each attack should do
  • health: integer value of how much damage an entity can take before death
  • speed: integer value of how far an entity moves each frame

Methods:

  • Stats(): constructor for stats
  • getStrength(): returns strength
  • getHealth(): returns health
  • getSpeed(): returns speed

Design Review

2022/04/12 3:00pm - Ethan Collins Recommended adjustments:

  • Change CellType values to: OBSTACLE, EMPTY, ENEMY
  • Add booleans isPaused and cheatMode to World to have easy access to those states when necessary
  • Add Integers points, experience and skillPoints to Player to track their score, as well as experience/skillPoints for purposes of unlocking skills
  • Add performAttack3 to each of the bosses
  • Remove Obstacle class as it is redundant to the OBSTACLE CellType
  • Check with Dr. Schaub about including indictors for visibility, variable types and method parameters/returns

4/12/22 | Paul Alger Recommended adjustments:
* Change Player to an instance variable in the World class

Clone this wiki locally