|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrobocode._RobotBase
robocode._Robot
robocode.Robot
robocode._AdvancedRobot
robocode._AdvancedRadiansRobot
robocode.AdvancedRobot
robocode.TeamRobot
public class TeamRobot
An advanced type of robot that supports sending messages between team mates in a robot team.
If you have not done already, you should create aRobot
or
AdvancedRobot
first.
JuniorRobot
,
Robot
,
AdvancedRobot
,
Droid
Field Summary |
---|
Fields inherited from class robocode._RobotBase |
---|
out |
Constructor Summary | |
---|---|
TeamRobot()
|
Method Summary | |
---|---|
void |
broadcastMessage(Serializable message)
Broadcasts a message to all teammates. |
Vector<MessageEvent> |
getMessageEvents()
Returns a vector containing all MessageEvents currently in the robot's queue. |
ITeamEvents |
getTeamEventListener()
Do not call this method! |
String[] |
getTeammates()
Returns the names of all teammates, or null there is no
teammates. |
boolean |
isTeammate(String name)
Checks if a given robot name is the name of one of your teammates. |
void |
onMessageReceived(MessageEvent event)
This method is called when your robot receives a message from a teammate. |
void |
sendMessage(String name,
Serializable message)
Sends a message to one (or more) teammates. |
Methods inherited from class robocode._Robot |
---|
getBattleNum, getGunCharge, getGunImageName, getLife, getNumBattles, getRadarImageName, getRobotImageName, setGunImageName, setRadarImageName, setRobotImageName |
Methods inherited from class robocode._RobotBase |
---|
finalize, setOut, setPeer |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface robocode.robotinterfaces.IAdvancedRobot |
---|
getAdvancedEventListener |
Methods inherited from interface robocode.robotinterfaces.IBasicRobot |
---|
getBasicEventListener, getRobotRunnable, setOut, setPeer |
Constructor Detail |
---|
public TeamRobot()
Method Detail |
---|
public void broadcastMessage(Serializable message) throws IOException
public void run() { broadcastMessage("I'm here!"); }
message
- the message to broadcast to all teammates
IOException
- if the message could not be broadcasted to the
teammatesisTeammate(String)
,
getTeammates()
,
sendMessage(String, Serializable)
public Vector<MessageEvent> getMessageEvents()
for (MessageEvent e : getMessageEvents()) { // do something with e }
onMessageReceived(MessageEvent)
,
MessageEvent
public final ITeamEvents getTeamEventListener()
ITeamEvents
listener.
getTeamEventListener
in interface ITeamRobot
null
if this robot should
not receive the notifications.public String[] getTeammates()
null
there is no
teammates.
Example:
public void run() { // Prints out all teammates String[] teammates = getTeammates(); if (teammates != null) { for (String member : teammates) { out.println(member); } } }
null
if there is no teammates. The length of the String array
is equal to the number of teammates.isTeammate(String)
,
broadcastMessage(Serializable)
,
sendMessage(String, Serializable)
public boolean isTeammate(String name)
public void onScannedRobot(ScannedRobotEvent e) { if (isTeammate(e.getName()) { return; } fire(1); }
name
- the robot name to check
true
if the specified name belongs to one of your
teammates; false
otherwise.getTeammates()
,
broadcastMessage(Serializable)
,
sendMessage(String, Serializable)
public void onMessageReceived(MessageEvent event)
public void onMessageReceived(MessageEvent event) { out.println(event.getSender() + " sent me: " + event.getMessage()); }
onMessageReceived
in interface ITeamEvents
event
- the message event sent by the gameMessageEvent
,
Event
public void sendMessage(String name, Serializable message) throws IOException
public void run() { sendMessage("sample.DroidBot", "I'm here!"); }
name
- the name of the intended recipient of the messagemessage
- the message to send
IOException
- if the message could not be sentisTeammate(String)
,
getTeammates()
,
broadcastMessage(Serializable)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |