Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- import robocode.*;
- import robocode.Robot;
- import robocode.ScannedRobotEvent;
- import java.awt.*;
- import java.awt.geom.Rectangle2D;
- /**
- *
- * @author student
- */
- public class zbrzezniak extends AdvancedRobot{
- private double enemyX;
- private double enemyY;
- private boolean movingForward;
- private double bfW;
- private double bfH;
- private Rectangle2D fieldRect;
- public void run() {
- // ruch robota
- fieldRect = new Rectangle2D.Double(18, 18, getBattleFieldWidth()-36,
- getBattleFieldHeight()-36);
- while (true) {
- setAhead(40000);
- movingForward = true;
- setTurnRight(90);
- waitFor(new TurnCompleteCondition(this));
- setTurnLeft(180);
- waitFor(new TurnCompleteCondition(this));
- setTurnRight(180);
- waitFor(new TurnCompleteCondition(this));
- }
- }
- public void onHitWall(HitWallEvent e) {
- // Bounce off!
- reverseDirection();
- }
- public void reverseDirection() {
- if (movingForward) {
- setBack(40000);
- movingForward = false;
- } else {
- setAhead(40000);
- movingForward = true;
- }
- }
- public void onStatus( StatusEvent e) {
- // you can also put all setAdjustXX(..) methods here
- setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- // setTurnRadarRight(2.0 * Utils.normalRelativeAngleDegrees(getHeading() + e.getBearing() - getRadarHeading()));
- double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
- enemyX = getX() + e.getDistance() * Math.sin(absoluteBearing);
- enemyY = getY() + e.getDistance() * Math.cos(absoluteBearing);
- // wyniki z radaru
- }
- public void onPaint(Graphics2D g) {
- // Set the paint color to a red half transparent color
- double myX = getX();
- double myY = getY();
- String posS =
- String.format("Zbrzeźniak = %f X, %f Y\n Kaczka = %f X, %f Y",
- myX, myY, enemyX, enemyY);
- g.setColor(new Color(0xff, 0xff, 0xff, 0x90));
- g.drawString(posS, 10, 20);
- //
- // // Draw a line from our robot to the scanned robot
- // g.drawLine(scannedX, scannedY, (int)getX(), (int)getY());
- //
- // // Draw a filled square on top of the scanned robot that covers it
- // g.fillRect(scannedX - 20, scannedY - 20, 40, 40);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement