Class CarGameController

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

public class CarGameController
extends java.lang.Thread
implements java.awt.event.KeyListener

This class represents a thread which runs the car game.

Author:
Dalibor Zeleny (dalibor@cs.wisc.edu)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int KEY_DOWN
          Position of the DOWN key press indicator in the array of keystrokes
static int KEY_LEFT
          Position of the LEFT key press indicator in the array of keystrokes
static int KEY_RIGHT
          Position of the RIGHT key press indicator in the array of keystrokes
static int KEY_UP
          Position of the UP key press indicator in the array of keystrokes
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CarGameController(CarGame game)
          Creates a controller for the specified CarGame object.
 
Method Summary
 CarGame getGame()
          Returns a reference to the CarGame object this instance is controlling.
 boolean getPaused()
          Indicates whether the game is paused
 boolean getQuit()
          Indicates whether the player wants to quit.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void run()
          Runs the game until the player chooses to quit.
 void setPaused(boolean paused)
          Sets whether the game should be paused
 void setViewer(CarGameGUI v)
          Sets the reference to the CarGameGUI object that will display the game's state.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_UP

public static int KEY_UP
Position of the UP key press indicator in the array of keystrokes


KEY_RIGHT

public static int KEY_RIGHT
Position of the RIGHT key press indicator in the array of keystrokes


KEY_DOWN

public static int KEY_DOWN
Position of the DOWN key press indicator in the array of keystrokes


KEY_LEFT

public static int KEY_LEFT
Position of the LEFT key press indicator in the array of keystrokes

Constructor Detail

CarGameController

public CarGameController(CarGame game)
Creates a controller for the specified CarGame object.

Parameters:
game - The game to control.
Method Detail

setViewer

public void setViewer(CarGameGUI v)
Sets the reference to the CarGameGUI object that will display the game's state.

Parameters:
v - The viewer that will display the game's state.

getPaused

public boolean getPaused()
Indicates whether the game is paused

Returns:
whether the game is paused

setPaused

public void setPaused(boolean paused)
Sets whether the game should be paused

Parameters:
paused - true if the game should be paused, false if the game should be running.

getGame

public CarGame getGame()
Returns a reference to the CarGame object this instance is controlling.

Returns:
a reference to the CarGame object this instance is controlling.

getQuit

public boolean getQuit()
Indicates whether the player wants to quit.

Returns:
whether the player wants to quit.

run

public void run()
Runs the game until the player chooses to quit.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

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