Package robocode
Class Condition
java.lang.Object
robocode.Condition
- Direct Known Subclasses:
GunTurnCompleteCondition
,MoveCompleteCondition
,RadarTurnCompleteCondition
,TurnCompleteCondition
Condition is used to define custom
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
)- Author:
- Mathew A. Nelson (original), Flemming N. Larsen (contributor), Nathaniel Troutman (contributor)
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new, unnamed Condition with the default priority, which is 80.Creates a new Condition with the specified name, and default priority, which is 80.Creates a new Condition with the specified name and priority. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Called by the system in order to clean up references to internal objects.getName()
Returns the name of this condition.final int
Returns the priority of this condition.void
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.
-
Field Details
-
priority
public int priorityThe priority of this condition. Defaults to 80. -
name
The name of this condition.
-
-
Constructor Details
-
Condition
public Condition()Creates a new, unnamed Condition with the default priority, which is 80. -
Condition
Creates a new Condition with the specified name, and default priority, which is 80.- Parameters:
name
- the name for the new Condition
-
Condition
Creates a new Condition with the specified name and priority. A condition priority is a value from 0 - 99. The higher value, the higher priority. The default priority is 80.- Parameters:
name
- the name for the new conditionpriority
- the priority of the new condition
-
-
Method Details
-
getName
Returns the name of this condition.- Returns:
- the name of this condition
-
getPriority
public final int getPriority()Returns the priority of this condition. A condition priority is a value from 0 - 99. The higher value, the higher priority. The default priority is 80.- Returns:
- the priority of this condition
-
setName
Sets the name of this condition.- Parameters:
newName
- the new name of this condition
-
setPriority
public void setPriority(int newPriority) Sets the priority of this condition. A condition priority is a value from 0 - 99. The higher value, the higher priority. The default priority is 80.- Parameters:
newPriority
- the new priority of this condition.
-
test
public abstract boolean test()Overriding the test() method is the point of a Condition. The game will call your test() function, and take action if it returnstrue
. This is valid for bothAdvancedRobot.waitFor(robocode.Condition)
andAdvancedRobot.addCustomEvent(robocode.Condition)
.You may not take any actions inside of test().
- Returns:
true
if the condition has been met,false
otherwise.
-
cleanup
public void cleanup()Called by the system in order to clean up references to internal objects.- Since:
- 1.4.3
-