mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-19 06:06:15 +01:00
Figuren Bewegung eingefügt
This commit is contained in:
parent
528126aa29
commit
51b879a7c8
@ -38,7 +38,18 @@ import static pp.monopoly.Resources.lookup;
|
|||||||
import pp.monopoly.client.gui.SettingsMenu;
|
import pp.monopoly.client.gui.SettingsMenu;
|
||||||
import pp.monopoly.client.gui.StartMenu;
|
import pp.monopoly.client.gui.StartMenu;
|
||||||
import pp.monopoly.client.gui.TestWorld;
|
import pp.monopoly.client.gui.TestWorld;
|
||||||
import pp.monopoly.client.gui.popups.*;
|
import pp.monopoly.client.gui.popups.Bankrupt;
|
||||||
|
import pp.monopoly.client.gui.popups.BuildingPropertyCard;
|
||||||
|
import pp.monopoly.client.gui.popups.BuyCard;
|
||||||
|
import pp.monopoly.client.gui.popups.BuyHouse;
|
||||||
|
import pp.monopoly.client.gui.popups.EventCardPopup;
|
||||||
|
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||||
|
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||||
|
import pp.monopoly.client.gui.popups.LooserPopUp;
|
||||||
|
import pp.monopoly.client.gui.popups.RepayMortage;
|
||||||
|
import pp.monopoly.client.gui.popups.SellHouse;
|
||||||
|
import pp.monopoly.client.gui.popups.TakeMortage;
|
||||||
|
import pp.monopoly.client.gui.popups.TimeOut;
|
||||||
import pp.monopoly.game.client.ClientGameLogic;
|
import pp.monopoly.game.client.ClientGameLogic;
|
||||||
import pp.monopoly.game.client.MonopolyClient;
|
import pp.monopoly.game.client.MonopolyClient;
|
||||||
import pp.monopoly.game.client.ServerConnection;
|
import pp.monopoly.game.client.ServerConnection;
|
||||||
@ -335,10 +346,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
logic.update(tpf);
|
logic.update(tpf);
|
||||||
stateManager.update(tpf);
|
stateManager.update(tpf);
|
||||||
|
|
||||||
//TODO testing replace later
|
// //TODO testing replace later
|
||||||
if (testWorld != null) {
|
// if (testWorld != null) {
|
||||||
testWorld.update(tpf);
|
// testWorld.update(tpf);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,22 +1,20 @@
|
|||||||
package pp.monopoly.client.gui;
|
package pp.monopoly.client.gui;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
|
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.client.gui.popups.BuyCard;
|
import pp.monopoly.client.gui.popups.BuyCard;
|
||||||
import pp.monopoly.client.gui.popups.ConfirmTrade;
|
|
||||||
import pp.monopoly.client.gui.popups.EventCardPopup;
|
import pp.monopoly.client.gui.popups.EventCardPopup;
|
||||||
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||||
import pp.monopoly.client.gui.popups.GateFieldCard;
|
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||||
import pp.monopoly.client.gui.popups.LooserPopUp;
|
import pp.monopoly.client.gui.popups.LooserPopUp;
|
||||||
import pp.monopoly.client.gui.popups.Rent;
|
|
||||||
import pp.monopoly.client.gui.popups.TimeOut;
|
import pp.monopoly.client.gui.popups.TimeOut;
|
||||||
import pp.monopoly.client.gui.popups.WinnerPopUp;
|
import pp.monopoly.client.gui.popups.WinnerPopUp;
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
import pp.monopoly.game.server.PlayerHandler;
|
import pp.monopoly.game.server.PlayerHandler;
|
||||||
import pp.monopoly.message.server.NotificationMessage;
|
|
||||||
import pp.monopoly.model.fields.BuildingProperty;
|
import pp.monopoly.model.fields.BuildingProperty;
|
||||||
import pp.monopoly.model.fields.FoodField;
|
import pp.monopoly.model.fields.FoodField;
|
||||||
import pp.monopoly.model.fields.GateField;
|
import pp.monopoly.model.fields.GateField;
|
||||||
@ -28,10 +26,10 @@ import pp.monopoly.notification.UpdatePlayerView;
|
|||||||
/**
|
/**
|
||||||
* TestWorld zeigt eine einfache Szene mit Spielfeld und Spielfiguren.
|
* TestWorld zeigt eine einfache Szene mit Spielfeld und Spielfiguren.
|
||||||
*/
|
*/
|
||||||
public class TestWorld implements GameEventListener{
|
public class TestWorld implements GameEventListener {
|
||||||
|
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
private PlayerHandler playerHandler; // Liste der Spieler, bereits aus GameStart geladen
|
private PlayerHandler playerHandler;
|
||||||
private CameraController cameraController;
|
private CameraController cameraController;
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
|
|
||||||
@ -58,10 +56,10 @@ public class TestWorld implements GameEventListener{
|
|||||||
|
|
||||||
System.out.println("Szene initialisiert.");
|
System.out.println("Szene initialisiert.");
|
||||||
|
|
||||||
// Initialisiere Szene
|
//Füge Inhalte ein
|
||||||
setSkyColor();
|
setSkyColor();
|
||||||
createBoard();
|
createBoard();
|
||||||
createPlayerFigures(); // Lädt Figuren aus der bereits vorhandenen Liste
|
createPlayerFigures();
|
||||||
toolbar = new Toolbar(app);
|
toolbar = new Toolbar(app);
|
||||||
toolbar.open();
|
toolbar.open();
|
||||||
}
|
}
|
||||||
@ -78,21 +76,23 @@ public class TestWorld implements GameEventListener{
|
|||||||
*/
|
*/
|
||||||
private void createBoard() {
|
private void createBoard() {
|
||||||
try {
|
try {
|
||||||
// Erstelle das Spielfeld als flaches Rechteck
|
com.jme3.scene.shape.Box box = new com.jme3.scene.shape.Box(10, 0.1f, 10);
|
||||||
com.jme3.scene.shape.Box box = new com.jme3.scene.shape.Box(10, 0.1f, 10); // Breite, Höhe, Tiefe
|
|
||||||
com.jme3.scene.Geometry geom = new com.jme3.scene.Geometry("Board", box);
|
com.jme3.scene.Geometry geom = new com.jme3.scene.Geometry("Board", box);
|
||||||
|
|
||||||
// Lade und setze das Material mit der Textur
|
|
||||||
com.jme3.material.Material mat = new com.jme3.material.Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
com.jme3.material.Material mat = new com.jme3.material.Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
com.jme3.texture.Texture texture = app.getAssetManager().loadTexture("Pictures/board2.png");
|
com.jme3.texture.Texture texture = app.getAssetManager().loadTexture("Pictures/board2.png");
|
||||||
mat.setTexture("ColorMap", texture);
|
mat.setTexture("ColorMap", texture);
|
||||||
geom.setMaterial(mat);
|
geom.setMaterial(mat);
|
||||||
|
|
||||||
// Positioniere das Spielfeld in der Szene
|
geom.setLocalTranslation(0, -0.1f, 0);
|
||||||
geom.setLocalTranslation(0, -0.1f, 0); // Direkt auf der Grundebene
|
|
||||||
|
com.jme3.math.Quaternion rotation = new com.jme3.math.Quaternion();
|
||||||
|
rotation.fromAngleAxis(com.jme3.math.FastMath.HALF_PI, com.jme3.math.Vector3f.UNIT_Y);
|
||||||
|
geom.setLocalRotation(rotation);
|
||||||
|
|
||||||
app.getRootNode().attachChild(geom);
|
app.getRootNode().attachChild(geom);
|
||||||
|
|
||||||
System.out.println("Spielbrett erfolgreich erstellt und hinzugefügt.");
|
System.out.println("Spielbrett erfolgreich erstellt, gedreht und hinzugefügt.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Fehler beim Erstellen des Spielfelds: " + e.getMessage());
|
System.err.println("Fehler beim Erstellen des Spielfelds: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -105,70 +105,154 @@ public class TestWorld implements GameEventListener{
|
|||||||
for (int i = 0; i < playerHandler.getPlayers().size(); i++) {
|
for (int i = 0; i < playerHandler.getPlayers().size(); i++) {
|
||||||
Player player = playerHandler.getPlayers().get(i);
|
Player player = playerHandler.getPlayers().get(i);
|
||||||
try {
|
try {
|
||||||
// Lade das 3D-Modell der Spielfigur
|
com.jme3.scene.Spatial model = app.getAssetManager().loadModel(
|
||||||
com.jme3.scene.Spatial model = app.getAssetManager().loadModel("Models/" + player.getFigure().getType() + "/" + player.getFigure().getType() + ".j3o");
|
"Models/" + player.getFigure().getType() + "/" + player.getFigure().getType() + ".j3o"
|
||||||
model.setLocalScale(0.5f); // Skaliere das Modell
|
);
|
||||||
|
model.setLocalScale(0.5f);
|
||||||
|
|
||||||
// Positioniere die Figur unten rechts
|
Vector3f startPosition = calculateFieldPosition(player.getFieldID(), i);
|
||||||
float startX = 9.1f; // X-Koordinate für die Ecke unten rechts
|
model.setLocalTranslation(startPosition);
|
||||||
float startZ = -9.1f; // Z-Koordinate für die Ecke unten rechts
|
|
||||||
float spacing = 0.4f; // Abstand zwischen den Figuren
|
|
||||||
model.setLocalTranslation(startX, 0, startZ - (i * spacing)); // Position anpassen
|
|
||||||
|
|
||||||
|
model.setName("PlayerFigure_" + player.getId());
|
||||||
app.getRootNode().attachChild(model);
|
app.getRootNode().attachChild(model);
|
||||||
System.out.println("Figur für Spieler " + player.getId() + " positioniert bei (" + startX + ", 0, " + (startZ - (i * spacing)) + ")");
|
|
||||||
|
System.out.println("Figur für Spieler " + player.getId() + " erstellt bei " + startPosition);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Fehler beim Laden des Modells für Spieler " + player.getId() + ": " + e.getMessage());
|
System.err.println("Fehler beim Laden des Modells für Spieler " + player.getId() + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private Vector3f calculateFieldPosition(int fieldID, int playerIndex) {
|
||||||
* Wird bei jedem Frame aufgerufen, um die Szene zu aktualisieren.
|
float offset = 0.1f;
|
||||||
*
|
float baseX = 0.0f;
|
||||||
* @param tpf Zeit seit dem letzten Frame in Sekunden
|
float baseZ = 0.0f;
|
||||||
*/
|
|
||||||
public void update(float tpf) {
|
switch (fieldID) {
|
||||||
if (cameraController != null) {
|
case 0: baseX = -9.1f; baseZ = -9.1f; break;
|
||||||
cameraController.update(tpf); // Aktualisiere die Kameraposition
|
case 1: baseX = -6.5f; baseZ = -9.1f; break;
|
||||||
|
case 2: baseX = -4.9f; baseZ = -9.1f; break;
|
||||||
|
case 3: baseX = -3.3f; baseZ = -9.1f; break;
|
||||||
|
case 4: baseX = -1.6f; baseZ = -9.1f; break;
|
||||||
|
case 5: baseX = 0.0f; baseZ = -9.1f; break;
|
||||||
|
case 6: baseX = 1.6f; baseZ = -9.1f; break;
|
||||||
|
case 7: baseX = 3.3f; baseZ = -9.1f; break;
|
||||||
|
case 8: baseX = 4.9f; baseZ = -9.1f; break;
|
||||||
|
case 9: baseX = 6.5f; baseZ = -9.1f; break;
|
||||||
|
case 10: baseX = 9.1f; baseZ = -9.1f; break;
|
||||||
|
case 11: baseX = 9.1f; baseZ = -6.5f; break;
|
||||||
|
case 12: baseX = 9.1f; baseZ = -4.9f; break;
|
||||||
|
case 13: baseX = 9.1f; baseZ = -3.3f; break;
|
||||||
|
case 14: baseX = 9.1f; baseZ = -1.6f; break;
|
||||||
|
case 15: baseX = 9.1f; baseZ = 0.0f; break;
|
||||||
|
case 16: baseX = 9.1f; baseZ = 1.6f; break;
|
||||||
|
case 17: baseX = 9.1f; baseZ = 3.3f; break;
|
||||||
|
case 18: baseX = 9.1f; baseZ = 4.9f; break;
|
||||||
|
case 19: baseX = 9.1f; baseZ = 6.5f; break;
|
||||||
|
case 20: baseX = 9.1f; baseZ = 9.1f; break;
|
||||||
|
case 21: baseX = 6.5f; baseZ = 9.1f; break;
|
||||||
|
case 22: baseX = 4.9f; baseZ = 9.1f; break;
|
||||||
|
case 23: baseX = 3.3f; baseZ = 9.1f; break;
|
||||||
|
case 24: baseX = 1.6f; baseZ = 9.1f; break;
|
||||||
|
case 25: baseX = 0.0f; baseZ = 9.1f; break;
|
||||||
|
case 26: baseX = -1.6f; baseZ = 9.1f; break;
|
||||||
|
case 27: baseX = -3.3f; baseZ = 9.1f; break;
|
||||||
|
case 28: baseX = -4.9f; baseZ = 9.1f; break;
|
||||||
|
case 29: baseX = -6.5f; baseZ = 9.1f; break;
|
||||||
|
case 30: baseX = -9.1f; baseZ = 9.1f; break;
|
||||||
|
case 31: baseX = -9.1f; baseZ = 6.5f; break;
|
||||||
|
case 32: baseX = -9.1f; baseZ = 4.9f; break;
|
||||||
|
case 33: baseX = -9.1f; baseZ = 3.3f; break;
|
||||||
|
case 34: baseX = -9.1f; baseZ = 1.6f; break;
|
||||||
|
case 35: baseX = -9.1f; baseZ = 0.0f; break;
|
||||||
|
case 36: baseX = -9.1f; baseZ = -1.6f; break;
|
||||||
|
case 37: baseX = -9.1f; baseZ = -3.3f; break;
|
||||||
|
case 38: baseX = -9.1f; baseZ = -4.9f; break;
|
||||||
|
case 39: baseX = -9.1f; baseZ = -6.5f; break;
|
||||||
|
default: throw new IllegalArgumentException("Ungültige Feld-ID: " + fieldID);
|
||||||
|
}
|
||||||
|
|
||||||
|
float xOffset = (playerIndex % 2) * offset;
|
||||||
|
float zOffset = (playerIndex / 2) * offset;
|
||||||
|
|
||||||
|
return new Vector3f(baseX + xOffset, 0, baseZ + zOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void movePlayerFigure(Player player) {
|
||||||
|
int fieldID = player.getFieldID();
|
||||||
|
int playerIndex = playerHandler.getPlayers().indexOf(player); // Hole den Index des Spielers
|
||||||
|
Vector3f targetPosition = calculateFieldPosition(fieldID, playerIndex);
|
||||||
|
|
||||||
|
String figureName = "PlayerFigure_" + player.getId();
|
||||||
|
com.jme3.scene.Spatial figure = app.getRootNode().getChild(figureName);
|
||||||
|
|
||||||
|
if (figure != null) {
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
app.enqueue(() -> {
|
||||||
|
figure.setLocalTranslation(targetPosition);
|
||||||
|
System.out.println("Spieler " + player.getId() + " bewegt zu Feld " + fieldID + " (" + targetPosition + ")");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 3000); // 3 Sekunden Verzögerung für die Bewegung
|
||||||
|
} else {
|
||||||
|
System.err.println("Figur für Spieler " + player.getId() + " nicht gefunden.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(PopUpEvent event) {
|
public void receivedEvent(PopUpEvent event) {
|
||||||
if(event.msg().equals("Buy")) {
|
if (event.msg().equals("Buy")) {
|
||||||
|
// Erstelle einen Timer, um den Delay umzusetzen
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// GUI-Operationen im jMonkey-Thread ausführen
|
||||||
|
app.enqueue(() -> {
|
||||||
int field = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID();
|
int field = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID();
|
||||||
Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field);
|
Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field);
|
||||||
|
|
||||||
if (fieldObject instanceof BuildingProperty) {
|
if (fieldObject instanceof BuildingProperty) {
|
||||||
new BuyCard(app).open();
|
new BuyCard(app).open();
|
||||||
} else if (fieldObject instanceof GateField){
|
} else if (fieldObject instanceof GateField) {
|
||||||
new GateFieldCard(app).open();
|
new GateFieldCard(app).open();
|
||||||
} else if (fieldObject instanceof FoodField) {
|
} else if (fieldObject instanceof FoodField) {
|
||||||
new FoodFieldCard(app).open();
|
new FoodFieldCard(app).open();
|
||||||
}
|
}
|
||||||
} else if(event.msg().equals("Winner")) {
|
});
|
||||||
|
}
|
||||||
|
}, 5000); // Verzögerung in Millisekunden
|
||||||
|
} else if (event.msg().equals("Winner")) {
|
||||||
new WinnerPopUp(app).open();
|
new WinnerPopUp(app).open();
|
||||||
} else if(event.msg().equals("Looser")) {
|
} else if (event.msg().equals("Looser")) {
|
||||||
new LooserPopUp(app).open();
|
new LooserPopUp(app).open();
|
||||||
} else if(event.msg().equals("timeout")) {
|
} else if (event.msg().equals("timeout")) {
|
||||||
new TimeOut(app).open();
|
new TimeOut(app).open();
|
||||||
} else if (event.msg().equals("tradeRequest")) {
|
|
||||||
new ConfirmTrade(app).open();
|
|
||||||
} else if(event.msg().equals("rent")) {
|
|
||||||
new Rent(app, ( (NotificationMessage) event.message()).getRentOwner(), ( (NotificationMessage) event.message()).getRentAmount() ).open();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(EventCardEvent event) {
|
public void receivedEvent(EventCardEvent event) {
|
||||||
new EventCardPopup(app, event.description()).open();
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
app.enqueue(() -> new EventCardPopup(app, event.description()).open());
|
||||||
}
|
}
|
||||||
|
}, 5000); // 5 Sekunden Verzögerung für Event-Popups
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(UpdatePlayerView event) {
|
public void receivedEvent(UpdatePlayerView event) {
|
||||||
this.playerHandler = app.getGameLogic().getPlayerHandler();
|
this.playerHandler = app.getGameLogic().getPlayerHandler();
|
||||||
cameraController.setPosition(playerHandler.getPlayerById(app.getId()).getFieldID());
|
|
||||||
cameraController.update(0);
|
// Aktualisiere die Position aller Spielerfiguren
|
||||||
|
for (Player player : playerHandler.getPlayers()) {
|
||||||
|
movePlayerFigure(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user