Skip to content

Commit b8456e7

Browse files
Manual merge of pull request #6 for Naval Robocode as this pull request could not be automatically merged with GitHub as it contained merge conflicts.
1 parent 7db0a01 commit b8456e7

File tree

13 files changed

+120
-12
lines changed

13 files changed

+120
-12
lines changed

naval-robocode-versions.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
## Naval Robocode Version 0.9.2 (28-Feb-2015)
1+
## Naval Robocode Version 0.9.2 (02-Mar-2015)
22

33
### Changes
44
* Merged all changes with Naval Robocode with Robocode 1.9.2.4 (newest version).
55
* Flemming clean-up and Naval Robocode specification
66
* Now able to use naval-robocode.bat to start Naval Robocode
77
* Fixed a few UnitTests that fell short due to a few missing classes
8+
* The in-game editor can now create a sample ship for you.
89

910
### Bug fixes
1011
* Mines now have a blast Radius. (See NavalRules)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package $PACKAGE;
2+
3+
import java.awt.Color;
4+
5+
import robocode.HitRobotEvent;
6+
import robocode.HitWallEvent;
7+
import robocode.ScannedShipEvent;
8+
import robocode.Ship;
9+
10+
/**
11+
* $CLASSNAME - a ship by (your name here)
12+
*/
13+
public class $CLASSNAME extends Ship{
14+
int direction = 1;
15+
16+
/**
17+
* run: $CLASSNAME's default behavior
18+
*/
19+
public void run(){
20+
// The following components can all be colored seperately
21+
// Setup
22+
setBodyColor(Color.red);
23+
setFrontCannonColor(Color.orange);
24+
setBackCannonColor(Color.yellow);
25+
setRadarColor(Color.green);
26+
setMineComponentColor(Color.cyan);
27+
setBulletColor(Color.blue);
28+
setScanColor(Color.magenta);
29+
30+
//Easy way to make your radar go in circles forever
31+
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
32+
33+
// Loop
34+
while(true){
35+
//Makes sure we go 4000 units toward a certain direction
36+
setAhead(4000 * direction);
37+
//Execute makes sure your commands actually get executed. You could see it
38+
//as if you're ending your turn.
39+
//Try removing the execute command. You'll see that that your Ship
40+
//won't even move! This is because you'll end up saying "Go ahead!" an infinite
41+
//amount of times, without ever ending your turn.
42+
execute();
43+
}
44+
}
45+
// When a wall is hit, reverse direction and make a slight turn.
46+
public void onHitWall(HitWallEvent event){
47+
direction *= -1;
48+
setTurnRightDegrees(45);
49+
}
50+
51+
public void onHitRobot(HitRobotEvent event){
52+
//Fill in something you'd like your Ship to do when it hits another Ship
53+
}
54+
55+
public void onScannedShip(ScannedShipEvent event){
56+
// The easiest way to target the scanned ship is to use these functions
57+
// Turn your front cannon towards the ship
58+
setTurnFrontCannonRightRadians(event.getBearingFrontRadians());
59+
//At this point you've already told your ship to move 4000 ahead,
60+
//AND you've told it to turn its front cannon
61+
//All you gotta do now is wait for your cannon to reach its destination
62+
while(getFrontCannonTurnRemainingRadians() != 0){
63+
execute();
64+
if(getFrontCannonAtBlindSpot())
65+
break;
66+
}
67+
//If your front cannon is not at its blindspot
68+
if(!getFrontCannonAtBlindSpot()){
69+
//Then shoot!
70+
fireFrontCannon(3);
71+
}
72+
//We waited all this time for our cannon to turn and it didn't even reach its target?!
73+
else{
74+
//Bomb the place.
75+
placeMine(5);
76+
}
77+
}
78+
}

