public class CustomEvent extends Event
onCustomEvent()
when a custom condition is met. Be sure to reset or remove
the custom condition to avoid having it recurring repeatedly (see the
example for the getCondition()
method.getCondition()
,
Serialized FormConstructor and Description |
---|
CustomEvent(Condition condition)
Called by the game to create a new CustomEvent when a condition is met.
|
CustomEvent(Condition condition,
int priority)
Called by the game to create a new CustomEvent when a condition is met.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Event event)
Compares this event to another event regarding precedence.
|
Condition |
getCondition()
Returns the condition that fired, causing this event to be generated.
|
int |
getPriority()
Returns the priority of this event.
|
getTime, setPriority, setTime
public CustomEvent(Condition condition)
condition
- the condition that must be metpublic CustomEvent(Condition condition, int priority)
This is equivalent to calling Condition.setPriority(int)
on the
Condition.
condition
- the condition that must be metpriority
- the priority of the conditionpublic Condition getCondition()
public void onCustomEvent(CustomEvent event) { if (event.getCondition().getName().equals("mycondition")) { removeCustomEvent(event.getCondition()); // do something else } }
public final int compareTo(Event event)
This method will first compare the time of each event. If the event time is the same for both events, then this method compared the priority of each event. If the event priorities are equals, then this method will compare the two event based on specific event information.
This method is called by the game in order to sort the event queue of a robot to make sure the events are listed in chronological order.
compareTo
in interface Comparable<Event>
compareTo
in class Event
event
- the event to compare to this event.public final int getPriority()
An event priority is a value from 0 - 99. The higher value, the higher priority.
The default priority is 80, but varies depending on the type of event.
getPriority
in class Event
Copyright © 2021 Robocode. All Rights Reserved.