public abstract class Condition extends Object
waitFor(Condition) and custom events for an AdvancedRobot. The code
below is taken from the sample robot named sample.Target. See the
sample/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(Condition),
AdvancedRobot.addCustomEvent(Condition),
AdvancedRobot.removeCustomEvent(Condition),
AdvancedRobot.onCustomEvent(CustomEvent)| Modifier and Type | Field and Description |
|---|---|
String |
name
The name of this condition.
|
int |
priority
The priority of this condition.
|
| Constructor and Description |
|---|
Condition()
Creates a new, unnamed Condition with the default priority, which is 80.
|
Condition(String name)
Creates a new Condition with the specified name, and default priority,
which is 80.
|
Condition(String name,
int priority)
Creates a new Condition with the specified name and priority.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cleanup()
Called by the system in order to clean up references to internal objects.
|
String |
getName()
Returns the name of this condition.
|
int |
getPriority()
Returns the priority of this condition.
|
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.
|
public int priority
public String name
public Condition()
public Condition(String name)
name - the name for the new Conditionpublic Condition(String name, int priority)
name - the name for the new conditionpriority - the priority of the new conditionpublic String getName()
public final int getPriority()
public void setName(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.public void cleanup()
Copyright © 2021 Robocode. All Rights Reserved.