Holger's
Java API

com.antelmann.game
Class JDefaultGame

java.lang.Object
  extended by com.antelmann.game.JDefaultGame
All Implemented Interfaces:
JGamePlay
Direct Known Subclasses:
JAwari, JBlackJack, JCheckers, JChess, JFourWins, JGomoku, JMuehle, JReversi, JSolitaire, JWS

public class JDefaultGame
extends Object
implements JGamePlay

JDefaultGame provides a basic wrapper for GamePlay objects for implementing the JGamePlay interface. JDefaultGame enables any GamePlay to be played with a JGameFrame if the game has no specific requirements for its display (or you can extend this class to ease the implementation of the interface). JDefaultGame relies on proper toString() methods to be set for the game and its moves; it further requires that a default constructor with no arguments is accessible from this class. Also, the GamePlay and all its associated objects must be serializable for game saving/loading.

Author:
Holger Antelmann
See Also:
JGameFrame, JGamePlay

Field Summary
protected  ExtensionFileFilter filter
           
protected  GameGUI frame
           
protected  AutoPlay play
           
 
Fields inherited from interface com.antelmann.game.JGamePlay
gameFrameX, gameFrameY, historyFrameX, historyFrameY, legalMovesFrameX, legalMovesFrameY, prototypeCellValue, redoFrameX, redoFrameY, windowHeight, windowLocationX, windowLocationY, windowWidth
 
Constructor Summary
JDefaultGame(GamePlay game)
           
JDefaultGame(GamePlay game, Player[] player, int level, ExtensionFileFilter filter)
           
 
Method Summary
 AutoPlay getAutoPlay()
          AutoPlay() returns the underlying game - to allow the calling functions to perform operations on the game itself.
 Container getContainer(GameGUI frame)
          takes the toString() function of the GamePlay and turns it into formatted html, which is returned as a JLabel
 String getDefaultFileExtension()
          getDefaultFileExtension() defines the String used as a file type when saving files; it should correspond to getFileFlter.
 FileFilter getFileFilter()
          getFileFilter() provides the option to filter for certain file types when saving or loading games.
 Container getHelp()
          returns null if not overridden
 JMenu getMenu()
          returns null if not overridden
 JGamePlay getNewGame()
          depends on a default constructor being accessible for the GamePlay object in question
 String getStatusMessage()
          indicates the number of moves performed, number of legal moves available, and indicates if someone won the game.
 String getTitle()
          returns getGameName() from the GamePlay object
protected  void setFileFilter(ExtensionFileFilter filter)
           
 JGamePlay setGame(AutoPlay play)
          setGame(AbstractGameBoard board) returns a JGamePlay object that embedds the given AutoPlay game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frame

protected GameGUI frame

play

protected AutoPlay play

filter

protected ExtensionFileFilter filter
Constructor Detail

JDefaultGame

public JDefaultGame(GamePlay game)

JDefaultGame

public JDefaultGame(GamePlay game,
                    Player[] player,
                    int level,
                    ExtensionFileFilter filter)
Method Detail

getContainer

public Container getContainer(GameGUI frame)
takes the toString() function of the GamePlay and turns it into formatted html, which is returned as a JLabel

Specified by:
getContainer in interface JGamePlay
Parameters:
frame - the object to be used to alter the game status by using the interface

getAutoPlay

public AutoPlay getAutoPlay()
Description copied from interface: JGamePlay
AutoPlay() returns the underlying game - to allow the calling functions to perform operations on the game itself.

Specified by:
getAutoPlay in interface JGamePlay

getFileFilter

public FileFilter getFileFilter()
Description copied from interface: JGamePlay
getFileFilter() provides the option to filter for certain file types when saving or loading games.

Specified by:
getFileFilter in interface JGamePlay

setFileFilter

protected void setFileFilter(ExtensionFileFilter filter)

getDefaultFileExtension

public String getDefaultFileExtension()
Description copied from interface: JGamePlay
getDefaultFileExtension() defines the String used as a file type when saving files; it should correspond to getFileFlter. Example: if getDefaultFileExtension() returns "test" and the user doesn't enter a file extension for the game to save but simply "game1", then the file saved will be name "game1.test".

Specified by:
getDefaultFileExtension in interface JGamePlay

getMenu

public JMenu getMenu()
returns null if not overridden

Specified by:
getMenu in interface JGamePlay

getNewGame

public JGamePlay getNewGame()
depends on a default constructor being accessible for the GamePlay object in question

Specified by:
getNewGame in interface JGamePlay

setGame

public JGamePlay setGame(AutoPlay play)
                  throws GameRuntimeException
Description copied from interface: JGamePlay
setGame(AbstractGameBoard board) returns a JGamePlay object that embedds the given AutoPlay game. This function enables the JGameFrame to load a game and transform it into a JGamePlay in a game specific way. If the given board doesn't match the implementation of JGamePlay, an exception is thrown.

Specified by:
setGame in interface JGamePlay
Throws:
GameRuntimeException

getTitle

public String getTitle()
returns getGameName() from the GamePlay object

Specified by:
getTitle in interface JGamePlay
See Also:
GamePlay.getGameName()

getStatusMessage

public String getStatusMessage()
indicates the number of moves performed, number of legal moves available, and indicates if someone won the game.

Specified by:
getStatusMessage in interface JGamePlay

getHelp

public Container getHelp()
returns null if not overridden

Specified by:
getHelp in interface JGamePlay


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads