|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvooga.engine.player.control.Control
public class Control
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 |
---|
protected java.util.List<GameEntitySprite> entities
protected java.lang.Class<?>[] paramTypes
protected Game myGame
Constructor Detail |
---|
public Control()
public Control(Game game)
game
- The game which this Control object is a part ofpublic Control(GameEntitySprite initialPlayer, Game game)
initialPlayer
- First player to add to use this control schemegame
- The game which this Control object is a part ofpublic Control(java.util.ArrayList<GameEntitySprite> players, Game game)
players
- Initial players to use this schemegame
- The game which this Control object is a part ofMethod Detail |
---|
public void setParams(java.lang.Class<?>... parameterTypes)
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})public void update()
public void addInput(int listen, java.lang.String method, java.lang.String classname, java.lang.Object... paramVals)
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.public void initializeMappings()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |