mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 15:57:08 +02:00
dice button now works and update dice images accordingly
This commit is contained in:
@@ -25,6 +25,7 @@ import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
@@ -214,9 +215,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceResult msg) {
|
||||
|
||||
//Set the dice images
|
||||
playSound(Sound.DICE_ROLL);
|
||||
System.out.println("Message kam an");
|
||||
notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,7 +227,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(EventDrawCard msg) {
|
||||
|
||||
|
||||
// Kartenlogik
|
||||
playSound(Sound.EVENT_CARD);
|
||||
}
|
||||
|
@@ -395,6 +395,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
* @return the result of a dice roll (1 to 6)
|
||||
*/
|
||||
private static int rollDice() {
|
||||
System.out.println("Gewuerfelt");
|
||||
return random.nextInt(6) + 1;
|
||||
}
|
||||
}
|
||||
@@ -439,7 +440,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll);
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
@@ -491,7 +492,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll);
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
if (rollResult.isDoublets()) {
|
||||
state = new ActiveState();
|
||||
} else if (DoubletsCounter == 0) {
|
||||
|
@@ -166,7 +166,6 @@ public class PlayerHandler {
|
||||
* @return the player with the required id
|
||||
*/
|
||||
public Player getPlayerById(int id) {
|
||||
System.out.println("TEST");
|
||||
for (Player player : players) {
|
||||
if (player.getId() == id) return player;
|
||||
System.out.println(player.getId());
|
||||
|
@@ -220,7 +220,8 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(RollDice msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
if (player != null) {
|
||||
System.out.println("Ergebniss gesendet");
|
||||
send(player, player.rollDice());
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ public class RollDice extends ClientMessage{
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private RollDice() { /* empty */ }
|
||||
public RollDice() { /* empty */ }
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
|
@@ -7,19 +7,24 @@ import com.jme3.network.serializing.Serializable;
|
||||
@Serializable
|
||||
public class DiceResult extends ServerMessage{
|
||||
|
||||
private List<Integer> rollResult;
|
||||
private final int a;
|
||||
private final int b;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private DiceResult() { /* empty */ }
|
||||
private DiceResult() {
|
||||
a = 1;
|
||||
b = 1;
|
||||
}
|
||||
|
||||
public DiceResult(List<Integer> rollResult) {
|
||||
this.rollResult = rollResult;
|
||||
public DiceResult(int a, int b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public List<Integer> getRollResult() {
|
||||
return rollResult;
|
||||
return List.of(a,b);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,10 +39,10 @@ public class DiceResult extends ServerMessage{
|
||||
}
|
||||
|
||||
public boolean isDoublets() {
|
||||
return rollResult.get(0) == rollResult.get(1);
|
||||
return a == b;
|
||||
}
|
||||
|
||||
public int calcTotal() {
|
||||
return rollResult.get(0)+rollResult.get(1);
|
||||
return a+b;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record DiceRollEvent(int a, int b) implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
|
||||
}
|
@@ -45,4 +45,6 @@ public interface GameEventListener {
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
|
||||
|
||||
default void receivedEvent(DiceRollEvent event) { /*Do nothing */}
|
||||
}
|
||||
|
Reference in New Issue
Block a user