mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-19 00:06:16 +01:00
Lade Figuren auf Spielbrett
This commit is contained in:
parent
fed8a3fd2d
commit
91826b730f
@ -7,15 +7,15 @@
|
||||
|
||||
package pp.monopoly.client;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.system.AppSettings;
|
||||
import pp.monopoly.client.MonopolyAppState;
|
||||
import pp.monopoly.client.gui.TestWorld;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import pp.monopoly.client.gui.TestWorld;
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
/**
|
||||
* Represents the state responsible for managing the battle interface within the Battleship game.
|
||||
@ -71,9 +71,14 @@ public class GameAppState extends MonopolyAppState {
|
||||
* Creates the opponent's map view and adds a grid overlay to it.
|
||||
*/
|
||||
private void initializeGuiComponents() {
|
||||
testWorld = new TestWorld(getApp());
|
||||
// Abrufen der Spielerliste aus der ClientGameLogic
|
||||
List<Player> players = getApp().getGameLogic().getPlayerHandler().getPlayers();
|
||||
|
||||
// Initialisiere TestWorld mit Spielern
|
||||
testWorld = new TestWorld(getApp(), players);
|
||||
testWorld.initializeScene();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the initialized GUI components to the battle node.
|
||||
|
@ -7,6 +7,15 @@
|
||||
|
||||
package pp.monopoly.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import com.jme3.app.DebugKeysAppState;
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.app.StatsAppState;
|
||||
@ -19,9 +28,13 @@ import com.jme3.input.controls.KeyTrigger;
|
||||
import com.jme3.input.controls.MouseButtonTrigger;
|
||||
import com.jme3.system.AppSettings;
|
||||
import com.simsilica.lemur.GuiGlobals;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.BaseStyles;
|
||||
import pp.monopoly.game.client.MonopolyClient;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.graphics.Draw;
|
||||
import static pp.monopoly.Resources.lookup;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.client.gui.StartMenu;
|
||||
import pp.monopoly.client.gui.TestWorld;
|
||||
@ -31,26 +44,12 @@ import pp.monopoly.client.gui.popups.EventCard;
|
||||
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||
import pp.monopoly.game.client.ClientGameLogic;
|
||||
import pp.monopoly.game.client.MonopolyClient;
|
||||
import pp.monopoly.game.client.ServerConnection;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.InfoTextEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.graphics.Draw;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import static pp.monopoly.Resources.lookup;
|
||||
|
||||
/**
|
||||
* The main class for the Battleship client application.
|
||||
@ -136,7 +135,6 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
private BuyCard buyCard;
|
||||
private boolean isBuyCardPopupOpen = false;
|
||||
private final ActionListener BListener = (name, isPressed, tpf) -> handleB(isPressed);
|
||||
private final ActionListener TListener = (name, isPressed, tpf) -> handleT(isPressed);
|
||||
private TestWorld testWorld;
|
||||
|
||||
static {
|
||||
@ -272,7 +270,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
inputManager.addMapping("B", new KeyTrigger(KeyInput.KEY_B));
|
||||
inputManager.addListener(BListener, "B");
|
||||
inputManager.addMapping("T", new KeyTrigger(KeyInput.KEY_T));
|
||||
inputManager.addListener(TListener, "T");
|
||||
|
||||
}
|
||||
|
||||
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen
|
||||
@ -283,13 +281,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
}
|
||||
}
|
||||
|
||||
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen
|
||||
private void handleT(boolean isPressed) {
|
||||
if (isPressed) {
|
||||
testWorld = new TestWorld(this);
|
||||
testWorld.initializeScene();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2,103 +2,115 @@ package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Box;
|
||||
import com.jme3.texture.Texture;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.popups.EventCard;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.EventCardEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
/**
|
||||
* TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat.
|
||||
* Die Kamera wird durch den CameraController gesteuert.
|
||||
* TestWorld zeigt eine einfache Szene mit Spielfeld und Spielfiguren.
|
||||
*/
|
||||
public class TestWorld implements GameEventListener{
|
||||
public class TestWorld {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private CameraController cameraController; // Steuert die Kamera
|
||||
private Toolbar toolbar;
|
||||
private final List<Player> players; // Liste der Spieler, bereits aus GameStart geladen
|
||||
private CameraController cameraController;
|
||||
|
||||
/**
|
||||
* Konstruktor für TestWorld.
|
||||
* Konstruktor für die TestWorld.
|
||||
*
|
||||
* @param app Die Hauptanwendung (MonopolyApp)
|
||||
* @param app Die Hauptanwendung
|
||||
* @param players Die Liste der Spieler mit ihren Figuren
|
||||
*/
|
||||
public TestWorld(MonopolyApp app) {
|
||||
public TestWorld(MonopolyApp app, List<Player> players) {
|
||||
this.app = app;
|
||||
app.getGameLogic().addListener(this);
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert die Szene und startet die Kamerabewegung.
|
||||
* Initialisiert die Szene mit Spielfeld und Figuren.
|
||||
*/
|
||||
public void initializeScene() {
|
||||
app.getGuiNode().detachAllChildren(); // Entferne GUI
|
||||
app.getRootNode().detachAllChildren(); // Entferne andere Szenenobjekte
|
||||
// Entferne bestehende Inhalte
|
||||
app.getGuiNode().detachAllChildren();
|
||||
app.getRootNode().detachAllChildren();
|
||||
|
||||
setSkyColor(); // Setze den Himmel auf hellblau
|
||||
createBoard(); // Erstelle das Spielfeld
|
||||
System.out.println("Szene initialisiert.");
|
||||
|
||||
// Erstelle den CameraController
|
||||
cameraController = new CameraController(
|
||||
app.getCamera(), // Die Kamera der App
|
||||
Vector3f.ZERO, // Fokus auf die Mitte des Spielfelds
|
||||
4, // Radius des Kreises
|
||||
15, // Höhe der Kamera
|
||||
0 // Geschwindigkeit der Bewegung
|
||||
);
|
||||
|
||||
// Füge die Toolbar hinzu
|
||||
toolbar = new Toolbar(app);
|
||||
toolbar.open();
|
||||
|
||||
cameraController.setPosition(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Aktualisiert die Kameraposition.
|
||||
*
|
||||
* @param tpf Zeit pro Frame
|
||||
*/
|
||||
public void update(float tpf) {
|
||||
if (cameraController != null) {
|
||||
cameraController.update(tpf);
|
||||
}
|
||||
// Initialisiere Szene
|
||||
setSkyColor();
|
||||
createBoard();
|
||||
createPlayerFigures(); // Lädt Figuren aus der bereits vorhandenen Liste
|
||||
setupCamera();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Hintergrundfarbe der Szene auf hellblau.
|
||||
*/
|
||||
private void setSkyColor() {
|
||||
app.getViewPort().setBackgroundColor(new ColorRGBA(0.5f, 0.7f, 1.0f, 1.0f)); // Hellblauer Himmel
|
||||
app.getViewPort().setBackgroundColor(new com.jme3.math.ColorRGBA(0.5f, 0.7f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstelle das Spielfeld.
|
||||
* Erstellt das Spielfeld und fügt es zur Szene hinzu.
|
||||
*/
|
||||
private void createBoard() {
|
||||
// Erstelle ein Quadrat
|
||||
Box box = new Box(10, 0.1f, 10); // Dünnes Quadrat für die Textur
|
||||
Geometry geom = new Geometry("Board", box);
|
||||
try {
|
||||
// Erstelle das Spielfeld als flaches Rechteck
|
||||
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);
|
||||
|
||||
// Setze das Material mit Textur
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
Texture texture = app.getAssetManager().loadTexture("Pictures/board2.png");
|
||||
mat.setTexture("ColorMap", texture);
|
||||
geom.setMaterial(mat);
|
||||
// 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.texture.Texture texture = app.getAssetManager().loadTexture("Pictures/board2.png");
|
||||
mat.setTexture("ColorMap", texture);
|
||||
geom.setMaterial(mat);
|
||||
|
||||
app.getRootNode().attachChild(geom);
|
||||
// Positioniere das Spielfeld in der Szene
|
||||
geom.setLocalTranslation(0, -0.1f, 0); // Direkt auf der Grundebene
|
||||
app.getRootNode().attachChild(geom);
|
||||
|
||||
System.out.println("Spielbrett erfolgreich erstellt und hinzugefügt.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Fehler beim Erstellen des Spielfelds: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(EventCardEvent event) {
|
||||
new EventCard(app, event.description()).open();
|
||||
/**
|
||||
* Erstellt die Spielfiguren basierend auf der bereits bekannten Spielerliste.
|
||||
*/
|
||||
private void createPlayerFigures() {
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
Player player = players.get(i);
|
||||
try {
|
||||
// Lade das 3D-Modell der Spielfigur
|
||||
com.jme3.scene.Spatial model = app.getAssetManager().loadModel("Models/" + player.getFigure().getType() + ".j3O");
|
||||
model.setLocalScale(0.5f); // Skaliere das Modell
|
||||
model.setLocalTranslation(0, 0, -i * 2); // Positioniere die Figur auf dem Startfeld
|
||||
|
||||
app.getRootNode().attachChild(model);
|
||||
System.out.println("Figur für Spieler " + player.getId() + " hinzugefügt.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Fehler beim Laden des Modells für Spieler " + player.getId() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Richtet die Kamera auf das Spielfeld aus.
|
||||
*/
|
||||
private void setupCamera() {
|
||||
app.getCamera().setLocation(new com.jme3.math.Vector3f(0, 20, 20)); // Über dem Spielfeld
|
||||
app.getCamera().lookAt(new com.jme3.math.Vector3f(0, 0, 0), com.jme3.math.Vector3f.UNIT_Y); // Fokus auf Spielfeldmitte
|
||||
System.out.println("Kamera eingerichtet.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird bei jedem Frame aufgerufen, um die Szene zu aktualisieren.
|
||||
*
|
||||
* @param tpf Zeit seit dem letzten Frame in Sekunden
|
||||
*/
|
||||
public void update(float tpf) {
|
||||
if (cameraController != null) {
|
||||
cameraController.update(tpf); // Aktualisiere die Kameraposition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,10 @@ package pp.monopoly.client.gui;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector2f;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.Axis;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.IconComponent;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
@ -142,7 +145,7 @@ public class Toolbar extends Dialog implements GameEventListener {
|
||||
Thread diceAnimation = new Thread(() -> {
|
||||
int[] currentFace = {1};
|
||||
try {
|
||||
while (System.currentTimeMillis() - startTime < 2500) { // Animation läuft für 4 Sekunden
|
||||
while (System.currentTimeMillis() - startTime < 2000) { // Animation läuft für 4 Sekunden
|
||||
currentFace[0] = (currentFace[0] % 6) + 1;
|
||||
|
||||
String rotatingImage1 = diceToString(currentFace[0]);
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -79,6 +79,10 @@ public class Player implements FieldVisitor<Void>{
|
||||
public void setFigure(Figure figure) {
|
||||
this.figure = figure;
|
||||
}
|
||||
|
||||
public Figure getFigure(){
|
||||
return figure;
|
||||
}
|
||||
|
||||
public PlayerColor getColor() {
|
||||
switch ((id%6)+1) {
|
||||
@ -540,4 +544,8 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Player{name=" + name + ", figure=" + figure + "}";
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package pp.monopoly.model;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
@Serializable
|
||||
public class Figure implements Item{
|
||||
private final String type;
|
||||
@ -313,5 +312,9 @@ public class Figure implements Item{
|
||||
public void accept(VoidVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user