Package base
Class GameLoop
java.lang.Object
base.GameLoop
- Direct Known Subclasses:
BreakoutGame
,MovingObjectsGame
,MultiLevelGame
Main class starting any game, contains main(). Apart from that, this class manages all
non-logical functionalities which should be hidden from a game designer like:
- Setting up windows, panels, buttons, action callbacks, ...
- Reading keyboard inputs
- Redrawing game window if necessary
- managing the game time and calling the appropriate
GameObject
orPlayground
methods periodically, at every time step of the game.
GameObject
and Playground
classes and implement new functionality
there. To make a long story short-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGameLoop()
constructor which callsdefineLevels()
, which adds all levels of this game. -
Method Summary
Modifier and TypeMethodDescription(package private) void
addLevel
(Playground level) Adds the given level instance to the end of the currently already stored list of levels to play.(package private) void
First resets (clears) the already existing level instances of this game's list of levels (resetLevels()
), then adds one instance ofLevel1
by calling#addLevel()
.static void
main to start the whole application.(package private) void
Removes all levels from the list of levels to play!void
loops over alllevels
and implements the game loop to update continuously the level during play time
-
Field Details
-
SIZEX
public static int SIZEXPixel width of Game GUI ( above 0) -
SIZEY
public static int SIZEYPixel height of Game GUI (above 0)
-
-
Constructor Details
-
GameLoop
public GameLoop()constructor which callsdefineLevels()
, which adds all levels of this game.
-
-
Method Details
-
defineLevels
void defineLevels()First resets (clears) the already existing level instances of this game's list of levels (resetLevels()
), then adds one instance ofLevel1
by calling#addLevel()
. Should be called only before playing starts (e.g. in constructor or beforerunGame(String[])
is called.
Note: Subclasses ofGameLoop
should override this method to define own levels for their game. -
addLevel
Adds the given level instance to the end of the currently already stored list of levels to play. Should be called only before playing starts (e.g. in constructor or beforerunGame(String[])
is called.- Parameters:
level
- instance of Playground (a level) to add.
-
resetLevels
void resetLevels()Removes all levels from the list of levels to play! Do not call this method whilerunGame(String[])
is running! -
runGame
loops over alllevels
and implements the game loop to update continuously the level during play time- Parameters:
args
- command line arguments forwarded (currently ignored)- Throws:
IOException
- if hitghscore.txt cannot be written.
-
main
main to start the whole application. It calls.runGame(String[])
. (levels are automatically added/loaded by constructor ofGameLoop()
).- Parameters:
args
- Java default command line args, forwarded torunGame(String[])
- Throws:
IOException
- in case highscore.txt cannot be written.
-