Class StarpointController


  • public class StarpointController
    extends java.lang.Object
    This is the control class for the Starpoints game. A surrounding application must create a StarpointController instance and can pass control to it by calling the start()-method. This will start the main menu, making the Controller wait for input events.

    Mouse click (or tip) events and mouseMove-events and key press events must be passed to the StarpointControllers event methods with a platform independent event-argument:
    - mouseMoved and mouseClicked (only clicks are essential for game control).
    - keyPressed events (if the StarpointContext returns false in its isKeyboardSupported()-method, key events are not necessary, the game control can be done by touchpad or direct clicks on the field).

    The StarpointController starts a UI UpdateThread, that frequently (~20ms) calls the repaintUI()-method of the StarpointContext.

    To use standard painting, the surrounding application should provide some (fullscreen) canvas like java.awt.Canvas, and call the paint()-method of the StarpointController, passing a platform specific GraphicContext-implementation.

    For platform specific sound, the StarpointContext must provide a SoundContext-implementation.

    If the StarpointGame finishes (if user selects Exit in the main menu), the StarpointContexts quit()-method is called.

    If the game should be quit by the application, call the exit()-method to store highscore list, stop the game timer and show the Credits-screen. Calling dispose() quits the UIUpdater-thread.

    • Field Detail

      • TITLE_STRING

        public static final java.lang.String TITLE_STRING
        The Main window title.
        See Also:
        Constant Field Values
      • DEBUG_TIMING

        public static final boolean DEBUG_TIMING
        DEBUG flag for console output during best move replay.
        See Also:
        Constant Field Values
      • CUSTOM_LEVEL_INIFILE

        public static final java.lang.String CUSTOM_LEVEL_INIFILE
        Filename for editor ini file.
        See Also:
        Constant Field Values
      • game

        protected Game game
        The currently played game. Is null during menu and credits.
    • Constructor Detail

      • StarpointController

        public StarpointController​(StarpointContext context)
        Constructor for the Starpoint game with default painting. Initializes game resources.
        Parameters:
        context - The surrounding application context.
    • Method Detail

      • getDisplayFigureState

        public FigureState getDisplayFigureState​(GameState state)
        Gets the figure state to display. Returns the first human player in normal game, or the client player in network game.
        Parameters:
        state - The game state.
        Returns:
        The figure state to display (if client figure cannot be found in client game, first human player is returned).
      • getHighScores

        public ScoreList getHighScores()
        Returns the high score list.
        Returns:
        The high score list
      • storeScoreList

        public void storeScoreList()
        Stores a scorelist.
      • createGameInfo

        public GameInfo createGameInfo​(int playerCount,
                                       java.lang.String levelInfoStream)
        Creates a new GameInfo for the given number of players. Any modifications on figure infos should be done before creating a game with it.
        Parameters:
        playerCount - The number fo player figures.
        levelInfoStream - The name of the Level-inifile.
        Returns:
        The GameInfo.
      • getPlayerInfo

        public FigureInfo getPlayerInfo​(int index)
        Gets the PlayerInfo for the given player index.
        Parameters:
        index - Player index.
        Returns:
        The FigureInfo.
      • createGame

        public Game createGame​(GameInfo gameInfo)
        Creates a new game in the state initialized.
        Parameters:
        gameInfo - The GameInfo
        Returns:
        The game.
      • getOptions

        public Options getOptions()
        Returns the game options.
        Returns:
        The current options setting.
      • saveOptions

        public void saveOptions()
        Saves the user specific options.
      • saveGame

        public void saveGame()
        Saves the current level and figure stati.
      • quickSaveGame

        public void quickSaveGame()
        Saves the current level and figure stati.
      • displayMessage

        public void displayMessage​(java.lang.String msg,
                                   int duration,
                                   MessagePosition pos,
                                   int c,
                                   FontSize size)
        Displays a message on the Message Painter.
        Parameters:
        msg - The message.
        duration - The duration.
        pos - The message position.
        c - The message color.
        size - The message size.
      • hideMessage

        public void hideMessage()
        Hides any message on the gui.
      • requestPlayerMoves

        public java.util.Map<java.lang.Integer,​Direction> requestPlayerMoves()
        Gets the current list of Player moves.
        Returns:
        A map of figure indices to their desired move direction.
      • hasPlayerRegisteredMove

        public boolean hasPlayerRegisteredMove()
        Checks, if a move exists for player with index 0.
        Returns:
        true, if a move exists for player with index 0.
      • requestPlayerItemUsage

        public java.util.Map<java.lang.Integer,​java.lang.Boolean> requestPlayerItemUsage()
        Gets the current list of Player item usage flags.
        Returns:
        A map of figure indices to their flag if item should be used.
      • getMode

        public StarpointMode getMode()
        Gets the GameMode.
        Returns:
        The GameMode.
      • getGame

        public Game getGame()
        Gets the game object. Returns null, if game is not running.
        Returns:
        The game.
      • getSoundFx

        public SoundFx getSoundFx()
        Gets the SoundFx.
        Returns:
        The SoundFx.
      • getContext

        public StarpointContext getContext()
        Returns the Surrounding application.
        Returns:
        The context.
      • getPainterFactory

        public PainterFactory getPainterFactory()
        Gets the PainterFactory.
        Returns:
        The PainterFactory.
      • getInitializer

        public StarpointInitializer getInitializer()
        Gets the Initializer.
        Returns:
        The Initializer.
      • start

        public void start()
        Starts Starpoints. Call this from the surrounding application to give control to the StarpointController. UI Updater is started and menu is shown.
      • quitGame

        public void quitGame()
        Quits the currently running game by setting the mode to GameQuit and stopping the Game timer thread.
      • switchToBestMoveReplay

        public void switchToBestMoveReplay()
        Switches to best move replay.
      • setOptions

        public void setOptions​(Options o)
        Sets the Guis options.
        Parameters:
        o - The options
      • resizeUI

        public void resizeUI()
        Should be called after UI resizing. Re-Layouts the painter components.
      • setMaxStartingLevel

        public void setMaxStartingLevel​(java.lang.String code)
        Sets the maximum start level when starting a new game.
        Parameters:
        code - The code.
      • getMaxStartingLevel

        public int getMaxStartingLevel()
        Gets the maximum start level when starting a new game.
        Returns:
        The max. level count
      • getMaxStartingLevelIndex

        public int getMaxStartingLevelIndex()
        Gets the maximum start level when starting a new game.
        Returns:
        The max. levels index, if maxStarting level is 0, 0 is returned.
      • showMenu

        public void showMenu()
        Shows the main menu.
      • showOptions

        public void showOptions()
        Shows the options menu.
      • pauseGame

        public void pauseGame()
        Pauses the game. Does nothing, if already paused.
      • resumeGame

        public void resumeGame()
        Resumes the game after pause. Does nothing, if not paused.
      • showGameOptions

        public void showGameOptions()
        Shows the game options menu.
      • nameEntryFinished

        public void nameEntryFinished()
        Called when name entry is finished.
      • isEnteringClientName

        public boolean isEnteringClientName()
        Checks, if currently entering name for participating in server game.
        Returns:
        true, if currently entering name for participating in server game.
      • insertHighscore

        public int insertHighscore​(Figure f,
                                   boolean finished,
                                   long gameID)
        Checks, if the figure gets a place in the high score list.
        Parameters:
        f - the figure to check.
        finished - Flag, if game was finished.
        gameID - ID of the game to prevent multiple entries after game save.
        Returns:
        The rank in the high score list, or -1 if score is too low (or if someone calls this method while no game is running).
      • exit

        public void exit()
        Exits Starpoints, saves the high score list and shows the credits.
      • isExited

        public boolean isExited()
        Checks, if controller already was exited.
        Returns:
        true, if controller already was exited.
      • dispose

        public void dispose()
        Disoses the UIUpdater thread. Should be called, if surrounding application is disposed.
      • paint

        public void paint​(GraphicContext context)
        Paints to the given GraphicContext by creating a Starpoints Graphics and painting the current painter to it.
        Parameters:
        context - The GraphicContext from the surrounding implementation.
      • getCurrentState

        public GameState getCurrentState()
        Gets the current state for display purposes.
        Returns:
        The GameState.
      • isClientGameRunning

        public boolean isClientGameRunning()
        Checks, if a client game is running.
        Returns:
        true, if a client game is running.
      • getLevelCode

        public java.lang.String getLevelCode​(int level)
        Gets the code for the level with the given number.
        Parameters:
        level - The level number
        Returns:
        The code string to get as close to the level immediatly.
      • showNetworkMenu

        public void showNetworkMenu()
        Shows the options menu.
      • startNewGame

        public void startNewGame​(int player)
        Starts a new StarpointArena game for the given player count in menu.
        Parameters:
        player - The number of human players.
      • startTutorial

        public void startTutorial()
        Starts the tutorial.
      • startLeagueGame

        public void startLeagueGame​(int player)
        Starts a new StarpointArena league for the given player count in menu.
        Parameters:
        player - The number of human players.
      • startGame

        public void startGame()
        Starts the game with the current game. To start a new (yet uninitialized) game, use startNewGame().
      • startEditor

        public void startEditor()
        Starts the editor.
      • getEditor

        public StarpointEditor getEditor()
        Gets a level editor.
        Returns:
        A level editor.
      • applyClientFigureInfos

        protected void applyClientFigureInfos()
        Applies the client player names and skins to the game player figures.
      • isClientPlayer

        public boolean isClientPlayer​(int playerIndex)
        Checks, if the player with the given index is a client player in network game.
        Parameters:
        playerIndex - The players index in the current game.
        Returns:
        true, if the player with the given index is a client player in network game. Always true, if not in server mode.
      • setPainter

        protected void setPainter​(Painter p)
        Sets the contexts's painter.
        Parameters:
        p - The painter.
      • update

        public void update()
        Called by Game updater thread after each game update.
      • skip

        protected void skip()
        Skips during level intro etc. after key press or mouse click events.
      • startNameEntry

        public void startNameEntry()
        Starts the skin selection before the game.
      • showCredits

        public void showCredits()
        Shows the credits.
      • hasAdditionalPainterRight

        public boolean hasAdditionalPainterRight()
        Checks, if space is needed between the PlayerInfoPanel (for tutorial or touchpad)
        Returns:
        true, if space is needed.
      • vibrate

        public void vibrate()
        Lets the surrounding application vibrate.
      • mouseClicked

        public void mouseClicked​(MouseEvent e)
        Reacts to mouse events from the surrounding apllication. Skips during skippable game phases, shows the game menu on right mouse click, or leaves the credits.
        Parameters:
        e - The MouseEvent.
      • isShowingBackgroundAnimation

        public boolean isShowingBackgroundAnimation()
        Checks, if background animations should be shown.
        Returns:
        true, if not clicking touchpad.
      • mouseMoved

        public void mouseMoved​(MouseEvent e)
        Reacts to mouse move events. Call this from surrounding application if a mouse move was detected.
        Parameters:
        e - The MouseEvent.
      • keyPressed

        public void keyPressed​(KeyEvent e)
        Reacts to key events. Call this from surrounding application if a mouse move was detected.
        Parameters:
        e - The KeyEvent.
      • isChessMode

        public boolean isChessMode()
        Checks, if the current game is running in (real) chess mode (Speed = Chess and 1 playr game)
        Returns:
        true, if the current game is running in (real) chess mode.
      • rotatePlayer

        public void rotatePlayer​(int playerIndex,
                                 Direction dir)
        Registers a player move in the next movement round segment.
        Parameters:
        playerIndex - The index of the PlayerFigure (0 for Player 1 aso.)
        dir - The move Direction
      • registerPlayerMove

        public void registerPlayerMove​(int playerIndex,
                                       Direction dir)
        Registers a player move in the next movement round segment.
        Parameters:
        playerIndex - The index of the PlayerFigure (0 for Player 1 aso.)
        dir - The move Direction
      • registerPlayerItemUsage

        public void registerPlayerItemUsage​(int playerIndex,
                                            boolean useItem)
        Registers a player item usage in the next movement round segment.
        Parameters:
        playerIndex - The index of the PlayerFigure (0 for Player 1 aso.)
        useItem - Flag, if item should be used.
      • registerPlayerShopItemClick

        public void registerPlayerShopItemClick​(int playerIndex,
                                                int shopItemIndex)
        Registers a player item buy during shop.
        Parameters:
        playerIndex - The index of the PlayerFigure (0 for Player 1 aso.)
        shopItemIndex - Index of the shop item to buy.
      • registerShopLeaveRequest

        public void registerShopLeaveRequest​(int playerIndex)
        Registers a player request to leave a shop.
        Parameters:
        playerIndex - The index of the PlayerFigure (0 for Player 1 aso.)
      • startSavedGameSelection

        public void startSavedGameSelection()
        Starts the selection of saved games.
      • startEditorGame

        public void startEditorGame​(int player)
        Starts a new game with the Level editors saved levelset.
        Parameters:
        player - The number of human players.
      • finishEditingGameSelection

        public void finishEditingGameSelection​(java.lang.String filename)
        Finishes the selection of the editor game to play.
        Parameters:
        filename - The selected editor file.
      • loadGame

        public void loadGame​(java.lang.String filename)
        Loads a stored game.
        Parameters:
        filename - The saved game file.
      • optionMenuFinished

        public void optionMenuFinished()
        Called, if the option menus Quit-button is clicked.
      • gameMenuFinished

        public void gameMenuFinished​(boolean quitGame)
        Called by the game menu.
        Parameters:
        quitGame - Flag, if game should be quit.
      • getNetworkHandler

        public StarpointNetworkHandler getNetworkHandler()
        Gets the network game handler.
        Returns:
        The StarpointNetworkHandler
      • getSavedGameManager

        public FileManager getSavedGameManager()
        Gets the saved games manager.
        Returns:
        The SavedGameManager
      • getLevelSetManager

        public FileManager getLevelSetManager()
        Gets the level set manager.
        Returns:
        The LevelSet Manager
      • getBestMoveManager

        public BestMoveManager getBestMoveManager()
        Gets the manager for best moves.
        Returns:
        The BestMoveManager.
      • leaveShop

        public void leaveShop()
        Call to leaves the shop during game.
      • finishSelling

        public void finishSelling()
        Call to stop selling items during game.
      • handleShopItemClick

        public void handleShopItemClick​(int index)
        Call to buy or sell shop item with given index during game.
        Parameters:
        index - The shop item index.
      • enterShop

        public void enterShop()
        Call to enter shop item with given index during game.
      • isNetworkClient

        public boolean isNetworkClient()
        Checks, if this controller is a network client.
        Returns:
        the isNetWorkClient
      • is3DGame

        public boolean is3DGame()
        Checks, if both context is supporting 3D and options are switched to 3D.
        Returns:
        the isNetWorkClient
      • isNetworkServer

        public boolean isNetworkServer()
        Checks, if this controller is a network server.
        Returns:
        true, if this controller is a network server.
      • setIsNetworkClient

        public void setIsNetworkClient​(boolean isNetWorkClient)
        Sets the client state of this controller
        Parameters:
        isNetWorkClient - Pass true, to make this controller a network client.
      • startWaitForClientGame

        public void startWaitForClientGame()
        Starts a client game, if client has received the game start message.
      • startClientGame

        public void startClientGame()
        Starts a client game, if client has received the first game message.
      • registerClientPlayerQuit

        public void registerClientPlayerQuit​(int playerIndex)
        Registers a quit message from a client during network game.
        Parameters:
        playerIndex - The client players index.
      • quitClientGameAfterServerStop

        public void quitClientGameAfterServerStop()
        Exits a client game after server stopped.