-
Notifications
You must be signed in to change notification settings - Fork 0
Game Model
Sintfoap edited this page Apr 28, 2022
·
18 revisions
The central class of the Game Model. Manages and updates all of the entities.
- 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
- scoreProperty: the current score of the game
- computer: the computer associated with this game
- numPlayerCitiesLeft: the number of player cities left
- season: determines what background image to use and what weather events to trigger
- deleteEntityList: the list of entities to delete on the next update
- difficulty: the difficulty of computer
- turnCount: the tick counter
- rand: an instance of Random
- makeWeather: a custom event for creating weather
- onFireProjectile: a custom event for firing projectiles
- selectedTroops: troops currently selected by user
- selectedCity: the currently selected city
- entityManager: when called, removes entity from view as well as model
- gameOver: observer for game end logic
- endGame: flag to set when game is ended
- 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
- gameEnd(): checks to see if numPlayerCitiesLeft == 0 or if score == 0 or if player has taken over all enemy cities
- load(String lvlName): loads the saved game from gamefile, populating entityList with the saved game's state
- update(): iterates through the entity list and calls update on each entity object
- deselect(): deselects currently selected troops and currently selected city
- sendTroopsFromCity(City selectedCity, Corrdinate destination, double percentage): sends troops from city towards destination city
- sendTroopsFromGround(ArrayList troops, Coordinate destination, DestinatioType destType): sends selected troops from ground to destination
- deployTroops(boolean pointInCircle, Coordinate cityCenter, Coordinate destination, double percentage): sends troops from city to either a city or a point on the ground
- save(String lvlName): save current state of game
- makeWeather(): creates an instance of Weather
- checkInBounds(Weather w): checks if weather is inside the screen, if not, kills it.
- checkInWeather(Coordinate e): returns weatherType if troop inside weather
- deleteTroopWeather(Troop troop): deletes troop in weather
- nextInt(int lowerBound, int upperBound): custom random int function
- getCityHit(Coordinate coordinate): returns city hit
- checkInCity(Coordinate e): returns a boolean value indicating weather the coordinate is in a city
- checkInCity(Coordinate e, boolean returnCity): returns the coordinate center of a city if the coordinate is inside the city.
- moveTroopToField(ArrayList troops, Coordinate destination): assigns each troop an independent destination so that they form a circle on the field
- deleteTroop(Troop troop): deletes troop from entityList
- startTimer(): starts timer, thus starting the update loop and resuming the game
- stopTimer(): pauses the timer, halting the update loop and thus pausing the game
- instantGameover(boolean playerWin): ends game and notifies view of who won
- instantAddTroops(): adds max troops to each player city
- instantMakeWeather(): makes an instance of weather
- renderProjectile(): notifies view to render projectile
- fireProjectile(): generates a projectile
A class which creates methods used by the three different computer difficulties.
- difficulty: the difficulty stored as an enum
- turnCount: number of ticks elapsed
- obs: computer observer
- 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
- randomNumberGenerator(int min, int max): returns a double in between min and max
- calculateAttackCity(ArrayList cities): determines what city in cities to attack
An enum which represents the difficulty of a computer
An interface for computer
- renderTroops(ArrayList troops): allows the model to notify the view of troop changes
The class which all game entities extend
- turnCount: number of ticks elapsed
- location: the x, y coordinate pair for where the object is on the screen
- update(): update method which updates attributes of object
- serialize(DataOutputStream wr): a method to package and save object
Objects that consist of x, y coordinate points
- xCoordinateProperty: x-position on coordinate plane
- yCoordinateProperty: y-position on coordinate plane
- figureNewCoordinate(double heading, double distance): determines a destination based off of heading and distance
- round(double value, int places): rounds double to places number of digits
- isNearThis(Coordinate comp): checks to see if coordinate is near comp coordinate
- isEqual(Coordinate c): checks if coordinate that is passed in is equal to coordinate
A structure that creates troops and deploys them
- population: number of troops in a city
- nationality: states whether city is friendly, enemy, or neutral
- selected: boolean value that determines if a city is selected for deploying troops or not
- type: type of units produced by city
- id: identifier of city
- obs: observer that allows city to notify view of changes in state
- turnCount: tick counter
- game: reference to central game object
- location: location of city
- nextId: static current id used for id assignment
- serialize(DataOutputStream wr): a method to package and save an entity
- load(DataInputStream: rd, Game game): loads in city object
- update(): hijacks the entity update method to update certain attributes of this
- sendTroops(double percentage, Coordinate destination, CityType troopType): sends troopType troops according to the amount that the user has selected and decrements population accordingly
- figureHeading(Coordinate destination): determines new heading based on current position and destination
- fireProjectile(): generates a projectile that will kill an oncoming enemy within a range
- recieveTroops(int amount, Nationality attackingType): decrements or increments population based on nationality of incoming troop
Types of city corresponding to what type troop they send out
A class that extends Entity to create moving entities
- 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
- update(): hijacks the entity update method to update certain attributes of this
- move(): updates x and y coordinates of entity based on speed and heading
An event that happens at random and has a random effect on troops
- type: the type of weather
- rand: instance of Random
- update(): hijacks the entity update method to update certain attributes of this
- load(DatainputStream rd, String entityType): loads in instance of weather
- serialize(DataOutputStream wr): a method to package and save an entity
An enum representing the various types of possible weathers
Damaging projectiles sent out of cities to kill troops
- damage: the damage of an projectile, typically set to one
- destination: target
- turnCount: tick Counter
- location: current location
- game: reference of game
- serialize(DataOutputStream wr): a method to package and save an entity
- load(DataInputStream rd): loads in instance of projectile
- update(): hijacks the entity update method to update certain attributes of this
- fireProjectile(City city): fires a projectile out of given city
Units which are sent to attack enemy cities and defend friendly cities
- 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
- TroopDelete: observer for what to do when troop needs deleted
- destinationType: determines weather troop is being sent to city or not
- troopType: troop type corresponding to sending city
- game: reference to game
- dead: flag to set on troop death
- serialize(DataOutputStream wr): a method to package and save an entity
- load(DataInputStream rd, Game game): loads in an instance of troop
- update(): hijacks the entity update method to update certain attributes of this
- collisionDetection(): checks if troop has collided with either another troop of the opposite nationality
- figureHeading(Coordinate destination): figures heading based off of current position and destination
- Fix some minor formatting issues: completed
- Add code link to wiki page: completed