Package ui

Class GameFrame

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class GameFrame extends JFrame implements PropertyChangeListener
A window that allows playing an interactive game of PacMann. Consists of a score/lives label, buttons for pausing the current game and creating a new game, and a game board view that supports keyboard input.
See Also:
  • Field Details

    • model

      private GameModel model
      The state and logic of the current game being played in this window.
    • gameBoard

      private final GameBoard gameBoard
      The component for displaying the current game state and responding to user input related to game actions.
    • scoreLabel

      private final ScoreLabel scoreLabel
      The label for showing the score and lives remaining of the current game being played in this window.
    • randomness

      private Randomness randomness
      The source of reproducible randomness to use when creating new games via this window.
    • width

      private final int width
      The number of columns in maps played in this window.
    • height

      private final int height
      The number of rows in maps played in this window.
    • withAI

      private final boolean withAI
      Whether the player actor should be controlled by user input or by an AI in games played in this window.
  • Constructor Details

    • GameFrame

      public GameFrame(int width, int height, boolean withAI, boolean showPaths, long seed)
      Create a new window for playing interactive games of PacMann. All games will have boards with `height` rows and `width` columns. If `withAI` is true, the player actor will be controlled by AI; otherwise, it will be controlled by user input. If `showPaths` is true, then the "guidance paths" of actors will be displayed (for debugging purposes). `seed` determines the sequence of random values used in map creation and AI logic.
  • Method Details

    • newGame

      private void newGame()
      Replace the current game with a new game corresponding to the next source of randomness. Map size and player control are determined by our configuration parameter fields.
    • setGameModel

      private void setGameModel(GameModel newModel)
      Update all UI widgets to reflect the new game model `newModel` instead of any previous game. The model is expected to publish a "game_result" property.
    • showWinMessage

      private void showWinMessage()
      Show a modal dialog indicating that the current game has been won.
    • showLoseMessage

      private void showLoseMessage()
      Show a modal dialog indicating that the current game has been lost.
    • propertyChange

      public void propertyChange(PropertyChangeEvent evt)
      Specified by:
      propertyChange in interface PropertyChangeListener