Package robocode
Class TeamRobot
- All Implemented Interfaces:
Runnable
,IAdvancedEvents
,IAdvancedRobot
,IBasicEvents
,IBasicEvents2
,IBasicEvents3
,IBasicRobot
,IInteractiveEvents
,IInteractiveRobot
,IPaintEvents
,IPaintRobot
,ITeamEvents
,ITeamRobot
- Direct Known Subclasses:
RateControlRobot
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 a Robot
or
AdvancedRobot
first.
- Author:
- Mathew A. Nelson (original), Flemming N. Larsen (contributor), Pavel Savara (contributor)
- See Also:
-
Field Summary
Fields inherited from class robocode._RobotBase
out
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
broadcastMessage
(Serializable message) Broadcasts a message to all teammates.Returns a vector containing all MessageEvents currently in the robot's queue.final ITeamEvents
Do not call this method!String[]
Returns the names of all teammates, ornull
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.AdvancedRobot
addCustomEvent, clearAllEvents, execute, getAdvancedEventListener, getAllEvents, getBulletHitBulletEvents, getBulletHitEvents, getBulletMissedEvents, getDataDirectory, getDataFile, getDataQuotaAvailable, getDistanceRemaining, getEventPriority, getGunHeadingRadians, getGunTurnRemaining, getGunTurnRemainingRadians, getHeadingRadians, getHitByBulletEvents, getHitRobotEvents, getHitWallEvents, getRadarHeadingRadians, getRadarTurnRemaining, getRadarTurnRemainingRadians, getRobotDeathEvents, getScannedRobotEvents, getStatusEvents, getTurnRemaining, getTurnRemainingRadians, isAdjustGunForRobotTurn, isAdjustRadarForGunTurn, isAdjustRadarForRobotTurn, onCustomEvent, onDeath, onSkippedTurn, removeCustomEvent, setAhead, setBack, setEventPriority, setFire, setFireBullet, setInterruptible, setMaxTurnRate, setMaxVelocity, setResume, setStop, setStop, setTurnGunLeft, setTurnGunLeftRadians, setTurnGunRight, setTurnGunRightRadians, setTurnLeft, setTurnLeftRadians, setTurnRadarLeft, setTurnRadarLeftRadians, setTurnRadarRight, setTurnRadarRightRadians, setTurnRight, setTurnRightRadians, turnGunLeftRadians, turnGunRightRadians, turnLeftRadians, turnRadarLeftRadians, turnRadarRightRadians, turnRightRadians, waitFor
Methods inherited from class robocode._AdvancedRobot
endTurn, getGunHeadingDegrees, getHeadingDegrees, getMaxWaitCount, getRadarHeadingDegrees, getWaitCount, setTurnGunLeftDegrees, setTurnGunRightDegrees, setTurnLeftDegrees, setTurnRadarLeftDegrees, setTurnRadarRightDegrees, setTurnRightDegrees, turnGunLeftDegrees, turnGunRightDegrees, turnLeftDegrees, turnRadarLeftDegrees, turnRadarRightDegrees, turnRightDegrees
Methods inherited from class robocode.Robot
ahead, back, doNothing, fire, fireBullet, getBasicEventListener, getBattleFieldHeight, getBattleFieldWidth, getEnergy, getGraphics, getGunCoolingRate, getGunHeading, getGunHeat, getHeading, getHeight, getInteractiveEventListener, getName, getNumRounds, getNumSentries, getOthers, getPaintEventListener, getRadarHeading, getRobotRunnable, getRoundNum, getSentryBorderSize, getTime, getVelocity, getWidth, getX, getY, onBattleEnded, onBulletHit, onBulletHitBullet, onBulletMissed, onHitByBullet, onHitRobot, onHitWall, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragged, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelMoved, onPaint, onRobotDeath, onRoundEnded, onScannedRobot, onStatus, onWin, resume, run, scan, setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn, setAllColors, setBodyColor, setBulletColor, setColors, setColors, setDebugProperty, setGunColor, setRadarColor, setScanColor, stop, stop, turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight
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 Details
-
TeamRobot
public TeamRobot()
-
-
Method Details
-
broadcastMessage
Broadcasts a message to all teammates.Example:
public void run() { broadcastMessage("I'm here!"); }
- Parameters:
message
- the message to broadcast to all teammates- Throws:
IOException
- if the message could not be broadcasted to the teammates- See Also:
-
getMessageEvents
Returns a vector containing all MessageEvents currently in the robot's queue. You might, for example, call this while processing another event.Example:
for (MessageEvent e : getMessageEvents()) { // do something with e }
- Returns:
- a vector containing all MessageEvents currently in the robot's queue
- Since:
- 1.2.6
- See Also:
-
getTeamEventListener
Do not call this method!This method is called by the game to notify this robot about team events. Hence, this method must be implemented so it returns your
ITeamEvents
listener.- Specified by:
getTeamEventListener
in interfaceITeamRobot
- Returns:
- listener to team events or
null
if this robot should not receive the notifications.
-
getTeammates
Returns the names of all teammates, ornull
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); } } }
- Returns:
- a String array containing the names of all your teammates, or
null
if there is no teammates. The length of the String array is equal to the number of teammates. - See Also:
-
isTeammate
Checks if a given robot name is the name of one of your teammates.Example:
public void onScannedRobot(ScannedRobotEvent e) { if (isTeammate(e.getName()) { return; } fire(1); }
- Parameters:
name
- the robot name to check- Returns:
true
if the specified name belongs to one of your teammates;false
otherwise.- See Also:
-
onMessageReceived
This method is called when your robot receives a message from a teammate. You should override it in your robot if you want to be informed of this event.Example:
public void onMessageReceived(MessageEvent event) { out.println(event.getSender() + " sent me: " + event.getMessage()); }
- Specified by:
onMessageReceived
in interfaceITeamEvents
- Parameters:
event
- the message event sent by the game- See Also:
-
sendMessage
Sends a message to one (or more) teammates.Example:
public void run() { sendMessage("sample.DroidBot", "I'm here!"); }
- Parameters:
name
- the name of the intended recipient of the messagemessage
- the message to send- Throws:
IOException
- if the message could not be sent- See Also:
-