diff --git a/src/main/java/project/app/warzone/Commands/PlayerCommands.java b/src/main/java/project/app/warzone/Commands/PlayerCommands.java index f053252..a30f5dd 100644 --- a/src/main/java/project/app/warzone/Commands/PlayerCommands.java +++ b/src/main/java/project/app/warzone/Commands/PlayerCommands.java @@ -80,11 +80,13 @@ public void showMapStatus() { * @return returns status of deploying army */ @ShellMethod(key = "deploy", value = "This is used to deploy armies") - public String deployArmies(@ShellOption int p_countryID, @ShellOption int p_armies) { + public void deployArmies(@ShellOption int p_countryID, @ShellOption int p_armies) { if(d_gameEngine.prevUserCommand != Commands.ASSIGNCOUNTRIES){ - return "You cannot deploy armies at this stage. Please follow the sequence of commands in the game."; + System.out.println("You cannot deploy armies at this stage. Please follow the sequence of commands in the game."); } - return d_playerFeatures.deployArmies(d_gameEngine, p_countryID, p_armies); + + d_gameEngine.getGamePhase().reinforce(p_countryID, p_armies); + // return d_playerFeatures.deployArmies(d_gameEngine, p_countryID, p_armies); } @@ -95,11 +97,14 @@ public String deployArmies(@ShellOption int p_countryID, @ShellOption int p_armi * @return returns status of deploying army */ @ShellMethod(key = "advance", value = "This is used to deploy armies") - public String advancearmies(@ShellOption int p_countryfrom,@ShellOption int p_countryTo, @ShellOption int p_armies) { + public void advancearmies(@ShellOption int p_countryfrom,@ShellOption int p_countryTo, @ShellOption int p_armies) { if(d_gameEngine.prevUserCommand != Commands.ASSIGNCOUNTRIES){ - return "You cannot deploy armies at this stage. Please follow the sequence of commands in the game."; + System.out.println("You cannot deploy armies at this stage. Please follow the sequence of commands in the game."); + + } - return d_playerFeatures.advanceArmies(d_CurrentPlayerId,d_gameEngine, p_countryfrom,p_countryTo, p_armies); + d_gameEngine.getGamePhase().advance(d_CurrentPlayerId,p_countryfrom,p_countryTo, p_armies); + // return d_playerFeatures.advanceArmies(d_CurrentPlayerId,d_gameEngine, p_countryfrom,p_countryTo, p_armies); } /** @@ -118,7 +123,10 @@ public String bombCountry(@ShellOption int p_countryId) { for (Cards card : l_player.d_cardsInCollection) { if (card.getCardType().equalsIgnoreCase("bomb")){ - return d_playerFeatures.bombCountry(d_gameEngine,p_countryId); + + d_gameEngine.getGamePhase().bomb(p_countryId); + + // return d_playerFeatures.bombCountry(d_gameEngine,p_countryId); } else{ @@ -144,7 +152,9 @@ public String blockade(@ShellOption int p_countryId) { for (Cards card : l_player.d_cardsInCollection) { if (card.getCardType().equalsIgnoreCase("blockade")){ - return d_playerFeatures.blockadeCountry(d_gameEngine,p_countryId); + d_gameEngine.getGamePhase().blockade(p_countryId); + + // return d_playerFeatures.blockadeCountry(d_gameEngine,p_countryId); } else{ return "The Player does not have Blockade card"; @@ -168,7 +178,9 @@ public String airlift(@ShellOption int p_countryfrom,@ShellOption int p_countryT for (Cards card : l_player.d_cardsInCollection) { if (card.getCardType().equalsIgnoreCase("airlift")){ - return d_playerFeatures.airlift(d_gameEngine,p_countryfrom,p_countryTo, p_airliftArmies); + d_gameEngine.getGamePhase().airlift(p_countryfrom,p_countryTo, p_airliftArmies); + + // return d_playerFeatures.airlift(d_gameEngine,p_countryfrom,p_countryTo, p_airliftArmies); } else{ return "The Player does not have Airlift card"; @@ -189,7 +201,9 @@ public String negotiate(@ShellOption int p_targetPlayerId) { for (Cards card : l_player.d_cardsInCollection) { if (card.getCardType().equalsIgnoreCase("negotiate")){ - return d_playerFeatures.negotiate(d_gameEngine,p_targetPlayerId); + + d_gameEngine.getGamePhase().negotiate(p_targetPlayerId); + } else{ return "The Player does not have Negotiate card"; diff --git a/src/main/java/project/app/warzone/Features/PlayerFeatures.java b/src/main/java/project/app/warzone/Features/PlayerFeatures.java index c4dedd8..a330556 100644 --- a/src/main/java/project/app/warzone/Features/PlayerFeatures.java +++ b/src/main/java/project/app/warzone/Features/PlayerFeatures.java @@ -219,7 +219,7 @@ public void showMapStatus(GameEngine p_gameengine) { * @return A string containing status of the game. */ - public String advanceArmies(int currentPlayerId, GameEngine p_gameEngine, int p_countryIDFrom, int p_countryIDTo, + public String advanceArmies( GameEngine p_gameEngine, int currentPlayerId,int p_countryIDFrom, int p_countryIDTo, int p_armiesToAdv) { // List l_players = p_gameEngine.getPlayers(); @@ -502,33 +502,39 @@ public String negotiate(GameEngine p_gameEngine, int p_targetPlayerId) { Player l_player_1 = p_gameEngine.getPlayers().get(PlayerCommands.d_CurrentPlayerId); Player l_player_2 = p_gameEngine.getPlayers().get(p_targetPlayerId); - List l_friendlyAlliesfor_player_1 = null; - if(l_player_1 != l_player_2){ - for (Player player : l_player_1.getD_friendlyAlliesList()) { - l_friendlyAlliesfor_player_1.add(player); - } - l_friendlyAlliesfor_player_1.add(l_player_2); - l_player_1.setD_friendlyAlliesList(l_friendlyAlliesfor_player_1); + + + java.util.Map l_orderDetails = new HashMap(); + + l_orderDetails.put("PlayerToBlock", p_targetPlayerId); + + l_orderDetails.put("CurrentPlayer", PlayerCommands.d_CurrentPlayerId); + + + + // IssueOrder + l_player_1.issue_order(p_gameEngine, 5, l_orderDetails); - // setting frinds for player 2 + p_gameEngine.checkPlayersReinforcements(); + + return ""; - List l_friendlyAllies_for_player_2 = null; - for (Player player : l_player_2.getD_friendlyAlliesList()) { - l_friendlyAllies_for_player_2.add(player); } - l_friendlyAllies_for_player_2.add(l_player_1); - l_player_2.setD_friendlyAlliesList(l_friendlyAllies_for_player_2); + else{ - return "Negotiate executed successfully"; - } - return "Negotiate unsuccessful : both players cannot be the same"; -} - ///order details constructor + return "Negotiate unsuccessful : both players cannot be the same"; + + } + + + + + } } diff --git a/src/main/java/project/app/warzone/Model/Attack.java b/src/main/java/project/app/warzone/Model/Attack.java index 0aabf04..a3e396d 100644 --- a/src/main/java/project/app/warzone/Model/Attack.java +++ b/src/main/java/project/app/warzone/Model/Attack.java @@ -22,16 +22,24 @@ public void next() { } public void reinforce(int p_countryID, int p_armies) { - printInvalidCommandMessage(); + String l_reString = d_playerFeatures.deployArmies(ge, p_countryID, p_armies); + + System.out.println(l_reString); + } - + public void attack() { System.out.println("attack done"); ge.setPhase(new Fortify(ge)); } + public void advance(int p_CurrentPlayerId,int p_countryfrom,int p_countryTo, int p_armies) { + String l_reString = d_playerFeatures.advanceArmies(ge, p_CurrentPlayerId,p_countryfrom,p_countryTo, p_armies); + + } + public void fortify() { printInvalidCommandMessage(); } -} \ No newline at end of file +} diff --git a/src/main/java/project/app/warzone/Model/AttackOrder.java b/src/main/java/project/app/warzone/Model/AttackOrder.java index 4271c69..36eeb0c 100644 --- a/src/main/java/project/app/warzone/Model/AttackOrder.java +++ b/src/main/java/project/app/warzone/Model/AttackOrder.java @@ -34,93 +34,20 @@ public String Deploy(int p_armies, Country p_country) return "Deployed armies successfully"; } - // /** - // * This method is used to deploy armies on a country - // * @param p_gameEngine Instance of the game engine - // * @param p_countryID ID of the country to deploy armies on - // * @param p_armies Number of armies to deploy - // * @return A string containing status of the game. - // */ - - // public String Deploy(GameEngine p_gameEngine, int p_countryID, int p_armies) { - // List l_players = p_gameEngine.getPlayers(); - - // Player l_player = p_gameEngine.getPlayers().get(PlayerCommands.d_CurrentPlayerId); - // Country l_country = p_gameEngine.gameMap.getNodes().get(p_countryID-1).getData(); - - // /** - // * Check if the player has enough armies in the reinforcement pool to deploy - // */ - - // if (l_player.getReinforcementArmies() < p_armies) { - // return "Not enough armies to be deployed. Available armies: " + l_player.getReinforcementArmies(); - // } - - // /** - // * Check if the country is owned by the player - // */ - - // Optional l_territory = l_player.d_listOfCountriesOwned.stream() - // .filter(c -> c.getCountryName().equals(l_country.getCountryName())).findFirst(); - - - // if (!l_territory.isPresent()) { - // return "Country is not owned by the player"; - // } - - // // Order l_deployOrder = new OrderMethods(); - // // l_deployOrder.setL_numberOfArmies(p_armies); - // // l_deployOrder.setL_territory(l_country); - - // java.util.Map l_orderDetails = new HashMap(); - - // l_orderDetails.put("Armies", p_armies); - // l_orderDetails.put("CountryId", p_countryID); - - // //IssueOrder - // l_player.issue_order(0,l_orderDetails); - - // /** - // * Main Game loop in round robin fashion which checks the reinforcement pool of the player and if it is 0, then - // * ask the next player to deploy armies. If all players have deployed all their armies, then execute the orders - // */ - // p_gameEngine.execute_orders(); - - // Boolean l_flag = false; - // int l_i = PlayerCommands.d_CurrentPlayerId+1; - - // while (l_i != PlayerCommands.d_CurrentPlayerId) { - // if (l_i == l_players.size()) { - // l_i = 0; - // continue; - // } - - // if (l_players.get(l_i).getReinforcementArmies() > 0) { - // l_flag = true; - // break; - // } - // l_i++; - // } - - // if (l_flag) { - // PlayerCommands.d_CurrentPlayerId = l_i; - // return "Turn of " + l_players.get(l_i).getL_playername() + " to deploy army"; - // } else { - // p_gameEngine.execute_orders(); - // return "Orders successfully executed"; - // } - // } - //Advance public void Advance( Player player1 , Player player2, int p_armiesToAdv, Country source, Country target) { System.out.println("Inside Advance Method"); - long targetArmiesKilled = Math.round( target.getNumberOfArmies() * 0.7) ; + List getAllies = player1.getD_friendlyAlliesList(); + + if(!getAllies.contains(player2)){ - long sourceArmiesKilled = Math.round (source.getNumberOfArmies() * 0.6); + long targetArmiesKilled = Math.round( target.getNumberOfArmies() * 0.7) ; - if(( p_armiesToAdv - targetArmiesKilled ) > target.getNumberOfArmies() - sourceArmiesKilled){ + long sourceArmiesKilled = Math.round (source.getNumberOfArmies() * 0.6); + + if(( p_armiesToAdv - targetArmiesKilled ) > target.getNumberOfArmies() - sourceArmiesKilled){ //Set armies in target country @@ -187,7 +114,14 @@ public void Advance( Player player1 , Player player2, int p_armiesToAdv, Country { source.setNumberOfArmies(0); } -} + } + + } + else{ + System.out.println(" Attack stopped as"+player1.getL_playername()+"used negotiation card on"+player2.getL_playername()); + } + + } @@ -216,17 +150,19 @@ public void Blockade(Player player,Country target) //Bomb public void Bomb(Country target) { - System.out.println("Inside Bomb Method"); target.setNumberOfArmies(target.getNumberOfArmies()/2); } //Negotiate - public String Negotiate() + public void Negotiate(Player p_playerToNegotiate,Player currentPlayer) { - System.out.println("Inside Negotiate Method"); - return "--Inside Negotiate Method"; + p_playerToNegotiate.addriendlyAlly(p_playerToNegotiate); + + currentPlayer.addriendlyAlly(p_playerToNegotiate); + + } } diff --git a/src/main/java/project/app/warzone/Model/Cards.java b/src/main/java/project/app/warzone/Model/Cards.java index 640ce6b..1a01cfd 100644 --- a/src/main/java/project/app/warzone/Model/Cards.java +++ b/src/main/java/project/app/warzone/Model/Cards.java @@ -27,7 +27,7 @@ public void setCardType(String cardType) { if (cardType.equals("BOMB") || cardType.equals("REINFORCEMENT") || cardType.equals("BLOCKADE") || cardType.equals("AIRLIFT") || cardType.equals("NEGOTIATE")) { this.cardType = cardType; } else { - throw new IllegalArgumentException("Invalid card type"); + System.out.println("Invalid card type"); } } diff --git a/src/main/java/project/app/warzone/Model/ConcreteNegotiate.java b/src/main/java/project/app/warzone/Model/ConcreteNegotiate.java index 9afab35..528ee40 100644 --- a/src/main/java/project/app/warzone/Model/ConcreteNegotiate.java +++ b/src/main/java/project/app/warzone/Model/ConcreteNegotiate.java @@ -4,15 +4,22 @@ public class ConcreteNegotiate extends OrderMethods implements OrderInterface { private AttackOrder attackOrder; - public ConcreteNegotiate() + public Player d_playerToNegotiate; + + public Player d_currentPlayer; + + public ConcreteNegotiate(Player p_playerToNegotiate,Player p_currenPlayer) { + this.d_playerToNegotiate = p_playerToNegotiate; + + this.d_currentPlayer = p_currenPlayer; } @Override public void execute() { - attackOrder.Negotiate(); + attackOrder.Negotiate(d_playerToNegotiate,d_currentPlayer); } diff --git a/src/main/java/project/app/warzone/Model/Edit.java b/src/main/java/project/app/warzone/Model/Edit.java index 3bd80f3..103afce 100644 --- a/src/main/java/project/app/warzone/Model/Edit.java +++ b/src/main/java/project/app/warzone/Model/Edit.java @@ -35,4 +35,28 @@ public void endGame() { public void showMap() { printInvalidCommandMessage(); } + + + + public void advance(int p_CurrentPlayerId,int p_countryfrom,int p_countryTo, int p_armies) { + printInvalidCommandMessage(); + } + + public void bomb(int p_countryID) { + printInvalidCommandMessage(); + } + + public void blockade( int p_countryID) { + printInvalidCommandMessage(); + } + + public void airlift( int p_countryIDFrom, int p_countryIDTo, int p_armiesToAirlift) { + printInvalidCommandMessage(); + } + + public void negotiate(int p_targetPlayerId) { + printInvalidCommandMessage(); + } + + } diff --git a/src/main/java/project/app/warzone/Model/End.java b/src/main/java/project/app/warzone/Model/End.java index 20d413f..992cf8e 100644 --- a/src/main/java/project/app/warzone/Model/End.java +++ b/src/main/java/project/app/warzone/Model/End.java @@ -64,4 +64,24 @@ public void editContinent(String p_editcmd,String p_editremovecmd){ public void next() { printInvalidCommandMessage(); } + + public void advance(int p_CurrentPlayerId,int p_countryfrom,int p_countryTo, int p_armies) { + printInvalidCommandMessage(); + } + + public void bomb(int p_countryID) { + printInvalidCommandMessage(); + } + + public void blockade( int p_countryID) { + printInvalidCommandMessage(); + } + + public void airlift( int p_countryIDFrom, int p_countryIDTo, int p_armiesToAirlift) { + printInvalidCommandMessage(); + } + + public void negotiate(int p_targetPlayerId) { + printInvalidCommandMessage(); + } } diff --git a/src/main/java/project/app/warzone/Model/MainPlay.java b/src/main/java/project/app/warzone/Model/MainPlay.java index 86e8de5..7a0272b 100644 --- a/src/main/java/project/app/warzone/Model/MainPlay.java +++ b/src/main/java/project/app/warzone/Model/MainPlay.java @@ -27,4 +27,25 @@ public void setPlayers(String p_attribute, String p_playerName) { public void assignCountries() { this.printInvalidCommandMessage(); } + + + public void advance(int p_CurrentPlayerId,int p_countryfrom,int p_countryTo, int p_armies) { + printInvalidCommandMessage(); + } + + public void bomb(int p_countryID) { + printInvalidCommandMessage(); + } + + public void blockade( int p_countryID) { + printInvalidCommandMessage(); + } + + public void airlift( int p_countryIDFrom, int p_countryIDTo, int p_armiesToAirlift) { + printInvalidCommandMessage(); + } + + public void negotiate(int p_targetPlayerId) { + printInvalidCommandMessage(); + } } diff --git a/src/main/java/project/app/warzone/Model/Phase.java b/src/main/java/project/app/warzone/Model/Phase.java index 375240f..b6b8ce7 100644 --- a/src/main/java/project/app/warzone/Model/Phase.java +++ b/src/main/java/project/app/warzone/Model/Phase.java @@ -44,6 +44,17 @@ public abstract class Phase { // attack commands abstract public void attack(); + abstract public void advance(int p_CurrentPlayerId,int p_countryfrom,int p_countryTo, int p_armies); + + abstract public void bomb(int p_countryID); + + abstract public void blockade( int p_countryID); + + abstract public void airlift( int p_countryIDFrom, int p_countryIDTo, int p_armiesToAirlift); + + abstract public void negotiate(int p_targetPlayerId); + + // fortify commands abstract public void fortify(); diff --git a/src/main/java/project/app/warzone/Model/Play.java b/src/main/java/project/app/warzone/Model/Play.java index 17b34ca..532f95b 100644 --- a/src/main/java/project/app/warzone/Model/Play.java +++ b/src/main/java/project/app/warzone/Model/Play.java @@ -75,4 +75,6 @@ public void editNeighbor(String p_editcmd,String p_editremovecmd) { public void endGame() { ge.setPhase(new End(ge)); } + + } diff --git a/src/main/java/project/app/warzone/Model/PlaySetup.java b/src/main/java/project/app/warzone/Model/PlaySetup.java index 7e07db1..d3e7421 100644 --- a/src/main/java/project/app/warzone/Model/PlaySetup.java +++ b/src/main/java/project/app/warzone/Model/PlaySetup.java @@ -86,4 +86,24 @@ public void endGame() { public void next() { ge.setPhase(new Reinforcement(ge)); } + + public void advance(int p_CurrentPlayerId,int p_countryfrom,int p_countryTo, int p_armies) { + printInvalidCommandMessage(); + } + + public void bomb(int p_countryID) { + printInvalidCommandMessage(); + } + + public void blockade( int p_countryID) { + printInvalidCommandMessage(); + } + + public void airlift(int p_countryIDFrom, int p_countryIDTo, int p_armiesToAirlift) { + printInvalidCommandMessage(); + } + + public void negotiate(int p_targetPlayerId) { + printInvalidCommandMessage(); + } } diff --git a/src/main/java/project/app/warzone/Model/Player.java b/src/main/java/project/app/warzone/Model/Player.java index 8bc7b3b..9cf988f 100644 --- a/src/main/java/project/app/warzone/Model/Player.java +++ b/src/main/java/project/app/warzone/Model/Player.java @@ -138,6 +138,10 @@ public List getD_friendlyAlliesList() { return d_friendlyAlliesList; } + public void addriendlyAlly(Player player) { + d_friendlyAlliesList.add(player); + } + public void setD_friendlyAlliesList(List d_friendlyAlliesList) { this.d_friendlyAlliesList = d_friendlyAlliesList; } @@ -216,9 +220,11 @@ public void issue_order(GameEngine p_gameEngine,int orderType,java.util.Map