|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--robocode.Condition
Condition is used to define custom waitFor
and
custom events for a AdvancedRobot
. The code below is taken from
the sample robot named Target. See Target.java for details.
addCustomEvent( new Condition("triggerhit") { public boolean test() { return (getEnergy() <= trigger); }; } );You should note that by extending Condition, you are actually creating an inner class -- so if you distribute your robot, there will be multiple class files. (i.e. Target$1.class)
AdvancedRobot.waitFor(robocode.Condition)
,
AdvancedRobot.addCustomEvent(robocode.Condition)
,
AdvancedRobot.removeCustomEvent(robocode.Condition)
,
AdvancedRobot.onCustomEvent(robocode.CustomEvent)
Field Summary | |
String |
name
The name of this condition |
int |
priority
The priority of this condition. |
Constructor Summary | |
Condition()
Creates a new, unnamed Condition with the default priority. |
|
Condition(String name)
Creates a new Condition with the specified name, and default priority. |
|
Condition(String name,
int priority)
Creates a new Condition with the specified name and priority. |
Method Summary | |
String |
getName()
|
int |
getPriority()
|
void |
setName(String newName)
Sets the name of this condition |
void |
setPriority(int newPriority)
Sets the priority of this condition |
abstract boolean |
test()
Overriding the test() method is the point of a Condition. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public int priority
public String name
Constructor Detail |
public Condition()
public Condition(String name)
public Condition(String name, int priority)
Method Detail |
public String getName()
public int getPriority()
public void setName(String newName)
newName
- java.lang.Stringpublic void setPriority(int newPriority)
newPriority
- intpublic abstract boolean test()
waitFor
and addCustomEvent
.
You may not take any actions inside of test().
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |