1 | /** |
---|
2 | * Copyright (c) 2001-2014 Mathew A. Nelson and Robocode contributors |
---|
3 | * All rights reserved. This program and the accompanying materials |
---|
4 | * are made available under the terms of the Eclipse Public License v1.0 |
---|
5 | * which accompanies this distribution, and is available at |
---|
6 | * http://robocode.sourceforge.net/license/epl-v10.html |
---|
7 | */ |
---|
8 | package sampleex; |
---|
9 | |
---|
10 | |
---|
11 | import robocode.*; |
---|
12 | import robocode.robotinterfaces.IBasicEvents; |
---|
13 | import robocode.robotinterfaces.IBasicRobot; |
---|
14 | import robocode.robotinterfaces.peer.IBasicRobotPeer; |
---|
15 | import robocode.robotinterfaces.peer.IStandardRobotPeer; |
---|
16 | |
---|
17 | import java.io.PrintStream; |
---|
18 | |
---|
19 | |
---|
20 | /** |
---|
21 | * A sample robot. |
---|
22 | * Is not inherited from classic base robots, uses new experimental access to RobotPeer. |
---|
23 | * Use -DEXPERIMENTAL=true to start robocode for this robot. |
---|
24 | * |
---|
25 | * @author Pavel Savara (original) |
---|
26 | */ |
---|
27 | public class Alien implements IBasicEvents, IBasicRobot, Runnable { |
---|
28 | |
---|
29 | PrintStream out; |
---|
30 | IStandardRobotPeer peer; |
---|
31 | |
---|
32 | public Runnable getRobotRunnable() { |
---|
33 | return this; |
---|
34 | } |
---|
35 | |
---|
36 | public IBasicEvents getBasicEventListener() { |
---|
37 | return this; |
---|
38 | } |
---|
39 | |
---|
40 | public void setPeer(IBasicRobotPeer iRobotPeer) { |
---|
41 | peer = (IStandardRobotPeer) iRobotPeer; |
---|
42 | } |
---|
43 | |
---|
44 | public void setOut(PrintStream printStream) { |
---|
45 | out = printStream; |
---|
46 | } |
---|
47 | |
---|
48 | public void run() { |
---|
49 | while (true) { |
---|
50 | peer.move(100); // Move ahead 100 |
---|
51 | peer.turnGun(Math.PI * 2); // Spin gun around |
---|
52 | peer.move(-100); // Move back 100 |
---|
53 | peer.turnGun(Math.PI * 2); // Spin gun around |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | public void onScannedRobot(ScannedRobotEvent e) { |
---|
58 | peer.setFire(1); |
---|
59 | } |
---|
60 | |
---|
61 | public void onHitByBullet(HitByBulletEvent e) { |
---|
62 | peer.turnBody(Math.PI / 2 + e.getBearingRadians()); |
---|
63 | } |
---|
64 | |
---|
65 | public void onStatus(StatusEvent e) {} |
---|
66 | |
---|
67 | public void onBulletHit(BulletHitEvent e) {} |
---|
68 | |
---|
69 | public void onBulletHitBullet(BulletHitBulletEvent e) {} |
---|
70 | |
---|
71 | public void onBulletMissed(BulletMissedEvent e) {} |
---|
72 | |
---|
73 | public void onDeath(DeathEvent e) {} |
---|
74 | |
---|
75 | public void onHitRobot(HitRobotEvent e) {} |
---|
76 | |
---|
77 | public void onHitWall(HitWallEvent e) {} |
---|
78 | |
---|
79 | public void onRobotDeath(RobotDeathEvent e) {} |
---|
80 | |
---|
81 | public void onWin(WinEvent e) {} |
---|
82 | } |
---|