|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrobocode._Robot
robocode.Robot
robocode._AdvancedRobot
robocode._AdvancedRadiansRobot
robocode.AdvancedRobot
robocode.TeamRobot
public class TeamRobot
An advanced type of robot that supports messages between teammates.
If you have not already, you should create a Robot
first.
Robot
Field Summary |
---|
Fields inherited from class robocode.Robot |
---|
out |
Constructor Summary | |
---|---|
TeamRobot()
|
Method Summary | |
---|---|
void |
broadcastMessage(java.io.Serializable message)
Broadcasts a message to all teammates. |
java.util.Vector<MessageEvent> |
getMessageEvents()
Returns a vector containing all MessageEvents currently in the robot's queue. |
java.lang.String[] |
getTeammates()
Returns the names of all your teammates. |
boolean |
isTeammate(java.lang.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(java.lang.String name,
java.io.Serializable message)
Sends a message to one (or more) teammates. |
Methods inherited from class robocode._Robot |
---|
getBattleNum, getGunCharge, getGunImageName, getLife, getNumBattles, getRadarImageName, getRobotImageName, setGunImageName, setPeer, setRadarImageName, setRobotImageName, uninitializedException |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TeamRobot()
Method Detail |
---|
public boolean isTeammate(java.lang.String name)
Example:
public void onScannedRobot(ScannedRobotEvent e) { if (isTeammate(e.getName()) { return; } else { fire(1); } }
name
- the robot name to checkpublic java.lang.String[] getTeammates()
Example:
public void run() { // Prints out all teammates for (String teammate : getTeammates()) { System.out.println(teammate); } }
public void broadcastMessage(java.io.Serializable message) throws java.io.IOException
Example:
public void run() { broadcastMessage("I'm here!"); }
message
- the message to broadcast to all teammates
java.io.IOException
public void sendMessage(java.lang.String name, java.io.Serializable message) throws java.io.IOException
Example:
public void run() { sendMessage("sample.DroidBot", "I'm here!"); }
name
- the name of the intended recipient of the messagemessage
- the message to send
java.io.IOException
public java.util.Vector<MessageEvent> getMessageEvents()
Example:
for (MessageEvent e : getMessageEvents()) { // do something with e }
onMessageReceived(robocode.MessageEvent)
,
MessageEvent
public void onMessageReceived(MessageEvent event)
Example:
public void onMessageReceived(MessageEvent event) { out.println(event.getSender() + " sent me: " + event.getMessage()); }
event
- the event sent by the gameMessageEvent
,
Event
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |