Last change
on this file since 13019 was
13019,
checked in by gkronber, 9 years ago
|
#2069: added necessary robocode files to project to make sure that the robocode problem is self-contained (only a java installation is necessary)
|
File size:
1.2 KB
|
Line | |
---|
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 sample; |
---|
9 | |
---|
10 | |
---|
11 | import robocode.HitByBulletEvent; |
---|
12 | import robocode.Robot; |
---|
13 | import robocode.ScannedRobotEvent; |
---|
14 | |
---|
15 | |
---|
16 | /** |
---|
17 | * MyFirstRobot - a sample robot by Mathew Nelson. |
---|
18 | * <p/> |
---|
19 | * Moves in a seesaw motion, and spins the gun around at each end. |
---|
20 | * |
---|
21 | * @author Mathew A. Nelson (original) |
---|
22 | */ |
---|
23 | public class MyFirstRobot extends Robot { |
---|
24 | |
---|
25 | /** |
---|
26 | * MyFirstRobot's run method - Seesaw |
---|
27 | */ |
---|
28 | public void run() { |
---|
29 | |
---|
30 | while (true) { |
---|
31 | ahead(100); // Move ahead 100 |
---|
32 | turnGunRight(360); // Spin gun around |
---|
33 | back(100); // Move back 100 |
---|
34 | turnGunRight(360); // Spin gun around |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * Fire when we see a robot |
---|
40 | */ |
---|
41 | public void onScannedRobot(ScannedRobotEvent e) { |
---|
42 | fire(1); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * We were hit! Turn perpendicular to the bullet, |
---|
47 | * so our seesaw might avoid a future shot. |
---|
48 | */ |
---|
49 | public void onHitByBullet(HitByBulletEvent e) { |
---|
50 | turnLeft(90 - e.getBearing()); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
Note: See
TracBrowser
for help on using the repository browser.