SpampedeBrain - The "Controller" in MVC, which includes all of the AI and handling key presses. More...
Public Member Functions | |
| void | startNewGame () |
| Starts a new game. | |
| void | gameOver () |
| Declares the game over. | |
| void | cycle () |
| Moves the game forward one step (i.e., one frame of animation, which occurs every Preferences.SLEEP_TIME milliseconds) | |
| void | keyPressed (KeyEvent evt) |
| Reacts to characters typed by the user. More... | |
| void | advanceTheSnake (BoardCell nextCell) |
| Move the snake into the next cell (and possibly eat spam) More... | |
| BoardCell | getNextCellFromBFS () |
| Uses BFS to search for the spam closest to the snake head. More... | |
| void | reverseSnake () |
| Reverses the snake back-to-front and updates the movement mode appropriately. | |
| void | playSound_spamEaten () |
| Plays crunch noise. | |
| void | playSound_spam () |
| Plays spam noise. | |
| void | playSound_meow () |
| Plays meow noise. | |
| String | testing_toStringParent () |
| BoardCell | testing_getNextCellInDir () |
| String | testing_toStringSpampedeData () |
| void | startNewGame () |
| Starts a new game. | |
| void | gameOver () |
| Declares the game over. | |
| void | cycle () |
| Moves the game forward one step (i.e., one frame of animation, which occurs every Preferences.SLEEP_TIME milliseconds) | |
| void | keyPressed (KeyEvent evt) |
| Reacts to characters typed by the user. More... | |
| void | advanceTheSnake (BoardCell nextCell) |
| Move the snake into the next cell (and possibly eat spam) More... | |
| BoardCell | getNextCellFromBFS () |
| Uses BFS to search for the spam closest to the snake head. More... | |
| void | reverseSnake () |
| Reverses the snake back-to-front and updates the movement mode appropriately. | |
| void | playSound_spamEaten () |
| Plays crunch noise. | |
| void | playSound_spam () |
| Plays spam noise. | |
| void | playSound_meow () |
| Plays meow noise. | |
| String | testing_toStringParent () |
| BoardCell | testing_getNextCellInDir () |
| String | testing_toStringSpampedeData () |
Public Member Functions inherited from com.gradescope.spampede.SpampedeBrainParent | |
| void | init () |
| void | actionPerformed (ActionEvent evt) |
| void | keyReleased (KeyEvent evt) |
| void | keyTyped (KeyEvent evt) |
| void | run () |
| synchronized void | go () |
| synchronized void | stop () |
| abstract void | keyPressed (KeyEvent evt) |
| void | init () |
| void | actionPerformed (ActionEvent evt) |
| void | keyReleased (KeyEvent evt) |
| void | keyTyped (KeyEvent evt) |
| void | run () |
| synchronized void | go () |
| synchronized void | stop () |
| abstract void | keyPressed (KeyEvent evt) |
Static Public Member Functions | |
| static SpampedeBrain | getTestGame (TestGame gameNum) |
| static SpampedeBrain | getTestGame (TestGame gameNum) |
Private Member Functions | |
| BoardCell | getFirstCellInPath (BoardCell start) |
| Follows parent pointers back from the closest spam cell to decide where the head should move. More... | |
| BoardCell | getFirstCellInPath (BoardCell start) |
| Follows parent pointers back from the closest spam cell to decide where the head should move. More... | |
Private Attributes | |
| SpampedeDisplay | theDisplay |
| The "View" in MVC. | |
| SpampedeData | theData |
| The "Model" in MVC. | |
| int | cycleNum = 0 |
| Number of animated frames displayed so far. | |
Additional Inherited Members | |
Public Attributes inherited from com.gradescope.spampede.SpampedeBrainParent | |
| Image | image |
| Graphics | screen |
| AudioClip | audioSpam |
| AudioClip | audioCrunch |
| AudioClip | audioMeow |
SpampedeBrain - The "Controller" in MVC, which includes all of the AI and handling key presses.
| void com.gradescope.spampede.SpampedeBrain.advanceTheSnake | ( | BoardCell | nextCell | ) |
Move the snake into the next cell (and possibly eat spam)
This method should probably be private, but we make it public anyway to permit unit testing.
| nextCell | New location of the snake head (which must be horizontally or vertically adjacent to the old location of the snake head). |
| void com.gradescope.spampede.SpampedeBrain.advanceTheSnake | ( | BoardCell | nextCell | ) |
Move the snake into the next cell (and possibly eat spam)
This method should probably be private, but we make it public anyway to permit unit testing.
| nextCell | New location of the snake head (which must be horizontally or vertically adjacent to the old location of the snake head). |
Follows parent pointers back from the closest spam cell to decide where the head should move.
Specifically, follows the parent pointers back from the spam until we find the cell whose parent is the snake head (and which must therefore be adjacent to the previous snake head location).
Recursive or looping solutions are possible.
| start | where to start following spam pointers; this will be (at least initially, if you use recursion) the location of the spam closest to the head. |
Follows parent pointers back from the closest spam cell to decide where the head should move.
Specifically, follows the parent pointers back from the spam until we find the cell whose parent is the snake head (and which must therefore be adjacent to the previous snake head location).
Recursive or looping solutions are possible.
| start | where to start following spam pointers; this will be (at least initially, if you use recursion) the location of the spam closest to the head. |
| BoardCell com.gradescope.spampede.SpampedeBrain.getNextCellFromBFS | ( | ) |
Uses BFS to search for the spam closest to the snake head.
| BoardCell com.gradescope.spampede.SpampedeBrain.getNextCellFromBFS | ( | ) |
Uses BFS to search for the spam closest to the snake head.
| void com.gradescope.spampede.SpampedeBrain.keyPressed | ( | KeyEvent | evt | ) |
Reacts to characters typed by the user.
The provided code registers the SpampedeBrain as an "observer" for key presses on the keyboard.
So, whenever the user presses a key, Java automatically calls this keyPressed method and passes it a KeyEvent describing the specific keypress.
| void com.gradescope.spampede.SpampedeBrain.keyPressed | ( | KeyEvent | evt | ) |
Reacts to characters typed by the user.
The provided code registers the SpampedeBrain as an "observer" for key presses on the keyboard.
So, whenever the user presses a key, Java automatically calls this keyPressed method and passes it a KeyEvent describing the specific keypress.
1.8.7