Skip to content

Fixed the test class bugs and more #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions naval-robocode-versions.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
## Naval Robocode Version 0.9.3 (28-Feb-2015)

### Bug fixes
* Now able to use naval-robocode.bat to start Naval Robocode
* Fixed a few UnitTests that fell short due to a few missing classes

## Naval Robocode Version 0.9.2 (24-Feb-2015)
## Naval Robocode Version 0.9.2 (2-Mar-2015)

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

### Bug fixes
* Mines now have a blast Radius. (See NavalRules)
Expand Down
2 changes: 1 addition & 1 deletion robocode.api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
</execution>
</executions>
<configuration>
<windowtitle>Robocode ${project.version} API</windowtitle>
<windowtitle>Naval Robocode ${project.version} API</windowtitle>
<docfilessubdirs>true</docfilessubdirs>
<doctitle>
<![CDATA[<h1>Robocode ${project.version} API</h1>]]>
Expand Down
78 changes: 78 additions & 0 deletions robocode.content/src/main/resources/templates/newship.tpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package $PACKAGE;

import java.awt.Color;

import robocode.HitRobotEvent;
import robocode.HitWallEvent;
import robocode.ScannedShipEvent;
import robocode.Ship;

/**
* $CLASSNAME - a ship by (your name here)
*/
public class $CLASSNAME extends Ship{
int direction = 1;

/**
* run: $CLASSNAME's default behavior
*/
public void run(){
// The following components can all be colored seperately
// Setup
setBodyColor(Color.red);
setFrontCannonColor(Color.orange);
setBackCannonColor(Color.yellow);
setRadarColor(Color.green);
setMineComponentColor(Color.cyan);
setBulletColor(Color.blue);
setScanColor(Color.magenta);

//Easy way to make your radar go in circles forever
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);

// Loop
while(true){
//Makes sure we go 4000 units toward a certain direction
setAhead(4000 * direction);
//Execute makes sure your commands actually get executed. You could see it
//as if you're ending your turn.
//Try removing the execute command. You'll see that that your Ship
//won't even move! This is because you'll end up saying "Go ahead!" an infinite
//amount of times, without ever ending your turn.
execute();
}
}
// When a wall is hit, reverse direction and make a slight turn.
public void onHitWall(HitWallEvent event){
direction *= -1;
setTurnRightDegrees(45);
}

public void onHitRobot(HitRobotEvent event){
//Fill in something you'd like your Ship to do when it hits another Ship
}

