public class Controller
extends java.lang.Object
implements java.awt.event.KeyListener
Modifier and Type | Class and Description |
---|---|
(package private) class |
Controller.damagePlantTask
TimerTask that handles damaging plants in a certain interval.
|
(package private) class |
Controller.TrashTask
TimerTask subclass that handles the spawning of Litter object around the map at the set interval it was scheduled at by calling the appropriate Model to View communication.
|
Modifier and Type | Field and Description |
---|---|
private int |
cheatState
The stage of counting "cheat" typing
|
private static int |
DRAW_DELAY
The delay between game frames
|
private Model |
model
The instance of
Model . |
private javax.swing.Action |
stepAction
The Action to run every frame.
|
private javax.swing.Timer |
stepTimer
The main loop timer
|
private java.util.Timer |
taskTimer
A timer used to damage the plants, runs
Controller.damagePlantTask |
private java.util.Timer |
trashTimer
A timer used to spawn litter, runs
Controller.TrashTask |
private View |
view
The instance of
View . |
Constructor and Description |
---|
Controller() |
Modifier and Type | Method and Description |
---|---|
void |
keyPressed(java.awt.event.KeyEvent e)
Changes the player's velocity according to the arrow keys being pressed, or marks that the space key is pressed down.
|
void |
keyReleased(java.awt.event.KeyEvent e)
Changes the player's velocity according to the arrow keys being released, or mark that the space key is no longer pressed down.
|
void |
keyTyped(java.awt.event.KeyEvent e)
Handles typing and cheat codes.
|
void |
loadGame()
Method that loads the serializable file and changes the attributes in model.
|
void |
saveGame()
Method that serializes the state of model to a serial file.
|
void |
start()
Method that creates a new Model and View, and starts the game.
|
private void |
step()
Method that updates the Model and changes the view based on the Model.
|
private javax.swing.Timer stepTimer
private java.util.Timer taskTimer
Controller.damagePlantTask
private java.util.Timer trashTimer
Controller.TrashTask
private static final int DRAW_DELAY
private int cheatState
private final javax.swing.Action stepAction
step()
method.private void step()
None
- public void start()
None.
- public void keyPressed(java.awt.event.KeyEvent e)
keyPressed
in interface java.awt.event.KeyListener
e
- The KeyEvent containing the key that way pressed.public void saveGame()
None.
- public void loadGame()
None.
- public void keyReleased(java.awt.event.KeyEvent e)
GamePhase.TITLE_SCREEN
, will start the tutorial.
If the space key was released and the game is in the GamePhase.GAME_END
, will reset and start normal mode.
If the 'q' key was released and the game is in the GamePhase.GAME_END{}, will start the title screen.keyReleased
in interface java.awt.event.KeyListener
e
- The KeyEvent containing the key that was released.public void keyTyped(java.awt.event.KeyEvent e)
keyTyped
in interface java.awt.event.KeyListener
e
- Ignored