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

@@ -59,7 +59,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
private final List<GameEventListener> listeners = new ArrayList<>();
/** 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. */
private ClientState state = new LobbyState(this);
@@ -310,6 +310,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
@Override
public void received(BuildInfo msg) {
System.out.println("TRIGGER BUILD INFO");
if (msg.isAdded()) {
BuildingProperty property = ((BuildingProperty)boardManager.getFieldAtIndex(msg.getId()));
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
* 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())) {
if (boardManager.canBuild(field) && sender.getAccountBalance() >= field.getHousePrice()) {
field.build();
send(playerHandler.getPlayerById(from), new BuildInfo(field.getId(), true));
updateAllPlayers();
sendAll( new BuildInfo(field.getId(), true));
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())) {
if (boardManager.canSell(field)) {
field.sell();
updateAllPlayers();
sendAll( new BuildInfo(field.getId(), false));
sender.earnMoney(field.getHousePrice() / 2);
}
}
@@ -434,9 +448,9 @@ public class ServerGameLogic implements ClientInterpreter {
} else if (msg.getKeyword().equals("PayJail")) {
playerHandler.getPlayerById(from).payBail();
} 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())) {
bp.build();
}
// for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) {
// bp.build();
// }
for(PropertyField field : boardManager.getBoard().stream().filter(p -> p instanceof PropertyField).map(p -> (PropertyField) p).collect(Collectors.toList())) {
field.setOwner(playerHandler.getPlayerById(0));
playerHandler.getPlayerById(0).addProperty(field.getId());

View File

@@ -59,7 +59,7 @@ public class Board {
*/
private void addItem(Item 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
*/
public Vector3f getPosition() {
public Vector3f getPos() {
return position;
}

View File

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

View File

@@ -1,5 +1,7 @@
package pp.monopoly.model;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.network.serializing.Serializable;
@@ -56,7 +58,7 @@ public class House implements Item{
*
* @return the position of the building on the field
*/
public Vector3f getBuildingPosition() {
public Vector3f getPos() {
float baseX = 0.0f;
float baseZ = 0.0f;
@@ -107,4 +109,22 @@ public class House implements Item{
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;
import com.jme3.math.Vector3f;
/**
* An interface representing any item on a board
* 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
*/
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();
}