-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCannon.java
More file actions
48 lines (34 loc) · 932 Bytes
/
Cannon.java
File metadata and controls
48 lines (34 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ubots;
import robocode.AdvancedRobot;
public class Cannon {
private static final int DEGRES_REMAINING_TO_TURN = 10;
private AdvancedRobot robot;
private EnemyInfo enemy;
public Cannon(AdvancedRobot robot, EnemyInfo enemy) {
this.robot = robot;
this.enemy = enemy;
}
public void init() {
robot.setAdjustGunForRobotTurn(true);
}
public void project() {
if (enemy.isNotScanned())
return;
BulletPredictor bullet = new BulletPredictor(enemy.getDistance());
AimPredictor aim = new AimPredictor(robot, enemy);
aim.point(bullet);
fire(bullet.getPower());
}
private void fire(double firePower) {
//evita deperdicio de disparos
if (isCool() && isCannonReady()) {
robot.setFire(firePower);
}
}
private boolean isCannonReady() {
return Math.abs(robot.getGunTurnRemaining()) < DEGRES_REMAINING_TO_TURN;
}
private boolean isCool() {
return robot.getGunHeat() == 0;
}
}