diff --git a/src/asteroids/Action.java b/src/asteroids/Action.java index db305901eb52d666140d9281d6e74608c35f096b..09dd18f1690b6b989e16579ea71d9c437bed025b 100644 --- a/src/asteroids/Action.java +++ b/src/asteroids/Action.java @@ -13,12 +13,24 @@ public class Action { public Action() {} + /** + * Create a new action to be executed by the controller + * + * @param thrust 1 is full thrust, 0 is nothing + * @param turn 1 is clockwise, -1 is anticlockwise, 0 is don't turn + * @param shoot true is fire, false is don't fire + */ public Action(double thrust, double turn, boolean shoot) { this.thrust = thrust; this.turn = turn; this.shoot = shoot; } + /** + * Create an action which is a copy of an existing action + * + * @param a the action to clone + */ public Action(Action a) { thrust = a.thrust; turn = a.turn; diff --git a/src/battle/SimpleBattle.java b/src/battle/SimpleBattle.java index 2763b66f78eb9dac237c6342d3607d4d67236b15..7d543cd28f51760d2d57f2c42639d926655d9f43 100644 --- a/src/battle/SimpleBattle.java +++ b/src/battle/SimpleBattle.java @@ -86,7 +86,6 @@ public class SimpleBattle { // apply them to each player's ship, taking actions as necessary Action a1 = p1.getAction(this, 0); Action a2 = p2.getAction(this, 1); - update(a1, a2); } @@ -148,7 +147,7 @@ public class SimpleBattle { return statsClone; } - public void checkCollision(GameObject actor) { + protected void checkCollision(GameObject actor) { // check with all other game objects // but use a hack to only consider interesting interactions // e.g. asteroids do not collide with themselves @@ -189,7 +188,7 @@ public class SimpleBattle { } } - public void fireMissile(Vector2d s, Vector2d d, int playerId) { + protected void fireMissile(Vector2d s, Vector2d d, int playerId) { // need all the usual missile firing code here NeuroShip currentShip = playerId == 0 ? s1 : s2; PlayerStats stats = this.stats.get(playerId); @@ -222,9 +221,27 @@ public class SimpleBattle { s2.draw(g); } + public NeuroShip getShip(int playerID) { + assert playerID < 2; + assert playerID >= 0; + + if (playerID == 0) { + return s1.copy(); + } else { + return s2.copy(); + } + } + public ArrayList<GameObject> getObjects() { - return objects; + return new ArrayList<>(objects); + } + + public PlayerStats getStats(int playerID) { + assert playerID < 2; + assert playerID >= 0; + + return stats.get(playerID); } static class PlayerStats {