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. |
| 16 | The editor starts with a pre-created super-simple robot that you can modify and extend. here's the code for the robot: |
| 17 | {{{ |
| 18 | package daa2537; |
| 19 | import robocode.*; |
| 20 | |
| 21 | // API help : https://robocode.sourceforge.io/docs/robocode/robocode/JuniorRobot.html |
| 22 | |
| 23 | /** RoboJojo - a robot by (your name here)*/ |
| 24 | public 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 | |
| 64 | Let's use it as-is to see what it does. We'll review it in the next lesson to understand the code better. |