~workspace $ git clone https://github.com/illinoistechesi/battleship.git
~workspace $ git clone https://github.com/illinoistechesi/battlehub.git
~workspace $ mkdir files
~workspace $ mkdir {yourusername}
Copy the CustomShip.java
file from the battleship/ships folder into your new folder. To make it your own, you will need to change these things:
- Filename: Change “CustomShip.java” to “{NewName}Ship.java” -- The part before “.java” is the name of your ship’s class.
- Line 1: Change “package battleship.ships;” to “package esi17.{yourusername};” -- “esi.{yourusername}” is the name of your personal package.
- Line 6 and 7: Update the name of your ship’s class and your name as its author.
- Line 9: Update the class name in this line to match your ship’s class.
- Line 11: Update the class name. This is your object’s constructor function.
- Line 12 and 13: Update your ship name (can be different from the class name if you want) and your name as its owner.
Modify the base properties of your ship. You have a total of 10 points to distribute amongst the four properties.
- Hull: number of hits it can withstand before being destroyed.
- Firepower: number of shots it can fire on a turn.
- Speed: number of spaces it can move on a turn.
- Range: number of spaces in any direction it can see or fire.
Program your ship’s strategy by filling in the doTurn() method. This method also takes in the game arena as an argument. On each turn, a ship can:
- Can look at other ships within X squares of your ship, where X is the ship’s range value.
- If a ship is in range, you can check its x and y coordinates as well as all of its properties.
- Can move up to X spaces, where X is the ship’s speed value.
- Must choose a direction to move in: North, East, South, or West.
- Can fire up to X times, where X is the ship’s firepower value.
- Must give the x and y coordinates of the square to fire at.
You can see all of the methods available to you in the battleship documentation.
Open battlehub/TeamMain.java
and find lines 20-28. This is where the combatants for a 3v3 battle are specified. Change as needed to test your ship.
~workspace $ javac battlehub/TeamMain.java
~workspace $ java battlehub.TeamMain