// this should replace isSpaceOccupied, allowing "logic" to be down inside // object class // this will return nulls if key not present public CordData getInfoOnCords(Cords cords) { // this would be so much better if goMaps were in a list CordData cordData = new CordData( shipMap.get(cords), enemyMap.get(cords), tileMap.get(cords), mineMap.get(cords)); return cordData; }
private void interpretGameObjectCodes(Cords cords, String gameObjectCode) { // encdode value ends in gameObjectCode when the first [ appears // this allows gameObjects to be passed parameters Log.i("MapData", "gameObjectCode " + gameObjectCode); int indexOfParameterStart = gameObjectCode.indexOf("["); String encodeValue; String parameters; if (indexOfParameterStart != -1) { encodeValue = gameObjectCode.substring(0, indexOfParameterStart); parameters = gameObjectCode.substring(indexOfParameterStart); } else { encodeValue = gameObjectCode; parameters = ""; } // to do: putin checks for bad maps, i.e. throw if a gameObject Map puts // 2 objects on the same key if (encodeValue.equals(Ship.ENCODE_VALUE)) { shipMap.put(cords, new Ship(cords, this)); Log.i("MapData", "ship placed at:" + cords); } else if (encodeValue.equals(Venemy.ENCODE_VALUE)) { System.out.println("venemy added"); enemyMap.put(cords, new Venemy(cords, (Enemy.Callbacks) this)); } else if (encodeValue.equals(Henemy.ENCODE_VALUE)) { System.out.println("henemy added"); enemyMap.put(cords, new Henemy(cords, (Enemy.Callbacks) this)); } else if (encodeValue.equals(Aenemy.ENCODE_VALUE)) { System.out.println("aenemy added"); enemyMap.put(cords, new Aenemy(cords, (Enemy.Callbacks) this)); } else if (encodeValue.equals(Rock.ENCODE_VALUE)) { tileMap.put(cords, new Rock(cords)); } else if (encodeValue.equals(Sea.ENCODE_VALUE)) { tileMap.put(cords, new Sea(cords)); // Log.i("MapData", "Sea added"); } else if (encodeValue.equals(Goal.ENCODE_VALUE)) { tileMap.put(cords, new Goal(cords)); } else if (encodeValue.equals(PathEnemy.ENCODE_VALUE)) { Log.i("MapData", "Path enemy added"); PathEnemy pathEnemy = new PathEnemy(cords, (Enemy.Callbacks) this, parameters); enemyMap.put(cords, pathEnemy); } else if (gameObjectCode.equals("")) { Log.i("MapData", "nothing added"); // because empty tilees can appear on custom maps } else { throw new RuntimeException( "Unrecognised number as GameObjectCode when loading map xml " + gameObjectCode.toString()); } }
// this features super hack reflection, to get static encode_value private String encodeCords(int x, int y) { String encodedCords = ""; Cords cords = new Cords(x, y); // yet more evidence gameObject maps should be in an array/metamap GameObject[] cordsGameObjects = new GameObject[] {tileMap.get(cords), enemyMap.get(cords), shipMap.get(cords)}; GameObject currentGameObject = cordsGameObjects[0]; if (currentGameObject != null) { encodedCords += getGameObjectEncodeValue(currentGameObject); } for (int i = 1; i < cordsGameObjects.length; i++) { currentGameObject = cordsGameObjects[i]; if (currentGameObject != null) { encodedCords += ":"; encodedCords += getGameObjectEncodeValue(currentGameObject); encodedCords += currentGameObject.getEncodedParameters(); } } return encodedCords; }
// should be function of ShipMap class extending GameObjectMap public void clearShipMoves() { for (Ship ship : shipMap.getAll()) { ship.clearPossibleMoves(); } }
public void newTurn() { pastTurns.add(currentTurnSteps.toTurn()); // this is poor, try do some loop shit enemyMap.newTurn(); shipMap.newTurn(); }