Skip to content

Commit

Permalink
Merge pull request #27 from ro18/rochelle_changes
Browse files Browse the repository at this point in the history
Rochelle changes
  • Loading branch information
ro18 authored Nov 9, 2023
2 parents 7a905ec + cf11937 commit 0922f07
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 123 deletions.
34 changes: 24 additions & 10 deletions src/main/java/project/app/warzone/Commands/PlayerCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand All @@ -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);
}

/**
Expand All @@ -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{
Expand All @@ -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";
Expand All @@ -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";
Expand All @@ -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";
Expand Down
44 changes: 25 additions & 19 deletions src/main/java/project/app/warzone/Features/PlayerFeatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> l_players = p_gameEngine.getPlayers();

Expand Down Expand Up @@ -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<Player> 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<String, Integer> l_orderDetails = new HashMap<String, Integer>();

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<Player> 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";

}







}
}
14 changes: 11 additions & 3 deletions src/main/java/project/app/warzone/Model/Attack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
}
106 changes: 21 additions & 85 deletions src/main/java/project/app/warzone/Model/AttackOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Player> 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<Country> 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<String, Integer> l_orderDetails = new HashMap<String, Integer>();

// 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<Player> 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
Expand Down Expand Up @@ -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());
}



}

Expand Down Expand Up @@ -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);


}

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/project/app/warzone/Model/Cards.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/project/app/warzone/Model/ConcreteNegotiate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
24 changes: 24 additions & 0 deletions src/main/java/project/app/warzone/Model/Edit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


}
Loading

0 comments on commit 0922f07

Please sign in to comment.