-
Notifications
You must be signed in to change notification settings - Fork 0
Game Model
Tripp312 edited this page Apr 12, 2022
·
29 revisions
.png)
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
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
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
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
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