public void onScannedShip(ScannedShipEvent event){
// The easiest way to target the scanned ship is to use these functions
// Turn your front cannon towards the ship
setTurnFrontCannonRightRadians(event.getBearingFrontRadians());
//At this point you've already told your ship to move 4000 ahead,
//AND you've told it to turn its front cannon
//All you gotta do now is wait for your cannon to reach its destination
while(getFrontCannonTurnRemainingRadians() != 0){
execute();
if(getFrontCannonAtBlindSpot())
break;
}
//If your front cannon is not at its blindspot
if(!getFrontCannonAtBlindSpot()){
//Then shoot!
fireFrontCannon(3);
}
//We waited all this time for our cannon to turn and it didn't even reach its target?!
else{
//Bomb the place.
placeMine(5);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.sf.robocode.recording.BattleRecordFormat;
import net.sf.robocode.recording.IRecordManager;
import net.sf.robocode.repository.IRepositoryManager;
import net.sf.robocode.security.HiddenAccess;
import net.sf.robocode.serialization.SerializableOptions;
import net.sf.robocode.settings.ISettingsManager;
import net.sf.robocode.sound.ISoundManager;
Expand Down Expand Up @@ -134,7 +135,8 @@ public void uncaughtException(Thread thread, Throwable t) {

if (setup.battleFilename == null && versionManager.isLastRunVersionChanged()) {
properties.saveProperties();
windowManager.runIntroBattle();
if(!HiddenAccess.getNaval())
windowManager.runIntroBattle();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public final class VersionManager implements IVersionManager {

private static final String VERSIONS_TXT = "versions.md";
private static final String VERSIONS_TXT = "naval-robocode-versions.md";
private static final String UNKNOWN_VERSION = "unknown";

private static Version version;
Expand All @@ -54,7 +54,7 @@ public String checkForNewVersion() {
BufferedReader reader = null;

try {
URL url = new URL("http://robocode.sourceforge.net/version/version.html");
URL url = new URL("http://robocode.sourceforge.net/version/naval-version.html");

URLConnection urlConnection = url.openConnection();

Expand Down Expand Up @@ -135,15 +135,15 @@ private static String getVersionFromJar() {
in = new BufferedReader(new InputStreamReader(is));

versionString = in.readLine();
while (versionString != null && !versionString.startsWith("## Version ")) {
while (versionString != null && !versionString.startsWith("## Naval Robocode Version ")) {
versionString = in.readLine();
}
}
} catch (FileNotFoundException e) {
logError("No " + VERSIONS_TXT + " file in robocode.jar");
System.err.println("No " + VERSIONS_TXT + " file in robocode.jar");
versionString = UNKNOWN_VERSION;
} catch (IOException e) {
logError("Error while reading " + VERSIONS_TXT + " from robocode.jar: " + e);
System.err.println("Error while reading " + VERSIONS_TXT + " from robocode.jar: " + e);
versionString = UNKNOWN_VERSION;
} finally {
if (in != null) {
Expand Down Expand Up @@ -213,7 +213,7 @@ private static String getVersionFromFile() {
}

private static String versionFileLineToVersion(String versionFileLine) {
String version = versionFileLine.substring("## Version ".length());
String version = versionFileLine.substring("## Naval Robocode Version ".length());

int index = version.indexOf('(');
if (index >= 0) {
Expand Down
4 changes: 4 additions & 0 deletions robocode.distribution/setup.asm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@
<source>../versions.md</source>
<lineEnding>lf</lineEnding> <!-- for Unix/Linux -->
</file>
<file>
<source>../naval-robocode-versions.md</source>
<lineEnding>lf</lineEnding> <!-- for Unix/Linux -->
</file>
</files>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private static boolean install(File suggestedDir) {

// Create shortcuts and file associations
if (extractor.extract(installDir)) {
extractor.createShortcuts(installDir, "robocode.bat", "Naval Robocode", "Naval Robocode");
extractor.createShortcuts(installDir, "naval-robocode.bat", "Naval Robocode", "Naval Robocode");
extractor.createFileAssociations(installDir);
return true;
}
Expand Down Expand Up @@ -467,7 +467,7 @@ private void createShortcuts(File installDir, String runnable, String folder, St
if (createWindowsShortcuts(installDir, runnable, folder, name) == false) {
JOptionPane.showMessageDialog(null,
message + "\n" + "To start Naval Robocode, enter the following at a command prompt:\n" + "cd "
+ installDir.getAbsolutePath() + "\n" + "robocode.bat");
+ installDir.getAbsolutePath() + "\n" + "naval-robocode.bat");
}
} else if (osName.toLowerCase().indexOf("mac") == 0) {
if (osVersion >= 10.1) {
Expand All @@ -476,12 +476,12 @@ private void createShortcuts(File installDir, String runnable, String folder, St
} else {
JOptionPane.showMessageDialog(null,
message + "\n" + "To start Naval Robocode, enter the following at a command prompt:\n"
+ installDir.getAbsolutePath() + "/robocode.sh");
+ installDir.getAbsolutePath() + "/naval-robocode.sh");
}
} else {
JOptionPane.showMessageDialog(null,
message + "\n" + "To start Naval Robocode, enter the following at a command prompt:\n"
+ installDir.getAbsolutePath() + "/robocode.sh");
message + "\n" + "To start Naval Robocode, enter the following at a shell prompt:\n"
+ installDir.getAbsolutePath() + "/naval-robocode.sh");
}
}

Expand Down Expand Up @@ -632,7 +632,7 @@ private static String createWindowsRegistryFileAssociation(String installDir, St
sb.append(HKCR).append(progId).append("\\shell]\n");
sb.append(HKCR).append(progId).append("\\shell\\open]\n");
sb.append(HKCR).append(progId).append("\\shell\\open\\command]\n");
sb.append("@=\"").append(getWindowsCmd()).append("\\\"cd \\\"").append(installDir.replaceAll("[\\\\]", "\\\\\\\\")).append("\\\" && robocode.bat ").append(robocodeCmdParam).append(
sb.append("@=\"").append(getWindowsCmd()).append("\\\"cd \\\"").append(installDir.replaceAll("[\\\\]", "\\\\\\\\")).append("\\\" && naval-robocode.bat ").append(robocodeCmdParam).append(
" \\\"%1\\\"\\\"\"\n");

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onTurnEnded(TurnEndedEvent event) {
messagedInitialization = true;
}

if (out.contains("access denied (java.net.SocketPermission")) {
if (out.contains("access denied (\"java.net.SocketPermission")) {
messagedAccessDenied = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {

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

if (out.contains("access denied (java.lang.reflect.ReflectPermission")) {
if (out.contains("access denied (\"java.lang.reflect.ReflectPermission")) {
messagedAccessDenied = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onTurnEnded(TurnEndedEvent event) {
messagedInitialization = true;
}

if (out.contains("access denied (java.net.SocketPermission")) {
if (out.contains("access denied (\"java.net.SocketPermission")) {
messagedAccessDenied = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public void onTurnEnded(TurnEndedEvent event) {
super.onTurnEnded(event);
final String out = event.getTurnSnapshot().getRobots()[1].getOutputStreamSnapshot();

if (out.contains("Preventing tested.robots.FileAttack from access: (java.io.FilePermission C:\\MSDOS.SYS read)")) {
if (out.contains("Preventing tested.robots.FileAttack from access: (\"java.io.FilePermission\" \"C:\\MSDOS.SYS\" \"read\")")) {
messagedRead = true;
}
if (out.contains(
"Preventing tested.robots.FileAttack from access: (java.io.FilePermission C:\\Robocode.attack write)")) {
"Preventing tested.robots.FileAttack from access: (\"java.io.FilePermission\" \"C:\\Robocode.attack\" \"write\")")) {
messagedWrite = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {

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

if (out.contains("access denied (java.io.FilePermission")) {
if (out.contains("access denied (\"java.io.FilePermission")) {
messagedAccessDenied = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {

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

if (out.contains("access denied (java.net.SocketPermission")) {
if (out.contains("access denied (\"java.net.SocketPermission")) {
messagedAccessDenied = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onTurnEnded(TurnEndedEvent event) {

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

if (out.contains("access denied (java.lang.reflect.ReflectPermission")) {
if (out.contains("access denied (\"java.lang.reflect.ReflectPermission")) {
messagedAccessDenied = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public void onTurnEnded(TurnEndedEvent event) {

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ public void createNewJavaFile() {
public void createNewRobot() {
createNewRobot("Robot");
}

public void createNewShip(){
createNewRobot("Ship");
}

public void createNewJuniorRobot() {
createNewRobot("JuniorRobot");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void actionPerformed(ActionEvent e) {

if (source == RobocodeEditorMenuBar.this.getFileNewRobotMenuItem()) {
fileNewRobotActionPerformed();
} else if(source == RobocodeEditorMenuBar.this.getFileNewShipMenuItem()){ //For adding ships
fileNewShipActionPerformed();
} else if (source == RobocodeEditorMenuBar.this.getFileNewJuniorRobotMenuItem()) {
fileNewJuniorRobotActionPerformed();
} else if (source == RobocodeEditorMenuBar.this.getFileNewJavaFileMenuItem()) {
Expand Down Expand Up @@ -102,6 +104,7 @@ public void actionPerformed(ActionEvent e) {
private JMenuItem fileNewJavaFileMenuItem;
private JMenu fileNewMenu;
private JMenuItem fileNewRobotMenuItem;
private JMenuItem fileNewShipMenuItem;
private JMenuItem fileNewJuniorRobotMenuItem;

// Compiler menu
Expand Down Expand Up @@ -198,6 +201,13 @@ private void fileNewRobotActionPerformed() {
getFileSaveMenuItem().setEnabled(true);
getFileSaveAsMenuItem().setEnabled(true);
}

private void fileNewShipActionPerformed(){
editor.createNewShip();

getFileSaveMenuItem().setEnabled(true);
getFileSaveAsMenuItem().setEnabled(true);
}

private void fileNewJuniorRobotActionPerformed() {
editor.createNewJuniorRobot();
Expand Down Expand Up @@ -408,6 +418,7 @@ private JMenu getFileNewMenu() {
fileNewMenu.setText("New");
fileNewMenu.setMnemonic('N');
fileNewMenu.add(getFileNewRobotMenuItem());
fileNewMenu.add(getFileNewShipMenuItem());
fileNewMenu.add(getFileNewJuniorRobotMenuItem());
fileNewMenu.add(getFileNewJavaFileMenuItem());
}
Expand All @@ -424,6 +435,18 @@ private JMenuItem getFileNewRobotMenuItem() {
}
return fileNewRobotMenuItem;
}

//New JMenuItem to add Ships
private JMenuItem getFileNewShipMenuItem(){
if(fileNewShipMenuItem == null){
fileNewShipMenuItem = new JMenuItem();
fileNewShipMenuItem.setText("Ship");

fileNewShipMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, MENU_SHORTCUT_KEY_MASK));
fileNewShipMenuItem.addActionListener(eventHandler);
}
return fileNewShipMenuItem;
}

private JMenuItem getFileNewJuniorRobotMenuItem() {
if (fileNewJuniorRobotMenuItem == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public String getDescription() {
}

public void showVersionsTxt() {
showInBrowser("file://" + new File(FileUtil.getCwd(), "").getAbsoluteFile() + File.separator + "versions.md");
showInBrowser("file://" + new File(FileUtil.getCwd(), "").getAbsoluteFile() + File.separator + "naval-robocode-versions.md");
}

public void showHelpApi() {
Expand Down
Loading