Package base

Class GameLoop

java.lang.Object
base.GameLoop
Direct Known Subclasses:
BreakoutGame, MovingObjectsGame, MultiLevelGame

public class GameLoop extends Object
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 or Playground methods periodically, at every time step of the game.
There will normally never be a need to modify this file, a designer/game programmer should always redefine the GameObject and Playground classes and implement new functionality there. To make a long story short
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    Pixel width of Game GUI ( above 0)
    static int
    Pixel height of Game GUI (above 0)
  • Constructor Summary

    Constructors
    Constructor
    Description
    constructor which calls defineLevels(), which adds all levels of this game.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    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 of Level1 by calling #addLevel().
    static void
    main(String[] args)
    main to start the whole application.
    (package private) void
    Removes all levels from the list of levels to play!
    void
    runGame(String[] args)
    loops over all levels and implements the game loop to update continuously the level during play time

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SIZEX

      public static int SIZEX
      Pixel width of Game GUI ( above 0)
    • SIZEY

      public static int SIZEY
      Pixel height of Game GUI (above 0)
  • Constructor Details

    • GameLoop

      public GameLoop()
      constructor which calls defineLevels(), 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 of Level1 by calling #addLevel(). Should be called only before playing starts (e.g. in constructor or before runGame(String[]) is called.
      Note: Subclasses of GameLoop should override this method to define own levels for their game.
    • addLevel

      void addLevel(Playground level)
      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 before runGame(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 while runGame(String[]) is running!
    • runGame

      public void runGame(String[] args) throws IOException
      loops over all levels 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

      public static void main(String[] args) throws IOException
      main to start the whole application. It calls. runGame(String[]). (levels are automatically added/loaded by constructor of GameLoop()).
      Parameters:
      args - Java default command line args, forwarded to runGame(String[])
      Throws:
      IOException - in case highscore.txt cannot be written.