Learn how to play the Java Battleship game.
If this is your first time playing, install the Battleship core library.
Install the Battleship library at the same directory level as all the other Battleship missions. Run these commands in your terminal to go to the correct directory level and clone the library from GitHub.
cd ..
git clone https://github.com/MimirHQ/battleship.git
At any time, if you need to get the latest version of the Battleship library, navigate to the battleship
folder and run the commands below.
git fetch
git pull
The code for this mission lives in its own folder, called a package. The folder name may vary based on how your instructor named the project. To run the mission, you must change the folder name to match the package name. Find the package name at the top of any Java file in the package: it is the same as the mission ID from the briefing.
If you are inside the folder in your terminal, navigate one level up before you rename. Run the commands below.
cd ..
mv currentfoldername missionid
Then conduct reconnaissance on the enemy ships by reading their source files.
Implement your ship in PlayerShip.java
. Read the API guide to learn how to use the Battleship methods.
Navigate to the directory level that contains the Battleship core library and the mission package. Compile and run the mission by running these commands in your terminal. Use the real mission id instead of missionfoldername
.
javac missionfoldername/Main.java
java missionfoldername.Main
Read the mission results in your terminal and study the output files to learn more about how your ship performed.