Package playground

Class Playground

java.lang.Object
playground.Playground
Direct Known Subclasses:
BreakoutLevelBase, SpaceInvadersLevel

public abstract class Playground extends Object
Playground represents a level of the game, focusing on the game LOGIC, i.e., not so much on the graphical representation. In particular, an instance of Playground
  • Field Details

  • Constructor Details

    • Playground

      public Playground()
  • Method Details

    • preferredSizeX

      public abstract int preferredSizeX()
    • preferredSizeY

      public abstract int preferredSizeY()
    • addObject

      public void addObject(GameObject o)
      Adds a graphics object to a level.
      Parameters:
      o - GameObject The object to be added
    • addObjectNow

      public void addObjectNow(GameObject o)
      Adds a graphics object to a level.
      Parameters:
      o - GameObject The object to be added
    • collectObjects

      public LinkedList<GameObject> collectObjects(String substr, boolean filterInactive)
      Puts objects with a certain substring in their name into a LinkedLisrt and returns them.
      Parameters:
      substr - The string that must be part of the object name if object is to be considered found.
      filterInactive - if set true only active objects are considered.
      Returns:
      a reference to a LinkedList filled with all objects that have substr in their name
    • deleteObject

      public void deleteObject(String id)
      Removes a graphics object from a level.
      Parameters:
      id - String The unique identifier of the object
    • deleteObjectNow

      public void deleteObjectNow(String id)
      Removes a graphics object from a level immediately, CAUTION.
      Parameters:
      id - String The unique identifier of the object
    • getObject

      public GameObject getObject(String id)
      Retrieves a graphics object by name.
      Parameters:
      id - String Unique id of the object
      Returns:
      reference to the requested game object, or null if not found
    • setGlobalFlag

      public static void setGlobalFlag(String flag, Object value)
      Sets a level-wide permanent flag.
      Parameters:
      flag - String Q unique name in this level. If it exists value is overwritten.
      value - Object Any Object can be the value of a flag!
    • setLevelFlag

      public Object setLevelFlag(String flag, Object value)
    • resetFlags

      public void resetFlags(int mode)
      mode can be: FLAGS_ALL (all), FLAGS_GLOBAL(global), FLAGs_LEVEL(level)
      Parameters:
      mode - can be only one of FLAGS_GLOBAL FLAGS_ALL or FLAGS_LEVEL
    • getGlobalFlag

      public static Object getGlobalFlag(String flag)
      Retrieves a level-wide flag by name.
      Parameters:
      flag - String Unique flag id
      Returns:
      the value associated with flag, or null if the flag does not exist.
    • getOrCreateGlobalFlag

      public static Object getOrCreateGlobalFlag(String flag, Object value)
      checks for existence and if not creates the new global flag with the given initial value. Returns the value. afterwards it is guaranteed that no priorly existing value is overridden and that it definitely exists (created if not present before).
      Parameters:
      flag - String name for the global flag (created if not present)
      value - Object value to be stored (used only if flag was not present)
      Returns:
      the current value of the flag (maybe the initial one in case flag was not there before)
    • getLevelFlag

      public Object getLevelFlag(String flag)
    • getOrCreateLevelFlag

      public Object getOrCreateLevelFlag(String flag, Object createValue)
    • reset

      public void reset()
      Reinitializes the level.
    • isPaused

      public boolean isPaused()
    • setPaused

      public void setPaused(boolean p)
    • togglePause

      public void togglePause()
    • processKeyEvents

      public void processKeyEvents(Stack<KeyEvent> keyEvents)
      Method meant to be filled with own code, processes Keyboard inputs.
      Parameters:
      keyEvents - all collected KeyEvents collected since last game loop.
    • processMouseEvents

      public void processMouseEvents(Stack<MouseEvent> mouseEvents)
    • getKeyEvents

      public Stack<KeyEvent> getKeyEvents()
    • getMouseEvents

      public Stack<MouseEvent> getMouseEvents()
    • applyGameLogic

      public abstract void applyGameLogic()
      Method meant to be filled with own code, handles the entore game logic (collision checks, timed events, ...).
    • prepareLevel

      public abstract void prepareLevel(String level)
      Sets up a single level. Prepares all objects etc.
      Parameters:
      level - String a string identifying the level number etc
    • gameOver

      public abstract boolean gameOver()
    • levelFinished

      public abstract boolean levelFinished()
    • getSizeX

      public int getSizeX()
    • getSizeY

      public int getSizeY()
    • updateObjects

      public void updateObjects()
      Calls all object update methods in level. Internal, never call directly.
    • setTimestep

      public void setTimestep(double s)
    • getTimestep

      public double getTimestep()
    • setGameTime

      public void setGameTime(double s)
      set the game time value (in seconds)
      Parameters:
      s - seconds the game is running
    • getGameTime

      public double getGameTime()
      returns time in seconds since level start
    • redrawLevel

      public abstract void redrawLevel(Graphics2D g2)
      To be redefined!! Draws mainly h level background and global information like points etc.
      Parameters:
      g2 - Graphics2D abstract drawing object of java Swing, used to carry out all drawing operations.
    • redraw

      public void redraw(Graphics2D g2)
      Internal, do not call directly.
      Parameters:
      g2 - Graphics2D abstract drawing object of java Swing, used to carry out all drawing operations.