Advertisement
qtinio

daliga

Jun 10th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. package nielegalnaplantacja;
  2.  
  3.  
  4. import java.awt.Color;
  5. import robocode.Droid;
  6. import robocode.HitByBulletEvent;
  7. import robocode.HitRobotEvent;
  8. import robocode.HitWallEvent;
  9. import robocode.MessageEvent;
  10. import robocode.StatusEvent;
  11. import robocode.TeamRobot;
  12. import robocode.TurnCompleteCondition;
  13. import sampleteam.Point;
  14. import static robocode.util.Utils.normalRelativeAngleDegrees;
  15.  
  16.  
  17. public class WladyslawDaliga extends TeamRobot implements Droid {
  18.  
  19. boolean movingForward;
  20. boolean received = true;
  21.  
  22. public void run() {
  23. out.println("Wladyslaw ready.");
  24. setBodyColor(Color.yellow);
  25. setGunColor(Color.yellow);
  26. setScanColor(Color.yellow);
  27. setBulletColor(Color.white);
  28.  
  29.  
  30. while (true) {
  31. setAhead(40000);
  32. movingForward = true;
  33. setTurnRight(90);
  34. waitFor(new TurnCompleteCondition(this));
  35. setTurnLeft(180);
  36. waitFor(new TurnCompleteCondition(this));
  37. setTurnRight(180);
  38. waitFor(new TurnCompleteCondition(this));
  39. execute();
  40. }
  41. }
  42.  
  43.  
  44. @Override
  45. public void onMessageReceived(MessageEvent e) {
  46. // Fire at a point
  47. if (e.getMessage() instanceof Point) {
  48. Point p = (Point) e.getMessage();
  49. // Calculate x and y to target
  50. double dx = p.getX() - this.getX();
  51. double dy = p.getY() - this.getY();
  52. // Calculate angle to target
  53. double theta = Math.toDegrees(Math.atan2(dx, dy));
  54.  
  55. // Turn gun to target
  56. turnGunRight(normalRelativeAngleDegrees(theta - getGunHeading()));
  57. // Fire hard!
  58. fire(3);
  59. }
  60.  
  61. }
  62.  
  63. // public void onHitByBullet(HitByBulletEvent e) {
  64. // turnLeft(90 - e.getBearing());
  65. // }
  66. //
  67. public void onHitWall(HitWallEvent e) {
  68. // Bounce off!
  69. reverseDirection();
  70. }
  71.  
  72. public void reverseDirection() {
  73. if (movingForward) {
  74. setBack(40000);
  75. movingForward = false;
  76. } else {
  77. setAhead(40000);
  78. movingForward = true;
  79. }
  80. }
  81.  
  82. public void onHitRobot(HitRobotEvent e) {
  83. // If we're moving the other robot, reverse!
  84. if (e.isMyFault()) {
  85. reverseDirection();
  86. }
  87. }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement