Command Line Client Environment Setup
Overview
This document provides instructions for running ships on the command line using javac and java.
These instructions were prepared for Java 1.7 and above.
Initial Setup
Create a Spaceship class:
import java.awt.Color; import ihs.apcs.spacebattle.*; import ihs.apcs.spacebattle.commands.*; public class ExampleShip extends BasicSpaceship { public static void main(String[] args) { TextClient.run("127.0.0.1", new ExampleShip()); } @Override public RegistrationData registerShip(int numImages, int worldWidth, int worldHeight) { return new RegistrationData("Example Ship", new Color(255, 255, 255), 0); } @Override public ShipCommand getNextCommand(BasicEnvironment env) { return new IdleCommand(0.1); } }
Be sure to have the gson-2.2.jar and SpaceBattle.jar in a known location (e.g. a 'lib' subdirectory).
Open a Command Prompt.
Execution Instructions
Note: Do not terminate the program with Ctrl+C; instead, type 'QUIT' to gracefully close the connection.
Compile your code with the following command:
javac -cp lib\SpaceBattle.jar;lib\gson-2.2.jar ExampleShip.java
Run your code with the following command:
java -cp lib\SpaceBattle.jar;lib\gson-2.2.jar;. ExampleShip
Note: the addition of the ';.' this is to represent the location of your compiled class file.
Type 'QUIT' in the console window to disconnect your ship.