Class GameManager

java.lang.Object
  extended by GameManager
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.KeyListener, java.lang.Runnable, java.util.EventListener

public class GameManager
extends java.lang.Object
implements java.awt.event.KeyListener, java.awt.event.ActionListener, java.lang.Runnable

This class creates and manages the grid in which all the players reside. This class also manages the controls of each and every player in the game. Implements KeyListener in order to listen to the input controls of each player. Images stolen from: http://tsgk.captainn.net/?p=showsheets&t=sr&sr=121


Field Summary
private  java.util.ArrayList<AI> aiList
           
private  javax.swing.JButton begin
           
private  GUI bommenwerper
           
private  Grid g
           
private  AnimationGrid gridApp
           
private  int[][] keystrokes
           
private  java.util.TreeMap<java.lang.Integer,java.lang.Integer> moveMap
           
private  javax.swing.JLabel p1Label
           
private  int p1Score
           
private  javax.swing.JLabel p2Label
           
private  int p2Score
           
private  javax.swing.JLabel p3Label
           
private  int p3Score
           
private  javax.swing.JLabel p4Label
           
private  int p4Score
           
private  Player player1
           
private  Player player2
           
private  Player player3
           
private  Player player4
           
private  java.util.TreeMap<java.lang.Integer,Player> playerMap
           
private  java.util.Set<java.lang.Integer> pressed
           
private  javax.swing.JLabel roundLabel
           
private  int roundNumber
           
private  java.util.Timer roundTimer
           
private  Settings set
           
private  java.lang.Thread t
           
private  boolean threadRunning
           
private  javax.swing.JLabel timeLabel
           
private  long timeStarted
           
 
Constructor Summary
GameManager(GUI gui, Settings set)
          Initializes the scores of each player to 0.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Listens for the button actions.
 void endRound()
          Ends the round.
 void gameGui()
          Creates the playing field.
private  boolean gameOver()
          Returns true if there is one or no Players alive.
 Grid getGrid()
          Used for testing purposes only.
private  void initBoxes()
          Randomly places boxes into the grid.
private  void initGrid()
          Initializes and places everything into the grid that is necessary.
private  void initPlayers()
          Places players into the grid based on how many are human and how many are computer players.
private  void initWalls()
          Places the necessary walls into the grid.
 void keyPressed(java.awt.event.KeyEvent arg0)
          Checks to see which key was pressed, and moves the corresponding player appropriately.
 void keyReleased(java.awt.event.KeyEvent arg0)
          removes the keycode from the currently pressed set.
 void keyTyped(java.awt.event.KeyEvent arg0)
           
 void makeMove(int player, int control)
          Makes the move of the player.
 void run()
          First law of Bommenwerper: A Player in motion will remain in motion unless acted upon by a keyReleasedActionEvent.
 void startRound()
          This method begins the next round by starting the timer, increasing round number, starting the input thread, and changing the button text.
 java.lang.Boolean threadRunning()
          Used for testing purposes only.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

g

private Grid g

bommenwerper

private GUI bommenwerper

begin

private javax.swing.JButton begin

p1Score

private int p1Score

p2Score

private int p2Score

p3Score

private int p3Score

p4Score

private int p4Score

p1Label

private javax.swing.JLabel p1Label

p2Label

private javax.swing.JLabel p2Label

p3Label

private javax.swing.JLabel p3Label

p4Label

private javax.swing.JLabel p4Label

timeLabel

private javax.swing.JLabel timeLabel

roundNumber

private int roundNumber

roundLabel

private javax.swing.JLabel roundLabel

roundTimer

private java.util.Timer roundTimer

keystrokes

private int[][] keystrokes

gridApp

private AnimationGrid gridApp

player1

private Player player1

player2

private Player player2

player3

private Player player3

player4

private Player player4

playerMap

private java.util.TreeMap<java.lang.Integer,Player> playerMap

moveMap

private java.util.TreeMap<java.lang.Integer,java.lang.Integer> moveMap

pressed

private final java.util.Set<java.lang.Integer> pressed

t

private java.lang.Thread t

timeStarted

private long timeStarted

threadRunning

private boolean threadRunning

aiList

private java.util.ArrayList<AI> aiList

set

private Settings set
Constructor Detail

GameManager

public GameManager(GUI gui,
                   Settings set)
Initializes the scores of each player to 0. Sets up the keys that it has to pay attention to based on how many players are set in the settings. Creates and draws the grids and the players.

Parameters:
gui - the GUI of the window
set - Settings of the game
Method Detail

initGrid

private void initGrid()
Initializes and places everything into the grid that is necessary.


initBoxes

private void initBoxes()
Randomly places boxes into the grid.


initWalls

private void initWalls()
Places the necessary walls into the grid.


initPlayers

private void initPlayers()
Places players into the grid based on how many are human and how many are computer players.


gameGui

public void gameGui()
Creates the playing field. The window is 800 x 600 px, the playing field is 13 by 9 squares. Each square is 55px x 55px to add up to a playing field of 715px x 495px.


makeMove

public void makeMove(int player,
                     int control)
Makes the move of the player.

Parameters:
player - The player to move.
control - The direction / fire that the player needs to do.

keyPressed

public void keyPressed(java.awt.event.KeyEvent arg0)
Checks to see which key was pressed, and moves the corresponding player appropriately. Adds the keycode into the currently pressed set.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent arg0)
removes the keycode from the currently pressed set.

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent arg0)
Specified by:
keyTyped in interface java.awt.event.KeyListener

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Listens for the button actions.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

startRound

public void startRound()
This method begins the next round by starting the timer, increasing round number, starting the input thread, and changing the button text.


endRound

public void endRound()
Ends the round. Adds up scores of each player and sets things up for the next round.


run

public void run()
First law of Bommenwerper: A Player in motion will remain in motion unless acted upon by a keyReleasedActionEvent. This method calls all the ais to think and changes the time, and tells the players to move.

Specified by:
run in interface java.lang.Runnable

gameOver

private boolean gameOver()
Returns true if there is one or no Players alive.

Returns:
true if there is one or no Players alive.

getGrid

public Grid getGrid()
Used for testing purposes only.

Returns:
Grid that the gameManager manages.

threadRunning

public java.lang.Boolean threadRunning()
Used for testing purposes only.

Returns:
The thread.