|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrobocode.Condition
public abstract class Condition
Condition is used to define custom AdvancedRobot#waitFor 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 this way, 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 | |
---|---|
java.lang.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, which is 80. |
|
Condition(java.lang.String name)
Creates a new Condition with the specified name, and default priority, which is 80. |
|
Condition(java.lang.String name,
int priority)
Creates a new Condition with the specified name and priority. |
Method Summary | |
---|---|
java.lang.String |
getName()
Returns the name of this condition. |
int |
getPriority()
Returns the priority of this condition. |
void |
setName(java.lang.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 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int priority
public java.lang.String name
Constructor Detail |
---|
public Condition()
public Condition(java.lang.String name)
name
- the name for the new Conditionpublic Condition(java.lang.String name, int priority)
name
- the name for the new conditionpriority
- the priority of the new conditionMethod Detail |
---|
public java.lang.String getName()
public int getPriority()
public void setName(java.lang.String newName)
newName
- the new name of this conditionpublic void setPriority(int newPriority)
newPriority
- the new priority of this condition.public abstract boolean test()
true
. This is valid for both AdvancedRobot.waitFor(robocode.Condition)
and
AdvancedRobot.addCustomEvent(robocode.Condition)
.
You may not take any actions inside of test().
true
if the condition has been met, false
otherwise.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |