mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 18:04:18 +02:00
rudimentary function for trade
This commit is contained in:
@@ -61,6 +61,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
|
||||
private BoardManager boardManager = new BoardManager();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a ClientGameLogic with the specified sender object.
|
||||
*
|
||||
@@ -290,7 +291,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(ViewAssetsResponse msg) {
|
||||
|
||||
boardManager = msg.getboard();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,9 +317,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(TradeRequest msg) {
|
||||
|
||||
// playSound(Sound.TRADE_REQUEST); no sound effect
|
||||
// notifyListeners();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -41,7 +41,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
private String name;
|
||||
private int accountBalance = 15000;
|
||||
private Figure figure;
|
||||
private transient List<PropertyField> properties = new ArrayList<>();
|
||||
private List<Integer> properties = new ArrayList<>();
|
||||
private int getOutOfJailCard;
|
||||
private int fieldID;
|
||||
private DiceResult rollResult;
|
||||
@@ -193,7 +193,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
* Gets all the properties owned by this player
|
||||
* @return List of all properties owned by this player
|
||||
*/
|
||||
public List<PropertyField> getProperties() {
|
||||
public List<Integer> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
public void buyProperty(PropertyField property) {
|
||||
if (property.getOwner() == null && accountBalance >= property.getPrice()) {
|
||||
properties.add(property);
|
||||
properties.add(property.getId());
|
||||
property.setOwner(this);
|
||||
pay(property.getPrice());
|
||||
}
|
||||
@@ -383,6 +383,16 @@ public class Player implements FieldVisitor<Void>{
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<PropertyField> getPropertyFields() {
|
||||
List<PropertyField> properties = new ArrayList<>();
|
||||
|
||||
for (Integer i : this.properties) {
|
||||
properties.add((PropertyField)getHandler().getLogic().getBoardManager().getFieldAtIndex(i));
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of Properties of the speciefied fild type
|
||||
* @param field the type of field to search for
|
||||
@@ -391,7 +401,8 @@ public class Player implements FieldVisitor<Void>{
|
||||
public int getNumProp(PropertyField field) {
|
||||
int count = 0;
|
||||
if (properties.isEmpty()) return 0;
|
||||
for (PropertyField propertyField : properties) {
|
||||
|
||||
for (PropertyField propertyField : getPropertyFields()) {
|
||||
if (propertyField.getClass() == field.getClass()) {
|
||||
count++;
|
||||
}
|
||||
@@ -402,7 +413,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
public int getNumHouses() {
|
||||
int total = 0;
|
||||
for (PropertyField field : properties) {
|
||||
for (PropertyField field : getPropertyFields()) {
|
||||
if (field.getClass() == BuildingProperty.class) {
|
||||
total += ((BuildingProperty) field).getHouses();
|
||||
}
|
||||
@@ -412,7 +423,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
public int getNumHotels() {
|
||||
int total = 0;
|
||||
for (PropertyField field : properties) {
|
||||
for (PropertyField field : getPropertyFields()) {
|
||||
if (field.getClass() == BuildingProperty.class) {
|
||||
total += ((BuildingProperty) field).getHotel();
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ import pp.monopoly.message.server.ServerMessage;
|
||||
import pp.monopoly.message.server.TradeReply;
|
||||
import pp.monopoly.message.server.TradeRequest;
|
||||
import pp.monopoly.message.server.ViewAssetsResponse;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.Rotation;
|
||||
import pp.monopoly.model.card.DeckHelper;
|
||||
@@ -264,11 +263,12 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(ViewAssetsRequest msg, int from) {
|
||||
Player sender = playerHandler.getPlayerById(from);
|
||||
Player player = msg.getPlayer();
|
||||
if (sender != null && player != null) {
|
||||
LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName());
|
||||
|
||||
send(sender, new ViewAssetsResponse(boardManager, player.getProperties(), player.getAccountBalance(), player.getNumJailCard()));
|
||||
if (sender != null) {
|
||||
LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName());
|
||||
send(sender, new ViewAssetsResponse(boardManager));
|
||||
for (Player player : playerHandler.getPlayers()) {
|
||||
send(player, new PlayerStatusUpdate(playerHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,23 +2,13 @@ package pp.monopoly.message.client;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
/**
|
||||
* Represents a request from a player to view their assets.
|
||||
*/
|
||||
@Serializable
|
||||
public class ViewAssetsRequest extends ClientMessage{
|
||||
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private ViewAssetsRequest() { /* empty */ }
|
||||
|
||||
public ViewAssetsRequest(Player player) {
|
||||
this.player = player;
|
||||
public ViewAssetsRequest() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,8 +16,4 @@ public class ViewAssetsRequest extends ClientMessage{
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +1,9 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
|
||||
/**
|
||||
* Represents a response containing the player's assets.
|
||||
@@ -13,10 +11,7 @@ import pp.monopoly.model.fields.PropertyField;
|
||||
@Serializable
|
||||
public class ViewAssetsResponse extends ServerMessage{
|
||||
|
||||
private List<PropertyField> properties;
|
||||
private BoardManager board;
|
||||
private int accountBalance;
|
||||
private int jailCards;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
@@ -29,11 +24,8 @@ public class ViewAssetsResponse extends ServerMessage{
|
||||
* @param properties a List of PropertyField objects representing the player's properties
|
||||
* @param accountBalance the player's current account balance
|
||||
*/
|
||||
public ViewAssetsResponse(BoardManager board, List<PropertyField> properties, int accountBalance, int jailCards) {
|
||||
public ViewAssetsResponse(BoardManager board) {
|
||||
this.board = board;
|
||||
this.properties = properties;
|
||||
this.accountBalance = accountBalance;
|
||||
this.jailCards = jailCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,18 +39,6 @@ public class ViewAssetsResponse extends ServerMessage{
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
public List<PropertyField> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public int getAccountBalance() {
|
||||
return accountBalance;
|
||||
}
|
||||
|
||||
public int getJailCards() {
|
||||
return jailCards;
|
||||
}
|
||||
|
||||
public BoardManager getboard() {
|
||||
return board;
|
||||
}
|
||||
|
@@ -4,9 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Simple Manager class responsible for managing the GameBoard of Monopoly
|
||||
*/
|
||||
@Serializable
|
||||
public class BoardManager {
|
||||
|
||||
private List<Field> board;
|
||||
@@ -92,4 +95,12 @@ public class BoardManager {
|
||||
public List<Field> getBoard() {
|
||||
return board;
|
||||
}
|
||||
|
||||
public List<PropertyField> getPropertyFields(List<Integer> source) {
|
||||
List<PropertyField> properties = new ArrayList<>();
|
||||
for (Integer i : source) {
|
||||
properties.add((PropertyField)getFieldAtIndex(i));
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user