mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:29:46 +02:00
Highscore-Zeug
This commit is contained in:
@@ -7,26 +7,46 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class MapHighscore implements Serializable {
|
public class MapHighscore implements Serializable {
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Map<Integer, ArrayList<String>> highscoreOfAllMaps = new HashMap<Integer, ArrayList<String>>();
|
private Map<Integer, ArrayList<Score>> highscoreOfAllMaps = new HashMap<Integer, ArrayList<Score>>();
|
||||||
|
|
||||||
|
public ArrayList<Score> getHighscores(int mapHash) {
|
||||||
|
if (highscoreOfAllMaps.get(mapHash) == null) {
|
||||||
|
ArrayList<Score> mapHighscores = new ArrayList<Score>();
|
||||||
|
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) {
|
public void setHighscore(int mapHash, String name, int score) {
|
||||||
|
|
||||||
ArrayList<String> mapHighscores = highscoreOfAllMaps.get(mapHash);
|
ArrayList<Score> mapHighscores = highscoreOfAllMaps.get(mapHash);
|
||||||
|
|
||||||
for (int i = 0; i<mapHighscores.size(); i++) {
|
ArrayList<Score> newMapHighscores = new ArrayList<Score>();
|
||||||
|
|
||||||
|
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) {
|
for (int j = i; j<10; j++) {
|
||||||
mapHighscores.remove(10);
|
|
||||||
|
newMapHighscores.add(mapHighscores.get(j));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
highscoreOfAllMaps.put(mapHash, newMapHighscores);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import de.heatup.objects.StaticObject;
|
|||||||
public class MapObjectHandler {
|
public class MapObjectHandler {
|
||||||
|
|
||||||
private static final int singleTileWidth = Config.singleTilePixels;
|
private static final int singleTileWidth = Config.singleTilePixels;
|
||||||
//private static final int triggerAreaAddition = Config.triggerAreaAddition;
|
|
||||||
|
|
||||||
private static ArrayList<StaticObject> allMapObjects = new ArrayList<StaticObject>();
|
private static ArrayList<StaticObject> allMapObjects = new ArrayList<StaticObject>();
|
||||||
private static ArrayList<StaticObject> allWallObjects = new ArrayList<StaticObject>();
|
private static ArrayList<StaticObject> allWallObjects = new ArrayList<StaticObject>();
|
||||||
@@ -27,7 +26,7 @@ public class MapObjectHandler {
|
|||||||
}
|
}
|
||||||
protected static void addAllHardwareTiles(MapEngine me) {
|
protected static void addAllHardwareTiles(MapEngine me) {
|
||||||
for (int i = 0; i<me.getAvailableHardwareTileTypes().size(); i++) {
|
for (int i = 0; i<me.getAvailableHardwareTileTypes().size(); i++) {
|
||||||
char currentType = me.getAvailableHardwareTileTypes().get(i); // current type
|
char currentType = me.getAvailableHardwareTileTypes().get(i);
|
||||||
ArrayList<Point> allPointsOfCurrentType = me.getAllCoordinatesOfTileType(currentType);
|
ArrayList<Point> allPointsOfCurrentType = me.getAllCoordinatesOfTileType(currentType);
|
||||||
Point firstPoint = allPointsOfCurrentType.get(0);
|
Point firstPoint = allPointsOfCurrentType.get(0);
|
||||||
Point lastPoint = allPointsOfCurrentType.get(allPointsOfCurrentType.size()-1);
|
Point lastPoint = allPointsOfCurrentType.get(allPointsOfCurrentType.size()-1);
|
||||||
@@ -35,19 +34,9 @@ public class MapObjectHandler {
|
|||||||
int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth;
|
int currentTilesTotalWidth = lastPoint.x-firstPoint.x+singleTileWidth;
|
||||||
int currentTilesTotalHeight = lastPoint.y-firstPoint.y+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);
|
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(newStaticObject);
|
||||||
// MapObjectHandler.allMapObjects.add(newTriggerObject);
|
|
||||||
MapObjectHandler.allHardwareObjects.add(newStaticObject);
|
MapObjectHandler.allHardwareObjects.add(newStaticObject);
|
||||||
// MapObjectHandler.allHardwareTriggerObjects.add(newTriggerObject);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected static void addAllWallsAndWaysTiles(MapEngine me) {
|
protected static void addAllWallsAndWaysTiles(MapEngine me) {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package de.heatup.objects;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.heatup.testing.Player;
|
||||||
|
|
||||||
|
public class InstancedObjects {
|
||||||
|
private static ArrayList<Player> objects;
|
||||||
|
|
||||||
|
public InstancedObjects() {
|
||||||
|
objects = new ArrayList<Player>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Player> getObjects() {
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addObject(Player object) {
|
||||||
|
InstancedObjects.objects.add(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package de.heatup.ui;
|
||||||
|
|
||||||
|
import java.awt.Point;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import de.heatup.mapengine.MapEngine;
|
||||||
|
import de.heatup.mapengine.SpawnAssistant;
|
||||||
|
import de.heatup.objects.ImageLoader;
|
||||||
|
import de.heatup.objects.InstancedObjects;
|
||||||
|
import de.heatup.testing.Opponent;
|
||||||
|
import de.heatup.testing.Player;
|
||||||
|
import de.heatup.ui.actionPanel.ActionControl;
|
||||||
|
|
||||||
|
public class PanelBuilder {
|
||||||
|
private static JPanel actionPanel;
|
||||||
|
private static JPanel outerPanel;
|
||||||
|
private static JPanel statusPanel;
|
||||||
|
private static JPanel gamePanel;
|
||||||
|
|
||||||
|
public static KeyBindings kb;
|
||||||
|
|
||||||
|
public static Player player01;
|
||||||
|
|
||||||
|
private static InstancedObjects instancedObjects;
|
||||||
|
private static ImageLoader imageLoader;
|
||||||
|
|
||||||
|
public static InstancedObjects getInstancedObjects() {
|
||||||
|
return instancedObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tick() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setPanels(JPanel actionPanel, JPanel outerPanel, JPanel statusPanel, JPanel gamePanel) {
|
||||||
|
PanelBuilder.actionPanel = actionPanel;
|
||||||
|
PanelBuilder.outerPanel = outerPanel;
|
||||||
|
PanelBuilder.statusPanel = statusPanel;
|
||||||
|
PanelBuilder.gamePanel = gamePanel;
|
||||||
|
}
|
||||||
|
public static void startMenu() {
|
||||||
|
|
||||||
|
// StatusPanel bauen
|
||||||
|
StatusPanelAdder.setPanel(statusPanel);
|
||||||
|
StatusPanelAdder.createPanel();
|
||||||
|
|
||||||
|
// ActionPanel bauen
|
||||||
|
ActionControl.setPanel(actionPanel);
|
||||||
|
|
||||||
|
|
||||||
|
createGame(1); /* wird eigentlich vom menue aufgerufen */
|
||||||
|
|
||||||
|
}
|
||||||
|
private static void createGame(int map) {
|
||||||
|
|
||||||
|
instancedObjects = new InstancedObjects();
|
||||||
|
|
||||||
|
imageLoader = new ImageLoader();
|
||||||
|
|
||||||
|
player01 = new Player(); // !!! PLAYER IMMER ZUERST INSTANZIIEREN, DANACH OPPONENTS !!!
|
||||||
|
gamePanel.add(player01);
|
||||||
|
player01.setBounds(25,25,25, 25); // !!! MUSS DRIN BLEIBEN TROTZ NACHTRÄGLICHES SPAWN UMSETZEN !!!
|
||||||
|
|
||||||
|
instancedObjects.getObjects().add(player01);
|
||||||
|
|
||||||
|
// Gegner hinzufügen
|
||||||
|
|
||||||
|
for (int i = 0; i<4; i++) {
|
||||||
|
Opponent newOpponent = new Opponent();
|
||||||
|
gamePanel.add(newOpponent);
|
||||||
|
newOpponent.setBounds(50, 50, 25, 25);
|
||||||
|
instancedObjects.getObjects().add(newOpponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
kb = new KeyBindings(player01);
|
||||||
|
statusPanel.addKeyListener(kb);
|
||||||
|
|
||||||
|
MapEngine me;
|
||||||
|
if (map > 0) {
|
||||||
|
me = new MapEngine(map);
|
||||||
|
} else {
|
||||||
|
me = new MapEngine();
|
||||||
|
}
|
||||||
|
me.addAllToPanel(gamePanel);
|
||||||
|
|
||||||
|
|
||||||
|
for (Player movingObject : instancedObjects.getObjects()) {
|
||||||
|
Point spawnPoint = SpawnAssistant.getPathLocationOnGrid();
|
||||||
|
movingObject.spawnAt(spawnPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImageLoader getImageLoader() {
|
||||||
|
return imageLoader;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user