From 7e8421387d033a6022387d99528c217fc9399ef2 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Sun, 3 May 2026 17:43:52 +0200 Subject: [PATCH] Fix: Game Init --- .../java/it/polimi/ingsw/gc14/Model/Game.java | 46 ++++++++++++------- .../gc14/Model/GamePackage/GameStages.java | 2 +- .../gc14/Controller/GameControllerTest.java | 14 +++--- .../Model/GamePackage/CurrentStateTest.java | 6 +-- .../it/polimi/ingsw/gc14/Model/GameTest.java | 34 +++++++------- 5 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java index bc777d2..01b43b2 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -232,6 +232,16 @@ public class Game implements Serializable { orderLogicCard=new Order5(playersList); break; } + for(Player player : playersList) + { + switch(orderLogicCard.getPosition(player.getUserName())) + { + case 0: player.addFood(2); break; + case 1,2: player.addFood(3); break; + case 3,4: player.addFood(4); break; + } + + } currentState.PlayerUpdate(orderLogicCard.pull(),null); currentState.GameStageUpdate(GameStages.SLOT_CHOICE); } @@ -264,6 +274,10 @@ public class Game implements Serializable { { return false; } + if(slotPlayerEntry.getKey().getSlotId()=='A') + { + player.addFood(3); + } slotMap.put(slotPlayerEntry.getKey(),player); nextPlayerSetup(); return true; @@ -288,7 +302,7 @@ public class Game implements Serializable { public boolean DrawUpperTribeCardByIndex(Player player,int cardIndex) { if( cardIndex<0 || cardIndex >=board.upperListTribe.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -324,7 +338,7 @@ public class Game implements Serializable { * @return {@code true} if the skip succeeds, {@code false} otherwise. */ public boolean SkipUpperDrawing(Player player) { - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -355,7 +369,7 @@ public class Game implements Serializable { * @return {@code true} if the skip succeeds, {@code false} otherwise. */ public boolean SkipLowerDrawing(Player player) { - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -389,7 +403,7 @@ public class Game implements Serializable { public boolean DrawLowerTribeCardByIndex(Player player, int cardIndex) { if( cardIndex<0 || cardIndex >=board.lowerListTribe.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -430,7 +444,7 @@ public class Game implements Serializable { public boolean DrawUpperBuildingCardByIndex(Player player,int cardIndex) { if( cardIndex<0 || cardIndex >=board.upperListBuilding.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -469,7 +483,7 @@ public class Game implements Serializable { public boolean DrawLowerBuildingCardByIndex(Player player,int cardIndex) { if( cardIndex<0 || cardIndex >=board.lowerListBuilding.size()) return false; - if(currentState.getGameStage()!= GameStages.RESOLVING_ACTIONS) + if(currentState.getGameStage()!= GameStages.RES_ACTIONS) { return false; } @@ -514,7 +528,7 @@ public class Game implements Serializable { * @return {@code true} if the operation succeeds, {@code false} otherwise. */ public boolean PickOptionalTribeCardByIndex(Player player,int cardIndex) { - if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){ + if(currentState.getGameStage() != GameStages.OPT_CARD_E){ return false; } if(!player.equals(currentState.getCurrentPlayer())){ @@ -549,7 +563,7 @@ public class Game implements Serializable { * @return {@code true} if the operation succeeds, {@code false} otherwise. */ public boolean PickOptionalBuildingCard(Player player, int cardIndex) { - if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){ + if(currentState.getGameStage() != GameStages.OPT_CARD_E){ return false; } if(!player.equals(currentState.getCurrentPlayer())){ @@ -581,7 +595,7 @@ public class Game implements Serializable { * @return {@code true} if the operation succeeds, {@code false} otherwise. */ public boolean NoOptionalCard(Player player) { - if(currentState.getGameStage() != GameStages.OPTIONAL_CARD_EFFECT){ + if(currentState.getGameStage() != GameStages.OPT_CARD_E){ return false; } if(!player.equals(currentState.getCurrentPlayer())){ @@ -620,7 +634,7 @@ public class Game implements Serializable { currentState.PlayerUpdate(tempPlayer, null); return; } - currentState.GameStageUpdate(GameStages.RESOLVING_ACTIONS); + currentState.GameStageUpdate(GameStages.RES_ACTIONS); for (Slot s : slotMap.keySet()) { if (slotMap.get(s) != null) { currentState.PlayerUpdate(slotMap.get(s), s); @@ -636,7 +650,7 @@ public class Game implements Serializable { return; } - if(GameStages.RESOLVING_ACTIONS==currentState.getGameStage()) { + if(GameStages.RES_ACTIONS ==currentState.getGameStage()) { orderLogicCard.push(currentState.getCurrentPlayer()); slotMap.put(currentState.getSlot(), null); for (Slot s : slotMap.keySet()) { @@ -655,7 +669,7 @@ public class Game implements Serializable { } if(slotMap.values().stream().allMatch(v -> v == null)) { - currentState.GameStageUpdate(GameStages.OPTIONAL_CARD_EFFECT); + currentState.GameStageUpdate(GameStages.OPT_CARD_E); HashMap optional=new LinkedHashMap<>(); for (Player p : orderLogicCard.players) { int tempCount=(int)p.buildingCards.stream().filter(x->x.getEffectId()==12).count(); @@ -676,7 +690,7 @@ public class Game implements Serializable { return; } - currentState.GameStageUpdate(GameStages.RESOLVING_EVENT); + currentState.GameStageUpdate(GameStages.RES_EVENT); if (currentState.getRound() < 10) { nextRound(); @@ -691,7 +705,7 @@ public class Game implements Serializable { } } - if (GameStages.OPTIONAL_CARD_EFFECT == currentState.getGameStage()) { + if (GameStages.OPT_CARD_E == currentState.getGameStage()) { Player optionalPlayer = OptionalCardQueue.poll(); if (optionalPlayer != null) { @@ -699,7 +713,7 @@ public class Game implements Serializable { return; } - currentState.GameStageUpdate(GameStages.RESOLVING_EVENT); + currentState.GameStageUpdate(GameStages.RES_EVENT); if (currentState.getRound() < 10) { nextRound(); @@ -748,7 +762,7 @@ public class Game implements Serializable { */ private void EventResolution() { - if(currentState.getGameStage()!= GameStages.RESOLVING_EVENT) + if(currentState.getGameStage()!= GameStages.RES_EVENT) { return; } diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java index 97e8fa3..61c8a74 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/GamePackage/GameStages.java @@ -1,5 +1,5 @@ package it.polimi.ingsw.gc14.Model.GamePackage; public enum GameStages { - WAITING, SLOT_CHOICE, RESOLVING_ACTIONS, OPTIONAL_CARD_EFFECT, RESOLVING_EVENT, ENDING, ENDED + WAITING, SLOT_CHOICE, RES_ACTIONS, OPT_CARD_E, RES_EVENT, ENDING, ENDED } diff --git a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java index ec4ddc8..3e95055 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Controller/GameControllerTest.java @@ -36,7 +36,7 @@ class GameControllerTest { assertTrue(controller.slotChoice(current.getUserName(), i)); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); return order; } @@ -89,12 +89,12 @@ class GameControllerTest { private void resolveActionsUntilOptionalCardEffect(Game game, GameController controller) { int guard = 0; - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS && guard < 100) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS && guard < 100) { guard++; resolveOneMandatoryAction(game, controller); } - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); } private void resolveOneMandatoryAction(Game game, GameController controller) { @@ -154,7 +154,7 @@ class GameControllerTest { assertTrue(controller.slotChoice(current.getUserName(), slotIndexes[i])); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); return order; } @@ -206,7 +206,7 @@ class GameControllerTest { Queue order = completeSlotChoice(game, controller); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); assertEquals(order.poll(), game.getCurrentState().getCurrentPlayer()); } @@ -320,7 +320,7 @@ class GameControllerTest { assertTrue(controller.slotChoice(current.getUserName(), i)); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); Player tempPlayer = players.poll(); assertNotNull(tempPlayer); @@ -395,7 +395,7 @@ class GameControllerTest { completeSlotChoice(game, controller); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); String cur = game.getCurrentState().getCurrentPlayer().getUserName(); diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java index b07549a..6fe34e9 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GamePackage/CurrentStateTest.java @@ -70,7 +70,7 @@ class CurrentStateTest { void getGameStage() { Player p = new Player("test"); Slot s = new Slot('A'); - GameStages g = GameStages.RESOLVING_ACTIONS; + GameStages g = GameStages.RES_ACTIONS; CurrentState curr = new CurrentState(); curr.PlayerUpdate(p, s); curr.GameStageUpdate(g); @@ -122,12 +122,12 @@ class CurrentStateTest { void gameStageUpdate() { Player p = new Player("test"); Slot s = new Slot('A'); - GameStages g = GameStages.RESOLVING_ACTIONS; + GameStages g = GameStages.RES_ACTIONS; CurrentState curr = new CurrentState(); assertEquals(GameStages.WAITING, curr.getGameStage()); curr.PlayerUpdate(p, s); curr.GameStageUpdate(g); - assertEquals(GameStages.RESOLVING_ACTIONS, curr.getGameStage()); + assertEquals(GameStages.RES_ACTIONS, curr.getGameStage()); } @Test diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java index 0e4f2a7..dd11d00 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/GameTest.java @@ -30,7 +30,7 @@ class GameTest { assertTrue(game.SlotChoiceByIndex(current, i)); } - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); return order; } @@ -63,7 +63,7 @@ class GameTest { } private void resolveAllMandatoryActions(Game game) { - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { resolveOneMandatoryAction(game); } } @@ -126,15 +126,15 @@ class GameTest { } private void resolveActionsUntilOptionalCardEffect(Game game) { - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { resolveOneMandatoryAction(game); } - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); } private void resolveOptionalPhaseIfPresent(Game game) { - while (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) { + while (game.getCurrentState().getGameStage() == GameStages.OPT_CARD_E) { Player current = game.getCurrentState().getCurrentPlayer(); assertNotNull(current); @@ -147,7 +147,7 @@ class GameTest { completeSlotChoice(game); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); resolveAllMandatoryActions(game); @@ -157,7 +157,7 @@ class GameTest { private void resolveCurrentPlayerCompletely(Game game, Player expectedPlayer) { assertEquals(expectedPlayer, game.getCurrentState().getCurrentPlayer()); - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS && expectedPlayer.equals(game.getCurrentState().getCurrentPlayer())) { resolveOneMandatoryAction(game); } @@ -357,7 +357,7 @@ class GameTest { assertNotNull(thirdPlayer); assertEquals(thirdPlayer, game.getCurrentState().getCurrentPlayer()); - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS && thirdPlayer.equals(game.getCurrentState().getCurrentPlayer())) { resolveOneMandatoryAction(game); } @@ -497,7 +497,7 @@ class GameTest { assertTrue(game.NoOptionalCard(current)); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); assertNotEquals(current, game.getCurrentState().getCurrentPlayer()); } @@ -662,7 +662,7 @@ class GameTest { assertDoesNotThrow(() -> resolveAllMandatoryActions(game)); - assertNotEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertNotEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); } @@ -879,7 +879,7 @@ class GameTest { completeSlotChoice(game); } - if (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + if (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { Player current = game.getCurrentState().getCurrentPlayer(); assertNotNull(current); @@ -920,7 +920,7 @@ class GameTest { resolveOneMandatoryAction(game); } - if (game.getCurrentState().getGameStage() == GameStages.OPTIONAL_CARD_EFFECT) { + if (game.getCurrentState().getGameStage() == GameStages.OPT_CARD_E) { resolveOptionalPhaseIfPresent(game); } @@ -939,7 +939,7 @@ class GameTest { completeSlotChoice(game); - while (game.getCurrentState().getGameStage() == GameStages.RESOLVING_ACTIONS) { + while (game.getCurrentState().getGameStage() == GameStages.RES_ACTIONS) { Player current = game.getCurrentState().getCurrentPlayer(); if (game.getCurrentState().getNUpper() > 0 @@ -977,7 +977,7 @@ class GameTest { Player thirdChooser = game.getCurrentState().getCurrentPlayer(); assertTrue(game.SlotChoiceByIndex(thirdChooser, 1)); - assertEquals(GameStages.RESOLVING_ACTIONS, game.getCurrentState().getGameStage()); + assertEquals(GameStages.RES_ACTIONS, game.getCurrentState().getGameStage()); assertEquals(secondChooser, game.getCurrentState().getCurrentPlayer()); @@ -1009,7 +1009,7 @@ class GameTest { completeSlotChoice(game); resolveAllMandatoryActions(game); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); assertDoesNotThrow(() -> resolveOptionalPhaseIfPresent(game)); @@ -1032,7 +1032,7 @@ class GameTest { completeSlotChoice(game); resolveAllMandatoryActions(game); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); Player player = players.get(0); @@ -1068,7 +1068,7 @@ class GameTest { completeSlotChoice(game); resolveAllMandatoryActions(game); - assertEquals(GameStages.OPTIONAL_CARD_EFFECT, game.getCurrentState().getGameStage()); + assertEquals(GameStages.OPT_CARD_E, game.getCurrentState().getGameStage()); Player player = players.get(0); assertNotNull(player);