| 4 | |
| 5 | public class Player { |
| 6 | public static void main(String[] args) { |
| 7 | // You can use other files in this directory, and in subdirectories. |
| 8 | Extra extra = new Extra(27); |
| 9 | System.out.println(extra.toString()); |
| 10 | |
| 11 | // MapLocation is a data structure you'll use a lot. |
| 12 | MapLocation loc = new MapLocation(Planet.Earth, 10, 20); |
| 13 | System.out.println("loc: "+loc+", one step to the Northwest: "+loc.add(Direction.Northwest)); |
| 14 | System.out.println("loc x: "+loc.getX()); |
| 15 | |
| 16 | // One slightly weird thing: some methods are currently static methods on a static class called bc. |
| 17 | // This will eventually be fixed :/ |
| 18 | System.out.println("Opposite of " + Direction.North + ": " + bc.bcDirectionOpposite(Direction.North)); |
| 19 | |
| 20 | // Connect to the manager, starting the game |
| 21 | GameController gc = new GameController(); |
| 22 | |
| 23 | // Direction is a normal java enum. |
| 24 | Direction[] directions = Direction.values(); |
| 25 | |
| 26 | while (true) { |
| 27 | System.out.println("Current round: "+gc.round()); |
| 28 | // VecUnit is a class that you can think of as similar to ArrayList<Unit>, but immutable. |
| 29 | VecUnit units = gc.myUnits(); |
| 30 | for (int i = 0; i < units.size(); i++) { |
| 31 | Unit unit = units.get(i); |
| 32 | |
| 33 | // Most methods on gc take unit IDs, instead of the unit objects themselves. |
| 34 | if (gc.isMoveReady(unit.id()) && gc.canMove(unit.id(), Direction.Southeast)) { |
| 35 | gc.moveRobot(unit.id(), Direction.Southeast); |
| 36 | } |
| 37 | } |
| 38 | // Submit the actions we've done, and wait for our next turn. |
| 39 | gc.nextTurn(); |
| 40 | } |
| 41 | } |
| 42 | } |