diff --git a/HeatUp/src/de/heatup/highscore/MapHighscore.java b/HeatUp/src/de/heatup/highscore/MapHighscore.java index afce6d3..7630240 100644 --- a/HeatUp/src/de/heatup/highscore/MapHighscore.java +++ b/HeatUp/src/de/heatup/highscore/MapHighscore.java @@ -6,27 +6,47 @@ import java.util.HashMap; import java.util.Map; public class MapHighscore implements Serializable { - - /** - * - */ + private static final long serialVersionUID = 1L; - private Map> highscoreOfAllMaps = new HashMap>(); + private Map> highscoreOfAllMaps = new HashMap>(); + + public ArrayList getHighscores(int mapHash) { + if (highscoreOfAllMaps.get(mapHash) == null) { + ArrayList mapHighscores = new ArrayList(); + for (int n = 0; n<10; n++) { + mapHighscores.add(new Score()); + } + highscoreOfAllMaps.put(mapHash, mapHighscores); + } + return highscoreOfAllMaps.get(mapHash); + } public void setHighscore(int mapHash, String name, int score) { - ArrayList mapHighscores = highscoreOfAllMaps.get(mapHash); + ArrayList mapHighscores = highscoreOfAllMaps.get(mapHash); - for (int i = 0; i newMapHighscores = new ArrayList(); + + int i = 0; + + for (i = 0; i<10; i++) { + if (mapHighscores.get(i).getScore() > score) { + newMapHighscores.add(mapHighscores.get(i)); + } else { + newMapHighscores.add(new Score(name, score)); + break; + } } - if (mapHighscores.size()>10) { - mapHighscores.remove(10); + for (int j = i; j<10; j++) { + + newMapHighscores.add(mapHighscores.get(j)); + } - + highscoreOfAllMaps.put(mapHash, newMapHighscores); + } } diff --git a/HeatUp/src/de/heatup/highscore/Score.java b/HeatUp/src/de/heatup/highscore/Score.java new file mode 100644 index 0000000..6b5fef6 --- /dev/null +++ b/HeatUp/src/de/heatup/highscore/Score.java @@ -0,0 +1,38 @@ +package de.heatup.highscore; + +import java.io.Serializable; + +public class Score implements Serializable { + + private static final long serialVersionUID = 1L; + + private String name; + private int score; + + public Score() { + name = "default"; + score = 2342; + } + + public Score(String name, int score) { + this.name = name; + this.score = score; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getScore() { + return score; + } + + public void setScore(int score) { + this.score = score; + } + +} diff --git a/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java b/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java index 3182ead..a2e587a 100644 --- a/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java +++ b/HeatUp/src/de/heatup/mapengine/MapObjectHandler.java @@ -9,7 +9,6 @@ import de.heatup.objects.StaticObject; public class MapObjectHandler { private static final int singleTileWidth = Config.singleTilePixels; - //private static final int triggerAreaAddition = Config.triggerAreaAddition; private static ArrayList allMapObjects = new ArrayList(); private static ArrayList allWallObjects = new ArrayList(); @@ -27,7 +26,7 @@ public class MapObjectHandler { } protected static void addAllHardwareTiles(MapEngine me) { for (int i = 0; i allPointsOfCurrentType = me.getAllCoordinatesOfTileType(currentType); Point firstPoint = allPointsOfCurrentType.get(0); Point lastPoint = allPointsOfCurrentType.get(allPointsOfCurrentType.size()-1); @@ -35,19 +34,9 @@ public class MapObjectHandler { int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth; int currentTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth; - /* obsolet - int currentTriggerTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth+triggerAreaAddition; - int currentTriggerTilesTotalHeight = lastPoint.y-firstPoint.y+singleTileWidth+triggerAreaAddition; - Point currentTriggerTilesFirstPoint = new Point(firstPoint.x-(triggerAreaAddition/2),firstPoint.y-(triggerAreaAddition/2)); - */ - StaticObject newStaticObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight); - // Trigger Object - obsolet - // StaticObject newTriggerObject = new StaticObject(currentType, firstPoint, currentTilesTotalWidth, currentTilesTotalHeight, true); MapObjectHandler.allMapObjects.add(newStaticObject); - // MapObjectHandler.allMapObjects.add(newTriggerObject); MapObjectHandler.allHardwareObjects.add(newStaticObject); - // MapObjectHandler.allHardwareTriggerObjects.add(newTriggerObject); } } protected static void addAllWallsAndWaysTiles(MapEngine me) {