world
Class World

java.lang.Object
  |
  +--world.World
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.awt.event.KeyListener

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

The World class contains all the world management code.

It handles the events that occur when buttons are clicked or keys are pressed.

It governs the speed of the simulation and calls necessary methods of objects in the world.


Field Summary
private  java.util.ArrayList background
           
private  java.util.ArrayList characters
           
private  WinEnv environment
           
static int FPS
           
static int KEY_A
           
static int KEY_D
           
static int KEY_DOWN
           
static int KEY_LEFT
           
static int KEY_RIGHT
           
static int KEY_S
           
static int KEY_SPACE
           
static int KEY_UP
           
static int KEY_W
           
private  boolean[] keysPressed
           
static int NUM_KEYS
           
private  javax.swing.Timer timer
           
 
Constructor Summary
World()
          Creates our World, empty.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Called by timer when it's running.
 void addVehicle(AbstractVehicle av)
          Registers a moving object with the controller Duplicates are allowed.
 void addWorldObject(Background o)
          Registers a non-moving world object with the controller.
 void draw(java.awt.Graphics2D g)
          Tells the graphics system what to draw on screen by going through all the objects in the world and telling them to draw themselves.
 boolean getKeyPressed(int key)
          Tells whether a given button on the keyboard is pressed.
 java.awt.Dimension getSize()
          Return the size of this world
 java.util.ArrayList getVehicles()
          Return the list of moving objects currently registered with the controller
 void keyPressed(java.awt.event.KeyEvent e)
          Handle the key pressed event
 void keyReleased(java.awt.event.KeyEvent e)
          Handle the key released event
 void keyTyped(java.awt.event.KeyEvent e)
          Handle the key typed event
 void start()
          Handles start button
 void stop()
          Handles stop button
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

environment

private WinEnv environment

timer

private javax.swing.Timer timer

FPS

public static final int FPS
See Also:
Constant Field Values

characters

private java.util.ArrayList characters

background

private java.util.ArrayList background

keysPressed

private boolean[] keysPressed

KEY_LEFT

public static final int KEY_LEFT
See Also:
Constant Field Values

KEY_UP

public static final int KEY_UP
See Also:
Constant Field Values

KEY_RIGHT

public static final int KEY_RIGHT
See Also:
Constant Field Values

KEY_DOWN

public static final int KEY_DOWN
See Also:
Constant Field Values

KEY_A

public static final int KEY_A
See Also:
Constant Field Values

KEY_S

public static final int KEY_S
See Also:
Constant Field Values

KEY_D

public static final int KEY_D
See Also:
Constant Field Values

KEY_W

public static final int KEY_W
See Also:
Constant Field Values

KEY_SPACE

public static final int KEY_SPACE
See Also:
Constant Field Values

NUM_KEYS

public static final int NUM_KEYS
See Also:
Constant Field Values
Constructor Detail

World

public World()
Creates our World, empty.

Method Detail

stop

public void stop()
Handles stop button


start

public void start()
Handles start button


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called by timer when it's running. It goes through all our objects in the world and asks for updates. Then it asks the window to repaint itself.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the timer action that we are handling

draw

public void draw(java.awt.Graphics2D g)
Tells the graphics system what to draw on screen by going through all the objects in the world and telling them to draw themselves.

Parameters:
g - the graphics system we can use to draw things on

addWorldObject

public void addWorldObject(Background o)
Registers a non-moving world object with the controller. Duplicates are allowed.

Parameters:
o - the object to be added

addVehicle

public void addVehicle(AbstractVehicle av)
Registers a moving object with the controller Duplicates are allowed.

Parameters:
av - the object to be added

getVehicles

public java.util.ArrayList getVehicles()
Return the list of moving objects currently registered with the controller

Returns:
the arraylist of abstract vehicles

getSize

public java.awt.Dimension getSize()
Return the size of this world

Returns:
Dimension with width and height of the world

getKeyPressed

public boolean getKeyPressed(int key)
Tells whether a given button on the keyboard is pressed. Only a subset of the keys are currently being monitored.

Parameters:
key - the keycode of the button
Returns:
true if the button is currently down and false if the buttone is up

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Handle the key typed event

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

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Handle the key pressed event

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

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Handle the key released event

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