Advertisement
Guest User

jackrobocode

a guest
Feb 22nd, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package ShielsJack;
  2. import robocode.*;
  3. import robocode.util.*;
  4. //import java.awt.Color;
  5.  
  6. // API help : https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html
  7.  
  8. /**
  9. * ShielsJack - a robot by (your name here)
  10. */
  11. public class ShielsJack extends AdvancedRobot
  12. {
  13. /**
  14. * run: ShielsJack's default behavior
  15. */
  16. public void run() {
  17. // Initialization of the robot should be put here
  18.  
  19. // After trying out your robot, try uncommenting the import at the top,
  20. // and the next line:
  21. setAdjustGunForRobotTurn(true);
  22. setAdjustRadarForGunTurn(true);
  23.  
  24. // setColors(Color.red,Color.blue,Color.green); // body,gun,radar
  25.  
  26. // Robot main loop
  27. while(true) {
  28. // Replace the next 4 lines with any behavior you would like
  29. setTurnRadarRight(360);
  30. ahead(200);
  31. turnLeft(45);
  32.  
  33. }
  34. }
  35.  
  36. /**
  37. * onScannedRobot: What to do when you see another robot
  38. */
  39. public void onScannedRobot(ScannedRobotEvent e) {
  40. // Replace the next line with any behavior you would like
  41.  
  42. // taken from wiki
  43.  
  44. // taken from mark.random-article.com
  45. setTurnGunRight(getHeading() - getGunHeading() + e.getBearing());
  46. fire(5);
  47. if (e.getDistance() < 200){
  48. ahead(100);
  49. back(100);
  50. setTurnRadarRight(360);
  51. }
  52. }
  53.  
  54. /**
  55. * onHitByBullet: What to do when you're hit by a bullet
  56. */
  57. public void onHitByBullet(HitByBulletEvent e) {
  58. // Replace the next line with any behavior you would like
  59. ahead(200);
  60. }
  61.  
  62. /**
  63. * onHitWall: What to do when you hit a wall
  64. */
  65. public void onHitWall(HitWallEvent e) {
  66. // Replace the next line with any behavior you would like
  67. back(20);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement