mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-18 22:56:15 +01:00
fixed move logic
This commit is contained in:
parent
6cdad71693
commit
86ece3b70d
@ -152,29 +152,18 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves by the specified amount of steps
|
||||
* @param steps the number of steps to move
|
||||
* Moves the player by a given number of steps, handling board wrapping.
|
||||
*
|
||||
* @param steps number of steps to move
|
||||
* @return the new position
|
||||
*/
|
||||
public int move(int steps){
|
||||
return movePos(fieldID+steps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the player to the specified Position on the board
|
||||
* @param position the position to move to
|
||||
* @return the new position
|
||||
*/
|
||||
public int movePos(int position){
|
||||
fieldID = fieldID+position;
|
||||
System.out.println("Aktuelle Position" +fieldID);
|
||||
System.err.println("Würfelergebniss"+ rollResult.calcTotal());
|
||||
if(fieldID >= 40) {
|
||||
fieldID = fieldID%40;
|
||||
earnMoney(2000);
|
||||
public int move(int steps) {
|
||||
fieldID = (fieldID + steps) % 40;
|
||||
if (fieldID + steps >= 40) {
|
||||
earnMoney(2000); // Passing GO gives money
|
||||
}
|
||||
figure.moveTo(fieldID);
|
||||
getHandler().getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
handler.getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
|
||||
return fieldID;
|
||||
}
|
||||
@ -452,29 +441,37 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rolls two dice and returns a list with the results.
|
||||
*
|
||||
* @return a List of two integers representing the dice roll results
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
if (mayRollDice) {
|
||||
state.rollDice();
|
||||
}
|
||||
if (rollResult.isDoublets()) {
|
||||
doubletscounter++;
|
||||
mayRollDice = true;
|
||||
getHandler().getLogic().send(this, new NextPlayerTurn());
|
||||
setName(name);
|
||||
if (doubletscounter >= 3) {
|
||||
setPosition(10);
|
||||
}
|
||||
} else {
|
||||
mayRollDice = false;
|
||||
}
|
||||
return rollResult;
|
||||
/**
|
||||
* Rolls two dice, handles movement logic, and checks for doublets.
|
||||
*
|
||||
* @return the DiceResult of the roll
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
if (!mayRollDice) {
|
||||
throw new IllegalStateException("Player is not allowed to roll dice at this moment.");
|
||||
}
|
||||
|
||||
rollResult = state.rollDice();
|
||||
mayRollDice = false;
|
||||
|
||||
if (rollResult.isDoublets()) {
|
||||
doubletscounter++;
|
||||
mayRollDice = true; // Allow another roll for doublets
|
||||
|
||||
if (doubletscounter >= 3) {
|
||||
setPosition(10); // Send to jail on third doublet
|
||||
doubletscounter = 0; // Reset doublets counter
|
||||
} else {
|
||||
getHandler().getLogic().send(this, new NextPlayerTurn());
|
||||
}
|
||||
} else {
|
||||
doubletscounter = 0; // Reset counter if no doublets
|
||||
}
|
||||
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A interface representing the PlayerStates
|
||||
*/
|
||||
|
@ -189,7 +189,7 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void spoparty(Player player) {
|
||||
player.movePos(14);
|
||||
player.setPosition(14);
|
||||
}
|
||||
|
||||
private void gulakFrei(Player player) {
|
||||
@ -197,11 +197,11 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void dienstfuehrerschein(Player player) {
|
||||
player.movePos(20);
|
||||
player.setPosition(20);
|
||||
}
|
||||
|
||||
private void pubquiz(Player player) {
|
||||
player.movePos(39);
|
||||
player.setPosition(39);
|
||||
}
|
||||
|
||||
private void namensschildTruppenkueche(Player player) {
|
||||
@ -216,11 +216,11 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void pruefungsphaseKrank(Player player) {
|
||||
player.movePos(player.getFieldID() - 3);
|
||||
player.setPosition(player.getFieldID() - 3);
|
||||
}
|
||||
|
||||
private void naechstesMonatsgehalt(Player player) {
|
||||
player.movePos(0);
|
||||
player.setPosition(0);
|
||||
}
|
||||
|
||||
private void antretenVerschlafen(Player player) {
|
||||
@ -237,20 +237,20 @@ public class DeckHelper{
|
||||
|
||||
private void dienstsportGym(Player player) {
|
||||
for (Player p : player.getHandler().getPlayers()) {
|
||||
p.movePos(1);
|
||||
p.setPosition(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void schimmelGulak(Player player) {
|
||||
player.movePos(10);
|
||||
player.setPosition(10);
|
||||
}
|
||||
|
||||
private void partynachtGulak(Player player) {
|
||||
player.movePos(10);
|
||||
player.setPosition(10);
|
||||
}
|
||||
|
||||
private void jahresabschlussantreten(Player player) {
|
||||
player.movePos(17);
|
||||
player.setPosition(17);
|
||||
}
|
||||
|
||||
private void verkaufenVersicherungen(Player player) {
|
||||
@ -263,7 +263,7 @@ public class DeckHelper{
|
||||
|
||||
private void hausfeierSturz(Player player) {
|
||||
player.pay(800);
|
||||
player.movePos(32);
|
||||
player.setPosition(32);
|
||||
}
|
||||
|
||||
private void befoerderung(Player player) {
|
||||
@ -292,7 +292,7 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void kranzExmatrikulation(Player player) {
|
||||
player.movePos(5);
|
||||
player.setPosition(5);
|
||||
}
|
||||
|
||||
private void partyEskaliert(Player player) {
|
||||
|
Loading…
Reference in New Issue
Block a user