now able to add all nessecary models

This commit is contained in:
Johannes Schmelz 2024-12-08 02:16:40 +01:00
parent 8614faf940
commit 159927e52c
10 changed files with 155 additions and 45 deletions

View File

@ -7,6 +7,8 @@ import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight; import com.jme3.light.DirectionalLight;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
@ -96,6 +98,7 @@ public class BoardAppState extends MonopolyAppState {
setupScene(); setupScene();
if (bobTheBuilder == null) { if (bobTheBuilder == null) {
bobTheBuilder = new BobTheBuilder(getApp(), getApp().getRootNode()); bobTheBuilder = new BobTheBuilder(getApp(), getApp().getRootNode());
System.out.println("LISTENER IS REGISTEDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD");
getGameLogic().addListener(bobTheBuilder); getGameLogic().addListener(bobTheBuilder);
} }
getApp().getRootNode().attachChild(viewNode); getApp().getRootNode().attachChild(viewNode);
@ -198,8 +201,11 @@ public class BoardAppState extends MonopolyAppState {
final float x = board.getWidth(); final float x = board.getWidth();
final float y = board.getHeight(); final float y = board.getHeight();
final Box seaMesh = new Box(y, 0.1f, x); final Box seaMesh = new Box(y, 0.1f, x);
final Geometry seaGeo = new Geometry("sea", seaMesh); //NON-NLS final Geometry seaGeo = new Geometry("sea", seaMesh); //NONs-NLS
seaGeo.setLocalTranslation(new Vector3f(0, -0.1f, 0)); seaGeo.setLocalTranslation(new Vector3f(0, -0.1f, 0));
Quaternion rotation = new com.jme3.math.Quaternion();
rotation.fromAngleAxis(FastMath.HALF_PI, com.jme3.math.Vector3f.UNIT_Y);
seaGeo.setLocalRotation(rotation);
final Material seaMat = new Material(getApp().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); final Material seaMat = new Material(getApp().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
Texture texture = getApp().getAssetManager().loadTexture("Pictures/board2.png"); Texture texture = getApp().getAssetManager().loadTexture("Pictures/board2.png");
seaMat.setTexture("DiffuseMap", texture); seaMat.setTexture("DiffuseMap", texture);

View File

@ -1,13 +1,12 @@
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
import java.lang.management.PlatformLoggingMXBean; import static com.jme3.material.Materials.LIGHTING;
import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode; import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode; import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Node; import com.jme3.scene.Node;
@ -38,35 +37,74 @@ public class BobTheBuilder extends GameBoardSynchronizer {
addExisting(); addExisting();
} }
@Override @Override
public Spatial visit(Figure figure) { public Spatial visit(Figure figure) {
try { final Node node = new Node(FIGURE);
// Lade das Modell node.attachChild(createFigure(figure));
com.jme3.scene.Spatial model = app.getAssetManager().loadModel(
"models/" + "Spielfiguren/" + figure.getType() + "/" + figure.getType() + ".j3o");
// Skaliere und positioniere das Modell // Setze die Position basierend auf der Feld-ID
model.setLocalScale(0.5f); node.setLocalTranslation(figure.getPos());
model.setLocalTranslation(figure.getPosition());
// Setze die Rotation basierend auf der Feld-ID // Setze die Rotation basierend auf der Feld-ID
model.setLocalRotation(figure.getRot().toQuaternion()); node.setLocalRotation(figure.getRot().toQuaternion());
// node.addControl(new FigureControl(figure));
return node;
}
return model;
} catch (Exception e) {
System.err.println("Fehler beim Laden des Modells für Spieler " + e.getMessage());
}
return createBox(figure);
}
@Override @Override
public Spatial visit(Hotel hotel) { public Spatial visit(Hotel hotel) {
return null; final Node node = new Node(HOTEL);
node.attachChild(createHotel(hotel));
// Setze die Position basierend auf der Feld-ID
node.setLocalTranslation(hotel.getPos());
// Setze die Rotation basierend auf der Feld-ID
node.setLocalRotation(hotel.getRot().toQuaternion());
return node;
} }
@Override @Override
public Spatial visit(House figure) { public Spatial visit(House house) {
return null; final Node node = new Node(HOUSE);
node.attachChild(createHouse(house));
// Setze die Position basierend auf der Feld-ID
node.setLocalTranslation(house.getPos());
// Setze die Rotation basierend auf der Feld-ID
node.setLocalRotation(house.getAlignment());
return node;
}
private Spatial createFigure(Figure figure) {
// Lade das Modell
Spatial model = app.getAssetManager().loadModel("models/" + "Spielfiguren/" + figure.getType() + "/" + figure.getType() + ".j3o");
// Skaliere und positioniere das Modell
model.scale(0.5f);
return model;
}
private Spatial createHotel(Hotel hotel) {
Spatial model = app.getAssetManager().loadModel("models/Hotel/Hotel.j3o");
model.scale(0.2f);
model.setShadowMode(ShadowMode.CastAndReceive);
return model;
}
private Spatial createHouse(House house) {
Spatial model = app.getAssetManager().loadModel("models/Haus/"+house.getStage()+"Haus.j3o");
model.scale(0.5f);
model.setShadowMode(ShadowMode.CastAndReceive);
return model;
} }
/** /**
@ -108,8 +146,9 @@ public class BobTheBuilder extends GameBoardSynchronizer {
@Override @Override
public void receivedEvent(UpdatePlayerView event) { public void receivedEvent(UpdatePlayerView event) {
clear();
board.removePlayers(); board.removePlayers();
//TODO transition animation
for (Player player : app.getGameLogic().getPlayerHandler().getPlayers()) { for (Player player : app.getGameLogic().getPlayerHandler().getPlayers()) {
board.add(player.getFigure()); board.add(player.getFigure());
} }

View File

@ -7,6 +7,7 @@ import pp.monopoly.model.Visitor;
import pp.monopoly.notification.DiceRollEvent; import pp.monopoly.notification.DiceRollEvent;
import pp.monopoly.notification.GameEventListener; import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.ItemAddedEvent; import pp.monopoly.notification.ItemAddedEvent;
import pp.monopoly.notification.ItemRemovedEvent;
import pp.monopoly.notification.UpdatePlayerView; import pp.monopoly.notification.UpdatePlayerView;
import pp.monopoly.model.Board; import pp.monopoly.model.Board;
import pp.monopoly.model.Figure; import pp.monopoly.model.Figure;
@ -58,22 +59,28 @@ abstract class GameBoardSynchronizer extends ModelViewSynchronizer<Item> impleme
board.getItems().forEach(this::add); board.getItems().forEach(this::add);
} }
/**
* Handles the event when an item is removed from the ship map.
* Removes the visual representation of the item from the view if it belongs to the synchronized ship map.
*
* @param event the event indicating that an item has been removed from the ship map
*/
@Override @Override
public void receivedEvent(UpdatePlayerView event) { public void receivedEvent(ItemRemovedEvent event) {
for (Item item : board.getItems()) { if (board == event.board())
// if(!(item instanceof Figure)) { delete(event.item());
delete(item);
add(item);
// }
}
} }
/**
* Handles the event when an item is added to the ship map.
* Adds the visual representation of the new item to the view if it belongs to the synchronized ship map.
*
* @param event the event indicating that an item has been added to the ship map
*/
@Override @Override
public void receivedEvent(DiceRollEvent event) { public void receivedEvent(ItemAddedEvent event) {
for (Item item : board.getItems()) { if (board == event.board()){
if(item instanceof Figure) { add(event.item());
//????????????????????????????????????????
}
} }
} }

View File

@ -59,7 +59,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
private final List<GameEventListener> listeners = new ArrayList<>(); private final List<GameEventListener> listeners = new ArrayList<>();
/** The game board representing the player's current state. */ /** The game board representing the player's current state. */
private Board board = new Board(10, 10, null); private Board board = new Board(10, 10, this);
/** The current state of the client game logic. */ /** The current state of the client game logic. */
private ClientState state = new LobbyState(this); private ClientState state = new LobbyState(this);
@ -310,6 +310,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
@Override @Override
public void received(BuildInfo msg) { public void received(BuildInfo msg) {
System.out.println("TRIGGER BUILD INFO");
if (msg.isAdded()) { if (msg.isAdded()) {
BuildingProperty property = ((BuildingProperty)boardManager.getFieldAtIndex(msg.getId())); BuildingProperty property = ((BuildingProperty)boardManager.getFieldAtIndex(msg.getId()));
if (property.getHotel() == 1 ) { if (property.getHotel() == 1 ) {

View File

@ -98,6 +98,17 @@ public class ServerGameLogic implements ClientInterpreter {
} }
} }
/**
* Sends a message to all players in the game.
*
* @param msg the ServerMessage to send
*/
void sendAll(ServerMessage msg) {
for (Player player : playerHandler.getPlayers()) {
send(player, msg);
}
}
/** /**
* Adds a new player to the game if the game is in the LOBBY state and the maximum * Adds a new player to the game if the game is in the LOBBY state and the maximum
* player limit has not been reached. * player limit has not been reached.
@ -412,7 +423,8 @@ public class ServerGameLogic implements ClientInterpreter {
for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) { for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
if (boardManager.canBuild(field) && sender.getAccountBalance() >= field.getHousePrice()) { if (boardManager.canBuild(field) && sender.getAccountBalance() >= field.getHousePrice()) {
field.build(); field.build();
send(playerHandler.getPlayerById(from), new BuildInfo(field.getId(), true)); updateAllPlayers();
sendAll( new BuildInfo(field.getId(), true));
sender.pay(field.getHousePrice()); sender.pay(field.getHousePrice());
} }
} }
@ -420,6 +432,8 @@ public class ServerGameLogic implements ClientInterpreter {
for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) { for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
if (boardManager.canSell(field)) { if (boardManager.canSell(field)) {
field.sell(); field.sell();
updateAllPlayers();
sendAll( new BuildInfo(field.getId(), false));
sender.earnMoney(field.getHousePrice() / 2); sender.earnMoney(field.getHousePrice() / 2);
} }
} }
@ -434,9 +448,9 @@ public class ServerGameLogic implements ClientInterpreter {
} else if (msg.getKeyword().equals("PayJail")) { } else if (msg.getKeyword().equals("PayJail")) {
playerHandler.getPlayerById(from).payBail(); playerHandler.getPlayerById(from).payBail();
} else if(msg.getKeyword().equals("hack")) { } else if(msg.getKeyword().equals("hack")) {
for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) { // for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
bp.build(); // bp.build();
} // }
for(PropertyField field : boardManager.getBoard().stream().filter(p -> p instanceof PropertyField).map(p -> (PropertyField) p).collect(Collectors.toList())) { for(PropertyField field : boardManager.getBoard().stream().filter(p -> p instanceof PropertyField).map(p -> (PropertyField) p).collect(Collectors.toList())) {
field.setOwner(playerHandler.getPlayerById(0)); field.setOwner(playerHandler.getPlayerById(0));
playerHandler.getPlayerById(0).addProperty(field.getId()); playerHandler.getPlayerById(0).addProperty(field.getId());

View File

@ -59,7 +59,7 @@ public class Board {
*/ */
private void addItem(Item item) { private void addItem(Item item) {
items.add(item); items.add(item);
notifyListeners((GameEvent) new ItemAddedEvent(this, item)); notifyListeners(new ItemAddedEvent(this, item));
} }
/** /**

View File

@ -65,7 +65,7 @@ public class Figure implements Item{
* *
* @return the position of the Figure * @return the position of the Figure
*/ */
public Vector3f getPosition() { public Vector3f getPos() {
return position; return position;
} }

View File

@ -40,7 +40,7 @@ public class Hotel implements Item{
* *
* @return the position of the building on the field * @return the position of the building on the field
*/ */
public Vector3f getBuildingPosition() { public Vector3f getPos() {
float baseX = 0.0f; float baseX = 0.0f;
float baseZ = 0.0f; float baseZ = 0.0f;
@ -90,4 +90,10 @@ public class Hotel implements Item{
return new Vector3f(baseX, 0, baseZ); return new Vector3f(baseX, 0, baseZ);
} }
@Override
public Rotation getRot() {
// TODO
return Rotation.NORTH;
}
} }

View File

@ -1,5 +1,7 @@
package pp.monopoly.model; package pp.monopoly.model;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
@ -56,7 +58,7 @@ public class House implements Item{
* *
* @return the position of the building on the field * @return the position of the building on the field
*/ */
public Vector3f getBuildingPosition() { public Vector3f getPos() {
float baseX = 0.0f; float baseX = 0.0f;
float baseZ = 0.0f; float baseZ = 0.0f;
@ -107,4 +109,22 @@ public class House implements Item{
return new Vector3f(baseX, 0, baseZ); return new Vector3f(baseX, 0, baseZ);
} }
@Override
public Rotation getRot() {
//TODO
return Rotation.NORTH;
}
public Quaternion getAlignment() {
Quaternion rotation = new Quaternion();
if (fieldID >= 1 && fieldID <= 10) {
rotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y);
} else if (fieldID >= 21 && fieldID <= 30) {
rotation.fromAngleAxis(3 * FastMath.HALF_PI, Vector3f.UNIT_Y);
} else if (fieldID >= 31 && fieldID <= 39) {
rotation.fromAngleAxis(FastMath.PI, Vector3f.UNIT_Y);
}
return rotation;
}
} }

View File

@ -7,6 +7,8 @@
package pp.monopoly.model; package pp.monopoly.model;
import com.jme3.math.Vector3f;
/** /**
* An interface representing any item on a board * An interface representing any item on a board
* It extends the IntPosition interface to provide position information. * It extends the IntPosition interface to provide position information.
@ -28,4 +30,19 @@ public interface Item {
* @param visitor the visitor performing operations on the item * @param visitor the visitor performing operations on the item
*/ */
void accept(VoidVisitor visitor); void accept(VoidVisitor visitor);
/**
* Returns the rotation of the item on the board.
*
* @return the rotation of the item on the board
*/
Rotation getRot();
/**
* Returns the position of the item on the board.
*
* @return the position of the item on the board
*/
Vector3f getPos();
} }