vooga.engine.player.control
Class Control

java.lang.Object
  extended by vooga.engine.player.control.Control

public class Control
extends java.lang.Object

Control class which can be used to create control schemes. Can also be extended to create alternate schemes (for AI, control pads, etc) Control takes one or more Players and registers actions that those Players will perform if an event occurs from some predetermined input device. If the programmer is just trying to use the keyboard and mouse listening capabilties, they can do: Control shipControl = new Control(this); //this is inside of a Player class. shipControl.setParams(new Class[]{int.class}); //Tells Control to expect a single int parameter. shipControl.addInput("KEYBOARD", "left", "rotateLeft", "Ship", 10); //Registers the left key to trigger rotateLeft with a parameter of 10. shipControl.act(); //Within Player's act method. Tells Control to check the registered events and see if any have occurred.


Field Summary
protected  java.util.List<GameEntitySprite> entities
           
protected  Game myGame
           
protected  java.lang.Class<?>[] paramTypes
           
 
Constructor Summary
Control()
          Default Control Constructor
Control(java.util.ArrayList<GameEntitySprite> players, Game game)
          Constructor that can add multiple players initially
Control(Game game)
          Control Constructor with only a Game declared
Control(GameEntitySprite initialPlayer, Game game)
          Constructor which can add an intial player to the scheme
 
Method Summary
 void addInput(int listen, java.lang.String method, java.lang.String classname, java.lang.Object... paramVals)
          Create keyset to map input to method.
 void initializeMappings()
           
 void setParams(java.lang.Class<?>... parameterTypes)
          Sets the parameter types that need to be used for the next method
 void update()
          Invoke methods here.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entities

protected java.util.List<GameEntitySprite> entities

paramTypes

protected java.lang.Class<?>[] paramTypes

myGame

protected Game myGame
Constructor Detail

Control

public Control()
Default Control Constructor


Control

public Control(Game game)
Control Constructor with only a Game declared

Parameters:
game - The game which this Control object is a part of

Control

public Control(GameEntitySprite initialPlayer,
               Game game)
Constructor which can add an intial player to the scheme

Parameters:
initialPlayer - First player to add to use this control scheme
game - The game which this Control object is a part of

Control

public Control(java.util.ArrayList<GameEntitySprite> players,
               Game game)
Constructor that can add multiple players initially

Parameters:
players - Initial players to use this scheme
game - The game which this Control object is a part of
Method Detail

setParams

public void setParams(java.lang.Class<?>... parameterTypes)
Sets the parameter types that need to be used for the next method

Parameters:
parameterTypes - The types of parameters that need to be used. Need to be implemented in the form setParams(new Class[]{Class cls}) eg. player.setParams(new Class[]{int.class, double.class})

update

public void update()
Invoke methods here. Call method each time through game loop


addInput

public void addInput(int listen,
                     java.lang.String method,
                     java.lang.String classname,
                     java.lang.Object... paramVals)
Create keyset to map input to method. Can be overwritten to create new control scheme

Parameters:
listen - Use an Integer version of what to listen to (eg. Java.awt.event.KeyEvent constants for "KEYBOARD" or Java.awt.event.MouseEvent constants for "MOUSE")
method - Name of method to map to (do not include brackets)
classname - Name of class that wants to use this (eg. "Player" or "Game") NOTE: You must put the class's fully qualified name (including its package) For example: if a class is called Test and is in the package cps108.games.example then the String here must be "cps108.games.example.Test"
paramVals - Value of the parameters that the method has NOTE: If you want to use this parameter with something other than 'null', you must use setParams first.

initializeMappings

public void initializeMappings()