Package snap.games

Class GameView

All Implemented Interfaces:
PropChange.DoChange, XMLArchiver.Archivable, ViewHost
Direct Known Subclasses:
BoardGameView

public class GameView extends ChildView
This class is the main view for games and manages Actors.
  • Field Details

  • Constructor Details

    • GameView

      public GameView()
      Constructor.
    • GameView

      public GameView(double width, double height)
      Constructor.
  • Method Details

    • getController

      public GameController getController()
      Returns the game controller.
    • getImage

      public Image getImage()
      Returns the background image.
    • setImage

      public void setImage(Image anImage)
      Sets the background image.
    • setImageForName

      public void setImageForName(String imageName)
      Sets the image for given name.
    • getShowCoords

      public boolean getShowCoords()
      Returns whether to draw coordinate grid.
    • setShowCoords

      public void setShowCoords(boolean aValue)
      Sets whether to draw coordinate grid.
    • getActors

      public List<Actor> getActors()
      Returns the actors.
    • getActorsReversed

      public List<Actor> getActorsReversed()
      Returns the actors reversed.
    • addActorAtXY

      public void addActorAtXY(Actor anActor, double anX, double aY)
      Adds a new actor to game view at given XY point.
    • getActorForName

      public Actor getActorForName(String aName)
      Returns the actor with given name.
    • getActorAtXY

      public <T extends Actor> T getActorAtXY(double aX, double aY, Class<T> aClass)
      Returns the first actor hit by given point in local coords.
    • getActorsAtXY

      public <T extends Actor> List<T> getActorsAtXY(double aX, double aY, Class<T> aClass)
      Returns the actors hit by given point in local coords.
    • isActorAtXY

      protected boolean isActorAtXY(Actor anActor, double aX, double aY, Class<?> aClass)
      Returns whether given actor is at given XY and of matching class.
    • removeActor

      public Actor removeActor(int anIndex)
      Removes an actor.
    • removeActor

      public int removeActor(Actor anActor)
      Removes an actor.
    • setFillColor

      public void setFillColor(String aString)
      Sets the game view fill color for given color string.
    • isMouseDown

      public boolean isMouseDown()
      Returns whether the mouse button is down.
      Overrides:
      isMouseDown in class View
    • getMouseX

      public double getMouseX()
      Returns the mouse X.
    • getMouseY

      public double getMouseY()
      Returns the mouse Y.
    • isMouseClicked

      public boolean isMouseClicked()
      Returns whether the mouse was clicked on this frame.
    • getMouseClickCount

      public int getMouseClickCount()
      Returns the mouse click count.
    • isKeyDown

      public boolean isKeyDown(String aKey)
      Returns whether a given key is pressed.
    • isKeyClicked

      public boolean isKeyClicked(String aKey)
      Returns whether a given key was pressed in the current frame.
    • isPlaying

      public boolean isPlaying()
      Returns whether game is playing.
    • setPlaying

      public void setPlaying(boolean aValue)
      Sets whether game is playing.
    • play

      public void play()
      Starts the game timer.
    • stop

      public void stop()
      Stops the game timer.
    • stepGameFrame

      protected void stepGameFrame()
      Steps the game forward a frame.
    • paintFront

      protected void paintFront(Painter aPntr)
      Paints the game view.
      Overrides:
      paintFront in class View
    • processEvent

      protected void processEvent(ViewEvent anEvent)
      Process event.
      Overrides:
      processEvent in class View
    • addChild

      public void addChild(View aChild, int anIndex)
      Override to clear actors list.
      Overrides:
      addChild in class ChildView
    • removeChild

      public View removeChild(int anIndex)
      Override to clear actors list.
      Overrides:
      removeChild in class ChildView