private static void assignScenesToLocations(Map map, Scene[] scenes) { Location[][] locations = map.getLocations(); // start point locations[0][0].setScene(scenes[SceneType.mexicoCity.ordinal()]); locations[0][1].setScene(scenes[SceneType.santasKitchen.ordinal()]); locations[0][2].setScene(scenes[SceneType.northPole.ordinal()]); locations[0][3].setScene(scenes[SceneType.santasWorkshop.ordinal()]); locations[0][4].setScene(scenes[SceneType.stables.ordinal()]); locations[1][0].setScene(scenes[SceneType.ottawa.ordinal()]); locations[1][1].setScene(scenes[SceneType.anchorage.ordinal()]); locations[1][2].setScene(scenes[SceneType.madrid.ordinal()]); locations[1][3].setScene(scenes[SceneType.prague.ordinal()]); locations[1][4].setScene(scenes[SceneType.bangkok.ordinal()]); locations[2][0].setScene(scenes[SceneType.seattle.ordinal()]); locations[2][1].setScene(scenes[SceneType.capeTown.ordinal()]); locations[2][2].setScene(scenes[SceneType.london.ordinal()]); locations[2][3].setScene(scenes[SceneType.mumbai.ordinal()]); locations[2][4].setScene(scenes[SceneType.perth.ordinal()]); locations[3][0].setScene(scenes[SceneType.saoPaulo.ordinal()]); locations[3][1].setScene(scenes[SceneType.bogota.ordinal()]); locations[3][2].setScene(scenes[SceneType.moscow.ordinal()]); locations[3][3].setScene(scenes[SceneType.hongKong.ordinal()]); locations[3][4].setScene(scenes[SceneType.auckland.ordinal()]); locations[4][0].setScene(scenes[SceneType.buenasAires.ordinal()]); locations[4][1].setScene(scenes[SceneType.nairobi.ordinal()]); locations[4][2].setScene(scenes[SceneType.casaBlanca.ordinal()]); locations[4][3].setScene(scenes[SceneType.ulaanbaatar.ordinal()]); locations[4][4].setScene(scenes[SceneType.finish.ordinal()]); // save the locations to the map map.setLocations(locations); }
public static Map createMap() { // create the map Map map = new Map(5, 5); // create a list of the different scenes in the game Scene[] scenes = createScenes(); map.setScenes(scenes); // save the scene to the map // assign the different scenes to locations in the map assignScenesToLocations(map, scenes); return map; }
public static void setActorToLocation(Actor actor, Point coordinates) throws MapControlException, SleighControlException { Map map = SantaChallenge.getCurrentGame().getMap(); int yCoordinate = coordinates.y; int xCoordinate = coordinates.x; if (xCoordinate < 0 || xCoordinate >= map.getNoOfRows() || yCoordinate < 0 || yCoordinate >= map.getNoOfColumns()) { throw new MapControlException( "Can not move actor to location " + coordinates.y + ", " + coordinates.x + " because that location is outside" + " the bounds of the map."); } if (actor == null) { throw new MapControlException("Actor not specified, please choose another option"); } // get the old location in the actor SantaChallenge.getCurrentGame().getActor(); SantaChallenge.getCurrentGame().getMap(); // get new location from the map.locations[](index-values of new row and new column) Location[][] locations = SantaChallenge.getCurrentGame().getMap().getLocations(); locations[coordinates.y][coordinates.x].setActor(actor); // set the actor in the old location to null (call setter function) // set the actor in the new location to the actor passed when the function was called // set the location in the Actor to the new location }