|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvooga.engine.control.Control
public class Control
Control class which can be extended to create control schemes. Keyboard and mouse control are already packaged subclasses, but this class can also be
extended to control GameEntitySprites with an AI, joystick, network, etc.
Control takes one or more GameEntitySprites and registers actions that those sprites will perform if an event occurs from some predetermined input device.
If the programmer is just trying to use the built in keyboard or mouse listening capabilties, they can do the following:
Field Summary | |
---|---|
protected java.util.List<java.lang.Object> |
entities
|
protected int |
key
|
protected java.util.Map<java.lang.Integer,java.util.ArrayList<java.lang.reflect.Method>> |
methodMap
|
protected java.util.Map<java.lang.Integer,java.util.ArrayList<java.lang.reflect.Method[]>> |
methodParamMap
|
protected Game |
myGame
|
protected java.util.Map<java.lang.Integer,java.util.ArrayList<java.lang.Object[]>> |
paramMap
|
protected java.lang.Class<?>[] |
paramTypes
|
Constructor Summary | |
---|---|
Control()
Default Control Constructor |
|
Control(Game game)
Control Constructor with only a Game declared |
|
Control(java.util.List<java.lang.Object> players,
Game game)
Constructor that can add multiple players initially |
|
Control(java.lang.Object initialPlayer,
Game game)
Constructor which can add an initial player to the scheme |
Method Summary | |
---|---|
void |
addInput(int listen,
java.lang.String method,
java.lang.String classname,
java.lang.Class<?>... paramTypes)
Create keyset to map input to method. |
void |
changeKey(int previousKey,
int newKey)
Change the input corresponding to a set of actions to a different input. |
void |
initializeMappings()
Initialize the mappings of inputs to methods and inputs to the methods parameters. |
void |
setParams(int listen,
java.lang.Class<?> paramClass,
java.lang.reflect.Method... paramValues)
Sets the parameter values that need to be used for a method |
void |
setParams(int listen,
java.lang.Object... paramValues)
Sets the parameter values that need to be used for a method |
void |
update()
|
void |
update(int key)
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<java.lang.Object> entities
protected java.lang.Class<?>[] paramTypes
protected Game myGame
protected java.util.Map<java.lang.Integer,java.util.ArrayList<java.lang.reflect.Method>> methodMap
protected java.util.Map<java.lang.Integer,java.util.ArrayList<java.lang.Object[]>> paramMap
protected java.util.Map<java.lang.Integer,java.util.ArrayList<java.lang.reflect.Method[]>> methodParamMap
protected int key
Constructor Detail |
---|
public Control()
public Control(Game game)
game
- The game which this Control object is a part ofpublic Control(java.lang.Object 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.List<java.lang.Object> players, Game game)
players
- Initial players to use this schemegame
- The game which this Control object is a part ofMethod Detail |
---|
public void setParams(int listen, java.lang.Object... paramValues)
listen
- The key which the method listens forparamValues
- The value of the parameters (eg. "Shoot", 10, etc.)public void setParams(int listen, java.lang.Class<?> paramClass, java.lang.reflect.Method... paramValues)
listen
- The key which the method listens forparamClass
- The class which the method belongs toparamValues
- The method which can be used as the value of the parameter. The method MUST
return an object needed for the method's parameters. (eg. getMouseX(), getCurrentLevel(), etc.)public void update(int key)
public void update()
public void addInput(int listen, java.lang.String method, java.lang.String classname, java.lang.Class<?>... paramTypes)
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"paramTypes
- Class type that the parameters must be for the method (previously set with setParams() method.
For example: String.class, int.class, etc.public void initializeMappings()
public void changeKey(int previousKey, int newKey)
previousKey
- the previous inputnewKey
- the new input
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |