Advertisement
qtinio

benc

May 7th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. import robocode.*;
  8. import robocode.Robot;
  9.  
  10. import robocode.ScannedRobotEvent;
  11. import java.awt.*;
  12. import java.awt.geom.Rectangle2D;
  13.  
  14. /**
  15. *
  16. * @author student
  17. */
  18. public class zbrzezniak extends AdvancedRobot{
  19. private double enemyX;
  20. private double enemyY;
  21. private boolean movingForward;
  22. private double bfW;
  23. private double bfH;
  24. private Rectangle2D fieldRect;
  25.  
  26. public void run() {
  27. // ruch robota
  28. fieldRect = new Rectangle2D.Double(18, 18, getBattleFieldWidth()-36,
  29. getBattleFieldHeight()-36);
  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. }
  40. }
  41.  
  42. public void onHitWall(HitWallEvent e) {
  43. // Bounce off!
  44. reverseDirection();
  45. }
  46.  
  47. public void reverseDirection() {
  48. if (movingForward) {
  49. setBack(40000);
  50. movingForward = false;
  51. } else {
  52. setAhead(40000);
  53. movingForward = true;
  54. }
  55. }
  56.  
  57. public void onStatus( StatusEvent e) {
  58. // you can also put all setAdjustXX(..) methods here
  59. setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
  60. }
  61.  
  62. public void onScannedRobot(ScannedRobotEvent e) {
  63. // setTurnRadarRight(2.0 * Utils.normalRelativeAngleDegrees(getHeading() + e.getBearing() - getRadarHeading()));
  64. double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
  65. enemyX = getX() + e.getDistance() * Math.sin(absoluteBearing);
  66. enemyY = getY() + e.getDistance() * Math.cos(absoluteBearing);
  67. // wyniki z radaru
  68.  
  69. }
  70.  
  71.  
  72. public void onPaint(Graphics2D g) {
  73. // Set the paint color to a red half transparent color
  74. double myX = getX();
  75. double myY = getY();
  76.  
  77. String posS =
  78. String.format("Zbrzeźniak = %f X, %f Y\n Kaczka = %f X, %f Y",
  79. myX, myY, enemyX, enemyY);
  80.  
  81. g.setColor(new Color(0xff, 0xff, 0xff, 0x90));
  82. g.drawString(posS, 10, 20);
  83. //
  84. // // Draw a line from our robot to the scanned robot
  85. // g.drawLine(scannedX, scannedY, (int)getX(), (int)getY());
  86. //
  87. // // Draw a filled square on top of the scanned robot that covers it
  88. // g.fillRect(scannedX - 20, scannedY - 20, 40, 40);
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement