public class Model
extends java.lang.Object
implements java.io.Serializable
View
for that
has methods to detect collision with boundaries decide next direction provide
direction provide locationModifier and Type | Field and Description |
---|---|
private Litter |
animalEatenLitter
The last Litter to be picked up by an
animal |
private java.util.HashSet<Animal> |
animals
Every animal in the world.
|
private int |
animalXIncr
The horizontal speed of the Crab
|
private int |
animalYIncr
The vertical speed of the Crab
|
private Animal |
crab
The Crab, currently the only Animal in the game.
|
private int |
crabDirection
The current movement direction of the
crab . |
private int |
endTimeMilli
How many milliseconds the game should last
|
private GamePhase |
gamePhase
The current game phase
|
private boolean |
hasLitter
Whether the Player is carrying
Litter . |
private boolean |
hasLost
Whether the player has lost
|
private static int |
HEIGHT
The height of the world in WORLD coordinates
|
private java.util.HashSet<java.util.ArrayList<java.lang.Integer>> |
litterAttrSet
HashSet where every element is an ArrayList containing the x and y
coordinates of the Litter objects, as well as the imgID and LitterType to
send to View
|
private java.util.HashSet<Litter> |
litterSet
HashSet of all of the current Litter objects in the game
|
private Litter |
pickedUp
The last Litter to be picked up by the
player |
(package private) java.util.ArrayList<java.lang.Integer> |
pickedUpAttr
ArrayList of Litter imgID and LitterType of Model.pickedUp Litter attribute
to send to View
|
private int |
plantDamage
The amount of health to detract from the Plant every time it is damaged
|
private static int |
plantHealth
The initial amount of health of each Plant
|
private java.util.ArrayList<Plant> |
plants
Contains plant objects
|
private Player |
player
The only controllable object in the game.
|
private boolean |
playerMove
Whether the player is allowed to move this frame.
|
private int |
randPlant
Random index of next plant
|
private Receptacle |
rBin
The recycle bin
|
private int |
recycleGlow
A count of the number of frames the recycle bin has been in glowing victory state for
|
private boolean |
recycleVictory
Whether the recycle bin recently received a piece of Litter
|
(package private) River |
river
onscreen river
|
private boolean |
spacePressed
Whether the space key is currently pressed down.
|
private long |
startTime
The time in milliseconds that the game has begun
|
private Receptacle |
tBin
The trash bin
|
private int |
totalLitterCollected
The number of Litter objects that the Player has picked up throughout the game
|
private int |
totalPlantsPlanted
The number of Plants that the Player has replanted throughout the game
|
private int |
trashGlow
A count of the number of frames the trash bin has been in glowing victory state for
|
private boolean |
trashVictory
Whether the trash bin recently received a piece of Litter
|
private boolean |
tutorialAnimalAteLitter
Boolean variable that represents whether the animal has eaten the Litter in
the tutorial
|
private boolean |
tutorialArrowKeyPrompt
Boolean that represents whether the arrow key prompt should be shown on
screen.
|
private boolean |
tutorialHoverLitter
Boolean that represents whether or not the Player is hovering, but not
picking up a Litter object
|
private boolean |
tutorialPlantGrown
Boolean variable that represents whether the player has planted the plant
that despawns in the tutorial
|
private TutorialState |
tutorialState
Current state of the tutorial
|
private static int |
WIDTH
The width of the world in WORLD coordinates
|
Constructor and Description |
---|
Model(int width,
int height)
Constructor for the Model.
|
Modifier and Type | Method and Description |
---|---|
void |
animalBinCollision()
Method that checks whether the crab has the trash bin or the recycling bin.
|
void |
animalWallCollision()
Method that checks whether the crab has hit a wall.
|
private boolean |
checkCollision()
Method that deals with all the various collisions in the game.
|
void |
checkPlants()
Method called to decide if all plants are gone and whether to flood the river
|
boolean |
checkPlayerAnimalCollision()
Method that checks whether the crab has collided with the player.
|
void |
checkPlayerWallCollision()
Checks whether the player is walking of the screen in any dimension, and prevents the player from doing so.
|
void |
checkTutorialStates()
Checks the current state of the tutorial, and calls tutorial events and
changes tutorial states as the player progresses through the tutorial.
|
void |
damagePlant()
Method called to decrement plant health by the plantdamage integer value
|
void |
damagePlant(int i)
Method called to damage a specific plant by the plantdamage integer value
|
void |
floodRiver()
Method called to flood the river onto land
|
Animal |
getAnimal()
Gets the Animal of the game.
|
Litter |
getAnimalEatenLitter()
|
int |
getAnimalXIncr()
Simple getter method that retrieves the amount the x coordinate should be
incremented by.
|
int |
getAnimalYIncr()
Simple getter method that retrieves the amount the y coordinate should be
incremented by.
|
int |
getEndTime()
Method that returns how long the game should last in milliseconds
|
GamePhase |
getGamePhase()
Sets the last picked up litter to the parameter
|
boolean |
getHasLost()
Get whether the player has lost,
|
int |
getHeight()
Gets the height of the Model
|
java.util.ArrayList<java.lang.Integer> |
getLitterAttr(Litter l)
Take a litter object and adds its attributes to an ArrayList of Integers that can be passed on to view
The first and second integer in the ArrayList returns represents the x and y location of the Litter object respectively
The third integer represents the imgID, the fourth represents the LitterType represented as an integer.
|
java.util.HashSet<java.util.ArrayList<java.lang.Integer>> |
getLitterAttrSet()
Returns the HashSet
|
java.util.HashSet<Litter> |
getLitterSet()
Returns the HashSet
|
java.util.ArrayList<java.lang.Integer> |
getPickedUpAttr()
Returns the ArrayList
|
Litter |
getPickedUpLitter()
Gets the Litter most recently picked up by the Player.
|
java.util.ArrayList<Plant> |
getPlants()
Method called to return plant array
|
Player |
getPlayer()
Gets the Player of the game
|
int |
getRandPlant()
Method called to return randPlant index
|
Receptacle |
getRBin()
Gets the
recycle bin . |
boolean |
getRecycleVictory()
Gets the
boolean . |
River |
getRiver()
Method called to return river
|
boolean |
getSpacePressed()
Gets whether the space key is pressed down.
|
long |
getStartTime()
Method to determine the game's start time
|
Receptacle |
getTBin()
Gets the
trash bin . |
int |
getTotalLitterCollected()
Returns the number of Litter objects that were collected throughout the game.
|
int |
getTotalPlantsPlanted()
Get the number of plants that were planted throughout the game.
|
boolean |
getTrashVictory()
Gets the
boolean . |
TutorialState |
getTutorialState()
Returns the current state of the tutorial, more specifically which stage of
the tutorial the player is on.
|
int |
getWidth()
Gets the width of the Model
|
boolean |
isAnimalAteLitter()
Returns the tutorialAnimalAteLitter boolean value
|
boolean |
isArrowKeyPrompt()
Returns the tutorialArrowKeyPrompt
|
boolean |
isHasLitter()
Returns a boolean depending on whether or not the player is currently holding
a Litter object that needs to be disposed of.
|
boolean |
isHoverLitter()
Returns the tutorialHoverLitter boolean of Model.
|
void |
litterWasCollected()
Increments the counter to track that a litter was collected.
|
void |
normalAlterPlayerVelocity(int ddx,
int ddy)
Alters the player's velocity, only works in the NORMAL
GamePhase . |
Litter |
pickUpLitter(Litter l)
"Picks up" a Litter object the Player is colliding with.
|
void |
recedeRiver()
Method called to return river to normal state
|
void |
resetEverything()
Resets everything to the 'initial game' state.
|
void |
setAnimalAteLitter(boolean animalAteLitter)
Sets the tutorialAnimalAteLitter boolean value of the Model.
|
void |
setGamePhase(GamePhase gp)
Sets the game phase of the Model.
|
void |
setHasLitter(boolean hasLitter)
Sets the hasLitter boolean of the model
|
void |
setPickedUpLitter(Litter l)
Sets the last picked up litter to the parameter
|
void |
setPlantGrown(boolean plantGrown)
Sets the tutorialPlantGrown boolean value of the Model.
|
void |
setRandPlant()
Method called to set randPlant index
|
void |
setRecycleVictory(boolean recycleVictory)
Sets the recycleVictory boolean of the Model.
|
void |
setTrashVictory(boolean trashVictory)
Sets the trashVictory boolean of the Model.
|
void |
setTutorialState(TutorialState tutorialState)
Sets the tutorial state of the game.
|
void |
spaceKeyPressed()
Method called when the space key is pressed.
|
void |
spaceKeyReleased()
Method called when the space key is released.
|
Litter |
spawnLitter()
Generates a new Litter object with random x and y coordinates, as well as
generates a random imgID for the object.
|
Litter |
spawnLitter(LitterType lt)
A public version of
checkCollision() only for use by the
ModelTest class. |
void |
startEndGame()
Moves to the ending game state (does NOT reset!)
|
void |
startNormal()
Moves to the Normal game state (does NOT reset!)
|
void |
startTitleScreen()
Initializes the title screen
|
void |
startTutorial()
Initializes the tutorial
|
boolean |
testCheckColl()
A public version of
checkCollision() only for use by the
ModelTest class. |
void |
updateModel()
Checks the current state of the game, and calls the appropriate updateModel
function depending on whether the game is currently in tutorial or regular
mode
|
void |
updatingAnimalLocation()
Method that updates the x and y coordinates of the crab depending on its
current direction.
|
void |
updatingTutorialAnimalLocation()
Moves the crab down by 10 units
|
private static int WIDTH
private static int HEIGHT
private GamePhase gamePhase
private TutorialState tutorialState
private boolean hasLitter
Litter
.private boolean spacePressed
private int crabDirection
crab
.private final int plantDamage
private static final int plantHealth
private Receptacle tBin
private Receptacle rBin
private boolean trashVictory
private boolean recycleVictory
private int trashGlow
private int recycleGlow
private Animal crab
private java.util.HashSet<Animal> animals
private java.util.HashSet<Litter> litterSet
private java.util.HashSet<java.util.ArrayList<java.lang.Integer>> litterAttrSet
private int animalXIncr
private int animalYIncr
private boolean hasLost
private boolean playerMove
java.util.ArrayList<java.lang.Integer> pickedUpAttr
private java.util.ArrayList<Plant> plants
private int randPlant
private boolean tutorialPlantGrown
private boolean tutorialAnimalAteLitter
private boolean tutorialArrowKeyPrompt
private boolean tutorialHoverLitter
River river
private long startTime
private int endTimeMilli
private int totalLitterCollected
private int totalPlantsPlanted
public Model(int width, int height)
width
- Width of the model.height
- Height of the model.public void setTrashVictory(boolean trashVictory)
trashVictory
- The boolean value the trashVictory boolean will be set to.public void setRecycleVictory(boolean recycleVictory)
recycleVictory
- The boolean value the recycleVictory boolean will be set to.public void setPlantGrown(boolean plantGrown)
plantGrown
- The boolean value the tutorialPlantGrown boolean will be set to.public boolean isAnimalAteLitter()
public void setAnimalAteLitter(boolean animalAteLitter)
animalAteLitter
- The boolean value the tutorialAnimalAteLitter boolean will be set to.public java.util.HashSet<Litter> getLitterSet()
public boolean isHoverLitter()
public boolean isArrowKeyPrompt()
public java.util.ArrayList<java.lang.Integer> getPickedUpAttr()
public java.util.HashSet<java.util.ArrayList<java.lang.Integer>> getLitterAttrSet()
public boolean isHasLitter()
None
- public void setHasLitter(boolean hasLitter)
hasLitter
- The boolean variable hasLitter will be set to.public TutorialState getTutorialState()
public void setTutorialState(TutorialState tutorialState)
tutorialState
- TutorialState variable that will become the current tutorial state of this Model.public int getAnimalXIncr()
empty
- public int getAnimalYIncr()
empty
- public Player getPlayer()
None.
- public Animal getAnimal()
None.
- public Litter getPickedUpLitter()
None.
- public boolean getSpacePressed()
public Litter getAnimalEatenLitter()
public Receptacle getRBin()
recycle bin
.recycle bin
. /** Gets the recycle
bin
.public Receptacle getTBin()
trash bin
.trash bin
.public void updateModel()
public void checkPlayerWallCollision()
public void checkTutorialStates()
public void spaceKeyPressed()
None.
- public void spaceKeyReleased()
spacePressed
to false, and exits the title
screen if necessary.None.
- public void animalWallCollision()
empty
- public void animalBinCollision()
empty
- public void updatingTutorialAnimalLocation()
public void updatingAnimalLocation()
empty
- public void damagePlant()
public void damagePlant(int i)
i
- The index in the plant arrayList of the plant to be damaged.public void setRandPlant()
public int getRandPlant()
public java.util.ArrayList<Plant> getPlants()
public River getRiver()
public void floodRiver()
public void recedeRiver()
public void checkPlants()
public Litter spawnLitter()
public Litter spawnLitter(LitterType lt)
checkCollision()
only for use by the
ModelTest
class.lt
- The litterType of the new Litter objectcheckCollision()
,
/** Method that spawns Litter for tutorial purposes. Spawns the Litter
at a set location with the specified type.
public boolean testCheckColl()
checkCollision()
only for use by the
ModelTest
class.checkCollision()
,
ModelTest
public boolean checkPlayerAnimalCollision()
empty
- private boolean checkCollision()
empty
- public Litter pickUpLitter(Litter l)
l
- The Litter object being picked uppublic java.util.ArrayList<java.lang.Integer> getLitterAttr(Litter l)
l
- The litter objectpublic int getWidth()
public int getHeight()
public GamePhase getGamePhase()
l
- The new Litter /** Gets the current game phase of the Modelpublic void setGamePhase(GamePhase gp)
gp
- The game phase to be set to the Model.public void setPickedUpLitter(Litter l)
l
- The new Litterpublic void normalAlterPlayerVelocity(int ddx, int ddy)
GamePhase
.
When outside that phase, does nothing.ddx
- The change in x-velocity of the playerddy
- The change in y-velocity of the playerpublic void startTitleScreen()
public void startTutorial()
public void startNormal()
public void startEndGame()
public void resetEverything()
public long getStartTime()
public int getEndTime()
public void litterWasCollected()
public int getTotalLitterCollected()
public int getTotalPlantsPlanted()
public boolean getHasLost()
false
if the player has won, true
if the player has lost.