Class GameController
java.lang.Object
GameController
public class GameController
extends java.lang.Object
GameController.java - A class to control flow of asteroids game
-
Constructor Summary
Constructors Constructor Description GameController()Constructor initializes arraylists to hold game objects, as well as score and lives -
Method Summary
Modifier and Type Method Description voidaddAlien(Alien alien)Add an alien spaceship to the gamevoidaddAlienBullet(Bullet bullet)Add an alien bullet to game when alien shootsvoidaddAsteroids(BigAsteroid[] asteroidsToAdd)Add multiple asteroids to game This method takes advantage of polymorphism to add big, medium, and small asteroids as both medium and small asteroids inherit from big asteroid class so can be treated as the same data typevoidaddBullet(Bullet bullet)Add a bullet to game when player shootsvoidaddGameFrame(GameFrame gameFrame)Gives game controller access to game framevoidaddPlayer(Player player)Add player to game windowvoidendGame()Execute ending game proceduresvoidexitGame()Execute exit game procedures This method involves text-file outputjava.awt.ImagegetAlienAnimation()Returns alien spaceship animation spritejava.awt.ImagegetAsteroidDestroyedImage()Returns asteroid destroy animationjava.awt.image.BufferedImagegetBigAsteroidImage()Returns big asteroid spritejava.awt.image.BufferedImagegetBulletImage()Returns bullet spritejavax.swing.ImageIcongetExitButtonImage()Returns exit button imageintgetHighscore()Return current highscorejava.awt.image.BufferedImagegetMediumAsteroidImage()Returns medium asteroid spritePlayergetPlayer()java.awt.ImagegetPlayerDestroyedImage()Returns player destroyed animationjava.awt.image.BufferedImagegetPlayerImage()Returns player spritejava.awt.image.BufferedImagegetSmallAsteroidImage()Returns small asteroid spritejavax.swing.ImageIcongetStartButtonImage()Returns start button imagevoidloadHighscore()Load current highscore from filevoidloadImages()Load images for game object spritesvoidremoveAlien(Alien alien)voidremoveAsteroid(BigAsteroid asteroid)Remove an asteroid from the game when it is destroyed This method takes advantage of polymorphism to remove big, medium, and small asteroids as both medium and small asteroids inherit from big asteroid class so can be treated as the same data typevoidremoveBullet(Bullet bullet)Remove a bullet from game when it is destroyedvoidremovePlayer()Remove a player from the screen when ship is destroyedvoidreturnToMenu()Tells game window to set up menu and updates highscorevoidstartAlienTimer()voidstartAsteroidTimer()Starts timer that adds new asteroids to game periodicallyvoidstartGame()Tells window to set up game window and sets up all game piecesvoidstartGameTimer()Start timer to control game from frame to frame
-
Constructor Details
-
GameController
public GameController()Constructor initializes arraylists to hold game objects, as well as score and lives
-
-
Method Details
-
loadImages
public void loadImages() throws java.io.IOExceptionLoad images for game object sprites- Throws:
java.io.IOException- if any images are absent
-
loadHighscore
public void loadHighscore() throws java.io.IOExceptionLoad current highscore from file- Throws:
java.io.IOException- if no file is present This method implements text file I/O Known exploit: Text file is unsecure and easy to edit
-
getHighscore
public int getHighscore()Return current highscore- Returns:
- Highscore
-
getPlayerImage
public java.awt.image.BufferedImage getPlayerImage()Returns player sprite- Returns:
- Player sprite
-
getPlayerDestroyedImage
public java.awt.Image getPlayerDestroyedImage()Returns player destroyed animation- Returns:
- Player destroyed animation
-
getBulletImage
public java.awt.image.BufferedImage getBulletImage()Returns bullet sprite- Returns:
- Bullet sprite
-
getBigAsteroidImage
public java.awt.image.BufferedImage getBigAsteroidImage()Returns big asteroid sprite- Returns:
- Big asteroid sprite
-
getMediumAsteroidImage
public java.awt.image.BufferedImage getMediumAsteroidImage()Returns medium asteroid sprite- Returns:
- Medium asteroid sprite
-
getSmallAsteroidImage
public java.awt.image.BufferedImage getSmallAsteroidImage()Returns small asteroid sprite- Returns:
- Small asteroid sprite
-
getAsteroidDestroyedImage
public java.awt.Image getAsteroidDestroyedImage()Returns asteroid destroy animation- Returns:
- Asteroid destroy animation
-
getAlienAnimation
public java.awt.Image getAlienAnimation()Returns alien spaceship animation sprite- Returns:
- Alien spaceship animation
-
getStartButtonImage
public javax.swing.ImageIcon getStartButtonImage()Returns start button image- Returns:
- Start button image
-
getExitButtonImage
public javax.swing.ImageIcon getExitButtonImage()Returns exit button image- Returns:
- Exit button image
-
addGameFrame
Gives game controller access to game frame- Parameters:
gameFrame- Game frame generating game window
-
addBullet
Add a bullet to game when player shoots- Parameters:
bullet- Bullet to be added
-
addAlienBullet
Add an alien bullet to game when alien shoots- Parameters:
bullet- Bullet to be added
-
addAlien
Add an alien spaceship to the game- Parameters:
alien- Bullet to be added
-
removeBullet
Remove a bullet from game when it is destroyed- Parameters:
bullet- Bullet to be removed
-
removeAsteroid
Remove an asteroid from the game when it is destroyed This method takes advantage of polymorphism to remove big, medium, and small asteroids as both medium and small asteroids inherit from big asteroid class so can be treated as the same data type- Parameters:
asteroid- Asteroid to be removed
-
addAsteroids
Add multiple asteroids to game This method takes advantage of polymorphism to add big, medium, and small asteroids as both medium and small asteroids inherit from big asteroid class so can be treated as the same data type- Parameters:
asteroidsToAdd- Array of asterodis to be added
-
addPlayer
Add player to game window- Parameters:
player- Player object to be added
-
removePlayer
public void removePlayer()Remove a player from the screen when ship is destroyed -
removeAlien
-
getPlayer
-
startGameTimer
public void startGameTimer()Start timer to control game from frame to frame -
startAsteroidTimer
public void startAsteroidTimer()Starts timer that adds new asteroids to game periodically -
startAlienTimer
public void startAlienTimer() -
startGame
public void startGame()Tells window to set up game window and sets up all game pieces -
endGame
public void endGame()Execute ending game procedures -
returnToMenu
public void returnToMenu()Tells game window to set up menu and updates highscore -
exitGame
public void exitGame()Execute exit game procedures This method involves text-file output
-