robocode.core/src/main/java/net/sf/robocode/core/RobocodeMain.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.sf.robocode.recording.BattleRecordFormat;
1919
import net.sf.robocode.recording.IRecordManager;
2020
import net.sf.robocode.repository.IRepositoryManager;
21+
import net.sf.robocode.security.HiddenAccess;
2122
import net.sf.robocode.serialization.SerializableOptions;
2223
import net.sf.robocode.settings.ISettingsManager;
2324
import net.sf.robocode.sound.ISoundManager;
@@ -134,7 +135,8 @@ public void uncaughtException(Thread thread, Throwable t) {
134135

135136
if (setup.battleFilename == null && versionManager.isLastRunVersionChanged()) {
136137
properties.saveProperties();
137-
windowManager.runIntroBattle();
138+
if(!HiddenAccess.getNaval())
139+
windowManager.runIntroBattle();
138140
}
139141
}
140142

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestConstructorHttpAttack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void onTurnEnded(TurnEndedEvent event) {
3636
messagedInitialization = true;
3737
}
3838

39-
if (out.contains("access denied (java.net.SocketPermission")) {
39+
if (out.contains("access denied (\"java.net.SocketPermission")) {
4040
messagedAccessDenied = true;
4141
}
4242
}

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestConstructorReflectionAttack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {
3131

3232
final String out = event.getTurnSnapshot().getRobots()[0].getOutputStreamSnapshot();
3333

34-
if (out.contains("access denied (java.lang.reflect.ReflectPermission")) {
34+
if (out.contains("access denied (\"java.lang.reflect.ReflectPermission")) {
3535
messagedAccessDenied = true;
3636
}
3737
}

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestConstructorSocketAttack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void onTurnEnded(TurnEndedEvent event) {
3636
messagedInitialization = true;
3737
}
3838

39-
if (out.contains("access denied (java.net.SocketPermission")) {
39+
if (out.contains("access denied (\"java.net.SocketPermission")) {
4040
messagedAccessDenied = true;
4141
}
4242
}

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestFileAttack.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public void onTurnEnded(TurnEndedEvent event) {
3333
super.onTurnEnded(event);
3434
final String out = event.getTurnSnapshot().getRobots()[1].getOutputStreamSnapshot();
3535

36-
if (out.contains("Preventing tested.robots.FileAttack from access: (java.io.FilePermission C:\\MSDOS.SYS read)")) {
36+
if (out.contains("Preventing tested.robots.FileAttack from access: (\"java.io.FilePermission\" \"C:\\MSDOS.SYS\" \"read\")")) {
3737
messagedRead = true;
3838
}
3939
if (out.contains(
40-
"Preventing tested.robots.FileAttack from access: (java.io.FilePermission C:\\Robocode.attack write)")) {
40+
"Preventing tested.robots.FileAttack from access: (\"java.io.FilePermission\" \"C:\\Robocode.attack\" \"write\")")) {
4141
messagedWrite = true;
4242
}
4343
}

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestFileOutputStreamAttack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {
3131

3232
final String out = event.getTurnSnapshot().getRobots()[0].getOutputStreamSnapshot();
3333

34-
if (out.contains("access denied (java.io.FilePermission")) {
34+
if (out.contains("access denied (\"java.io.FilePermission")) {
3535
messagedAccessDenied = true;
3636
}
3737
}

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestHttpAttack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {
3131

3232
final String out = event.getTurnSnapshot().getRobots()[0].getOutputStreamSnapshot();
3333

34-
if (out.contains("access denied (java.net.SocketPermission")) {
34+
if (out.contains("access denied (\"java.net.SocketPermission")) {
3535
messagedAccessDenied = true;
3636
}
3737
}

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestReflectionAttack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {
3131

3232
final String out = event.getTurnSnapshot().getRobots()[0].getOutputStreamSnapshot();
3333

34-
if (out.contains("access denied (java.lang.reflect.ReflectPermission")) {
34+
if (out.contains("access denied (\"java.lang.reflect.ReflectPermission")) {
3535
messagedAccessDenied = true;
3636
}
3737
}

robocode.tests/src/test/java/net/sf/robocode/test/robots/TestSocketAttack.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public void onTurnEnded(TurnEndedEvent event) {
3131

3232
final String out = event.getTurnSnapshot().getRobots()[0].getOutputStreamSnapshot();
3333

34-
if (out.contains("access denied (java.net.SocketPermission")) {
34+
if (out.contains("access denied (\"java.net.SocketPermission")) { // In Thomas's version, the extra " is required
3535
messagedAccessDenied = true;
36-
}
36+
}
3737
}
3838

3939
@Override

robocode.ui.editor/src/main/java/net/sf/robocode/ui/editor/RobocodeEditor.java

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ public void createNewJavaFile() {
212212
public void createNewRobot() {
213213
createNewRobot("Robot");
214214
}
215+
216+
public void createNewShip(){
217+
createNewRobot("Ship");
218+
}
215219

216220
public void createNewJuniorRobot() {
217221
createNewRobot("JuniorRobot");

robocode.ui.editor/src/main/java/net/sf/robocode/ui/editor/RobocodeEditorMenuBar.java

+23
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public void actionPerformed(ActionEvent e) {
3838

3939
if (source == RobocodeEditorMenuBar.this.getFileNewRobotMenuItem()) {
4040
fileNewRobotActionPerformed();
41+
} else if(source == RobocodeEditorMenuBar.this.getFileNewShipMenuItem()){ //For adding ships
42+
fileNewShipActionPerformed();
4143
} else if (source == RobocodeEditorMenuBar.this.getFileNewJuniorRobotMenuItem()) {
4244
fileNewJuniorRobotActionPerformed();
4345
} else if (source == RobocodeEditorMenuBar.this.getFileNewJavaFileMenuItem()) {
@@ -102,6 +104,7 @@ public void actionPerformed(ActionEvent e) {
102104
private JMenuItem fileNewJavaFileMenuItem;
103105
private JMenu fileNewMenu;
104106
private JMenuItem fileNewRobotMenuItem;
107+
private JMenuItem fileNewShipMenuItem;
105108
private JMenuItem fileNewJuniorRobotMenuItem;
106109

107110
// Compiler menu
@@ -198,6 +201,13 @@ private void fileNewRobotActionPerformed() {
198201
getFileSaveMenuItem().setEnabled(true);
199202
getFileSaveAsMenuItem().setEnabled(true);
200203
}
204+
205+
private void fileNewShipActionPerformed(){
206+
editor.createNewShip();
207+
208+
getFileSaveMenuItem().setEnabled(true);
209+
getFileSaveAsMenuItem().setEnabled(true);
210+
}
201211

202212
private void fileNewJuniorRobotActionPerformed() {
203213
editor.createNewJuniorRobot();
@@ -408,6 +418,7 @@ private JMenu getFileNewMenu() {
408418
fileNewMenu.setText("New");
409419
fileNewMenu.setMnemonic('N');
410420
fileNewMenu.add(getFileNewRobotMenuItem());
421+
fileNewMenu.add(getFileNewShipMenuItem());
411422
fileNewMenu.add(getFileNewJuniorRobotMenuItem());
412423
fileNewMenu.add(getFileNewJavaFileMenuItem());
413424
}
@@ -424,6 +435,18 @@ private JMenuItem getFileNewRobotMenuItem() {
424435
}
425436
return fileNewRobotMenuItem;
426437
}
438+
439+
//New JMenuItem to add Ships
440+
private JMenuItem getFileNewShipMenuItem(){
441+
if(fileNewShipMenuItem == null){
442+
fileNewShipMenuItem = new JMenuItem();
443+
fileNewShipMenuItem.setText("Ship");
444+
445+
fileNewShipMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, MENU_SHORTCUT_KEY_MASK));
446+
fileNewShipMenuItem.addActionListener(eventHandler);
447+
}
448+
return fileNewShipMenuItem;
449+
}
427450

428451
private JMenuItem getFileNewJuniorRobotMenuItem() {
429452
if (fileNewJuniorRobotMenuItem == null) {

0 commit comments

Comments
 (0)