Changes between Version 6 and Version 7 of ControlSystems/SoftwareTeam/Training/VirtualTraining/HelloRoboCode


Ignore:
Timestamp:
Aug 31, 2020, 10:37:03 PM (5 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/VirtualTraining/HelloRoboCode

    v6 v7  
    1414[[br]][[br]][[br]]
    1515
    16 The editor starts with a pre-created super-simple robot that you can modify and extend.  Let's use it as-is to see what it does.
     16The editor starts with a pre-created super-simple robot that you can modify and extend.  here's the code for the robot:
     17{{{
     18package daa2537;
     19import robocode.*;
     20
     21// API help : https://robocode.sourceforge.io/docs/robocode/robocode/JuniorRobot.html
     22
     23/** RoboJojo - a robot by (your name here)*/
     24public class RoboJojo extends JuniorRobot
     25{
     26        /** run: RoboJojo's default behavior */
     27        public void run() {
     28                // Initialization of the robot should be put here
     29
     30                // Some color codes: blue, yellow, black, white, red, pink, brown, grey, orange...
     31                // Sets these colors (robot parts): body, gun, radar, bullet, scan_arc
     32                setColors(orange, blue, white, yellow, black);
     33
     34                // Robot main loop
     35                while(true) {
     36                        // Replace the next 4 lines with any behavior you would like
     37                        ahead(100);
     38                        turnGunRight(360);
     39                        back(100);
     40                        turnGunRight(360);
     41                }
     42        }
     43
     44        /** onScannedRobot: What to do when you see another robot */
     45        public void onScannedRobot() {
     46                // Replace the next line with any behavior you would like
     47                fire(1);
     48        }
     49
     50        /** onHitByBullet: What to do when you're hit by a bullet */
     51        public void onHitByBullet() {
     52                // Replace the next line with any behavior you would like
     53                back(10);
     54        }
     55       
     56        /** onHitWall: What to do when you hit a wall */
     57        public void onHitWall() {
     58                // Replace the next line with any behavior you would like
     59                back(20);
     60        }       
     61}
     62}}}
     63
     64Let's use it as-is to see what it does.  We'll review it in the next lesson to understand the code better.
    1765[[Image(RobotCompile.jpg, align=right, 250px)]]
    18661. Save the robot: '''File->Save''' accept the default filename (e.g. !RoboJojo.java)