All Packages Class Hierarchy This Package Previous Next Index
Class com.monpetitcoin.java.PrisonerGame.PrisonerGame
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----com.monpetitcoin.java.PrisonerGame.PrisonerGame
- public class PrisonerGame
- extends java.awt.Panel
- implements java.awt.event.ActionListener, java.lang.Runnable
This class is the core of the Prisoner's Dilemma game application. It instantiates the
game boards and all its cells and runs the game. It also manages all the options.
Several inner classes are used for elements of the UI.
- Version:
- 1.00, 14 August 2001
- Author:
- François Suter
-
PrisonerGame.GameController
- This inner class is used to display the game parameters:
- current game turn
- game board display refresh frequency
- size of the board (rows and columns)
- incentive and behavior change threshold
- color codes for honest and dishonest behaviors
This is all done in the paint() method.
-
PrisonerGame.OptionsDialog
- This inner class displays a dialog box with the options of a Prisoner's Dilemma game that can be set by the user, i.e.
-
boardConstraints
-
-
buttonsWidth
-
-
cheatColor
-
-
controller
-
-
controllerHeight
-
-
DEFAULT_BOARDSIZE
-
-
DEFAULT_INCENTIVE
-
-
DEFAULT_REFRESH_FREQUENCY
-
-
DEFAULT_THRESHOLD
-
-
gameSize
-
-
gameStopped
-
-
gridbag
-
-
helpButton
-
-
honestColor
-
-
lightGray
-
-
optionsButton
-
-
refreshFrequency
-
-
restartButton
-
-
startButton
-
-
stepButton
-
-
theBoard
-
-
theDialog
-
-
theIncentive
-
-
theThread
-
-
theThreshold
-
-
turnCounter
-
-
PrisonerGame(int, int)
-
-
PrisonerGame(int, int, double, double)
-
-
PrisonerGame(int, int, int, int)
-
-
PrisonerGame(int, int, int, int, double, double)
-
-
actionPerformed(ActionEvent)
-
-
gameTurn()
- This method performs a single game turn of the Prisoner's Dilemma.
-
getMinimumSize()
-
-
getPreferredSize()
-
-
isStopped()
- This method returns the value of the gameStopped flag.
-
restartGame(int, int, double, double)
- This method creates a new game with the parameters passed to it.
-
run()
-
-
setControls()
- This method complements the constructors, by setting up all the necessary controls.
-
setRefreshFrequency(int)
- This methods set the refresh frequency to a new value.
-
startGame()
- This methods gets the Prisoner's Dilemma game running.
-
stopGame()
- This method stops the game by setting the gameStopped flag to true.
DEFAULT_INCENTIVE
public static final double DEFAULT_INCENTIVE
DEFAULT_THRESHOLD
public static final double DEFAULT_THRESHOLD
DEFAULT_BOARDSIZE
public static final int DEFAULT_BOARDSIZE
DEFAULT_REFRESH_FREQUENCY
public static final int DEFAULT_REFRESH_FREQUENCY
theBoard
private com.monpetitcoin.java.PrisonerGame.Square2DBoard theBoard
theThreshold
private double theThreshold
theIncentive
private double theIncentive
gameSize
private java.awt.Dimension gameSize
gameStopped
private boolean gameStopped
turnCounter
private int turnCounter
refreshFrequency
private int refreshFrequency
startButton
private java.awt.Button startButton
stepButton
private java.awt.Button stepButton
restartButton
private java.awt.Button restartButton
optionsButton
private java.awt.Button optionsButton
helpButton
private java.awt.Button helpButton
controller
private com.monpetitcoin.java.PrisonerGame.PrisonerGame.GameController controller
controllerHeight
private int controllerHeight
buttonsWidth
private int buttonsWidth
theDialog
private com.monpetitcoin.java.PrisonerGame.PrisonerGame.OptionsDialog theDialog
lightGray
private java.awt.Color lightGray
honestColor
protected java.awt.Color honestColor
cheatColor
protected java.awt.Color cheatColor
boardConstraints
private java.awt.GridBagConstraints boardConstraints
gridbag
private java.awt.GridBagLayout gridbag
theThread
private java.lang.Thread theThread
PrisonerGame
public PrisonerGame(int width,
int height)
PrisonerGame
public PrisonerGame(int width,
int height,
int columns,
int rows)
PrisonerGame
public PrisonerGame(int width,
int height,
double incentive,
double threshold)
PrisonerGame
public PrisonerGame(int width,
int height,
int columns,
int rows,
double incentive,
double threshold)
setControls
private void setControls()
- This method complements the constructors, by setting up all the necessary controls.
Two gridbag layouts are used: one to contain the board, the game controller and the container
that holds all the buttons. The latter has its own gridbag layout.
- See Also:
- com.monpetitcoin.java.PrisonerGame.PrisonerGame.GameController
startGame
private void startGame()
- This methods gets the Prisoner's Dilemma game running.
It does so by setting the flag gameStopped to false and by starting a new thread with the PrisonerGame
object itself as a parameter.
- See Also:
- stopGame
stopGame
private synchronized void stopGame()
- This method stops the game by setting the gameStopped flag to true.
This causes to run() method to return, thereby killing the thread in which the game executes.
- See Also:
- startGame
restartGame
private void restartGame(int newColumns,
int newRows,
double newIncentive,
double newThreshold)
- This method creates a new game with the parameters passed to it.
The current board is destroyed and a new one created, with a new population of prisoner, which
means a new random distribution (even if the parameters haven't changed, as is the case when a
user presses the "Restart" button.
- See Also:
- actionPerformed
gameTurn
private void gameTurn()
- This method performs a single game turn of the Prisoner's Dilemma.
Using the GameBoard's enumeration capabilities, each prisoner is asked to bartner with its neighbors
and then to evaluate its results. Since the board actually stores Pawns, it is necessary to cast them to Prisoners.
- See Also:
- com.monpetitcoin.java.GameBoard, com.monpetitcoin.java.Pawn, com.monpetitcoin.java.Prisoner
setRefreshFrequency
public synchronized void setRefreshFrequency(int newFrequency)
- This methods set the refresh frequency to a new value.
isStopped
private synchronized boolean isStopped()
- This method returns the value of the gameStopped flag.
It is synchronized so as not to have a race condition with the run() method.
getPreferredSize
public java.awt.Dimension getPreferredSize()
- Overrides:
- getPreferredSize in class java.awt.Container
getMinimumSize
public java.awt.Dimension getMinimumSize()
- Overrides:
- getMinimumSize in class java.awt.Container
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
run
public void run()
All Packages Class Hierarchy This Package Previous Next Index