Package robocode

Class TeamRobot

    • Constructor Detail

      • TeamRobot

        public TeamRobot()
    • Method Detail

      • broadcastMessage

        public void broadcastMessage​(java.io.Serializable message)
                              throws java.io.IOException
        Broadcasts a message to all teammates.

        Example:

           public void run() {
               broadcastMessage("I'm here!");
           }
         
        Parameters:
        message - the message to broadcast to all teammates
        Throws:
        java.io.IOException - if the message could not be broadcasted to the teammates
        See Also:
        isTeammate(String), getTeammates(), sendMessage(String, Serializable)
      • getMessageEvents

        public java.util.Vector<MessageEvent> 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:
        onMessageReceived(MessageEvent), MessageEvent
      • getTeamEventListener

        public final ITeamEvents 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 interface ITeamRobot
        Returns:
        listener to team events or null if this robot should not receive the notifications.
      • getTeammates

        public java.lang.String[] getTeammates()
        Returns the names of all teammates, or 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);
                   }
               }
           }
         
        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(String), broadcastMessage(Serializable), sendMessage(String, Serializable)
      • isTeammate

        public boolean isTeammate​(java.lang.String name)
        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:
        getTeammates(), broadcastMessage(Serializable), sendMessage(String, Serializable)
      • onMessageReceived

        public void onMessageReceived​(MessageEvent event)
        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 interface ITeamEvents
        Parameters:
        event - the message event sent by the game
        See Also:
        MessageEvent, Event
      • sendMessage

        public void sendMessage​(java.lang.String name,
                                java.io.Serializable message)
                         throws java.io.IOException
        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 message
        message - the message to send
        Throws:
        java.io.IOException - if the message could not be sent
        See Also:
        isTeammate(String), getTeammates(), broadcastMessage(Serializable)