diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index b9003d9..4bedf7b 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -33,6 +33,7 @@
+
diff --git a/log.txt b/log.txt
index 7691d47..e69de29 100644
--- a/log.txt
+++ b/log.txt
@@ -1,6 +0,0 @@
-
-In PreLoad Phase:
-loadmap Command is being executed
-Command given by user:loadmap new.map
-new.map Map is valid. Add players ->
-In StartUp Phase:
\ No newline at end of file
diff --git a/src/main/java/Controller/GameEngine.java b/src/main/java/Controller/GameEngine.java
index 11624fa..4916400 100644
--- a/src/main/java/Controller/GameEngine.java
+++ b/src/main/java/Controller/GameEngine.java
@@ -26,7 +26,6 @@ public class GameEngine {
public Phase d_Phase;
-
public void setD_GamePhase(GamePhase d_GamePhase) {
this.d_GamePhase = d_GamePhase;
}
@@ -60,7 +59,7 @@ public boolean isValidMapName(String p_mapName) {
}
/**
- * Checks if passed string just has alphbets
+ * Checks if passed string just has alphabets
*
* @param p_string
* @return true if string has all alphabets or false
@@ -549,6 +548,115 @@ public GamePhase parseCommand(Player p_player, String p_givenCommand) {
exit(0);
}
+ case "bomb":
+ System.out.println(l_commandName + " command entered");
+ try {
+ if (l_param.length == 2 && this.isAlphabetic(l_param[1])) {
+ setPhase(new IssueOrderPhase(this));
+ String countryId = l_param[1];
+
+ // Get the target player from your game logic; replace "fetchTargetPlayer" with the appropriate method
+ Player targetPlayer = fetchTargetPlayer(p_player);
+
+ boolean sourceCountryOwned = p_player.getOwnedCountries().containsKey(countryId.toLowerCase());
+ boolean checkCard = p_player.checkCardExists("Bomb");
+
+ if (sourceCountryOwned && checkCard) {
+ // Create a Bomb order
+ Bomb bombOrder = new Bomb(p_player, targetPlayer, countryId);
+
+ // Add the Bomb order to the current player's order list
+ p_player.addOrder(bombOrder);
+
+ // Issue the order (p_player.issue_order() or d_Phase.issue_order(p_player))
+ // ...
+
+ System.out.println("For player " + p_player.getPlayerName()
+ + " Bomb order added to Players OrdersList: " + l_param[0] + " "
+ + l_param[1]);
+ d_LogEntry.setMessage("For player " + p_player.getPlayerName()
+ + " Bomb order added to Players OrdersList: " + l_param[0] + " "
+ + l_param[1]);
+ p_player.removeCard("Bomb");
+ System.out.println("Bomb card used, hence it is now removed from Player's cardList");
+ d_LogEntry.setMessage("Bomb card used, hence it is now removed from Player's cardList");
+ } else {
+ System.out.println(
+ "Bomb Card not owned or Country not owned by current player | please pass to the next player");
+ d_LogEntry.setMessage(
+ "Bomb Card not owned or Country not owned by the current player | please pass to the next player");
+ }
+ this.d_GamePhase = GamePhase.TAKETURN;
+ break;
+ } else {
+ System.out.println("Invalid Command");
+ }
+ } catch (Exception e) {
+ System.out.println(
+ "Bomb Card is not Owned or Country not owned by the current player | please pass to the next player");
+ d_LogEntry.setMessage(
+ "Bomb Card is not Owned or Country not owned by the current player | please pass to the next player");
+ }
+ break;
+
+
+
+ case "airlift":
+ System.out.println(l_commandName + " command entered");
+ try {
+ if (!(l_param[1] == null) && !(l_param[2] == null) && !(l_param[3] == null)) {
+ if (this.isAlphabetic(l_param[1]) && this.isNumeric(l_param[2]) && this.isAlphabetic(l_param[3])) {
+ setPhase(new IssueOrderPhase(this));
+ String sourceCountryId = l_param[1];
+ int numArmiesToAirlift = Integer.parseInt(l_param[2]);
+ String targetCountryId = l_param[3];
+
+ boolean sourceCountryOwned = p_player.getOwnedCountries()
+ .containsKey(sourceCountryId.toLowerCase());
+ boolean targetCountryOwned = p_player.getOwnedCountries()
+ .containsKey(targetCountryId.toLowerCase());
+ boolean checkCard = p_player.checkCardExists("Airlift");
+
+ if (sourceCountryOwned && targetCountryOwned && checkCard) {
+ // Create an Airlift order
+ Airlift airliftOrder = new Airlift(p_player, sourceCountryId, targetCountryId, numArmiesToAirlift);
+
+ // Add the Airlift order to the current player's order list
+ p_player.addOrder(airliftOrder);
+
+ //p_player.issue_order();
+ d_Phase.issue_order(p_player);
+
+ System.out.println("For player " + p_player.getPlayerName()
+ + " Airlift order added to Players OrdersList: " + l_param[0] + " "
+ + l_param[1] + " " + l_param[2] + " " + l_param[3]);
+ d_LogEntry.setMessage("For player " + p_player.getPlayerName()
+ + " Airlift order added to Players OrdersList: " + l_param[0] + " "
+ + l_param[1] + " " + l_param[2] + " " + l_param[3]);
+ p_player.removeCard("Airlift");
+ System.out.println("Airlift card used hence it is now removed from Player's cardList ");
+ d_LogEntry.setMessage("Airlift card used hence it is now removed from Player's cardList ");
+ } else {
+ System.out.println(
+ "Airlift Card not owned or Source/Target country not owned by current player | please pass to next player");
+ d_LogEntry.setMessage(
+ "Airlift Card not owned or Source/Target country not owned by current player | please pass to the next player");
+ }
+ this.d_GamePhase = GamePhase.TAKETURN;
+ break;
+ }
+ } else {
+ System.out.println("Invalid Command");
+ }
+ } catch (Exception e) {
+ System.out.println(
+ "Airlift Card is not Owned or Source/Target country not owned by current player | please pass to next player");
+ d_LogEntry.setMessage(
+ "Airlift Card is not Owned or Source/Target country not owned by current player | please pass to the next player");
+ }
+ break;
+
+
case "blockade":
System.out.println(l_commandName + " command entered");
try {
@@ -576,7 +684,7 @@ public GamePhase parseCommand(Player p_player, String p_givenCommand) {
System.out.println(
"Blockade Card not owned or Country not owned by current player | please pass to next player");
d_LogEntry.setMessage(
- "Blockade Card not qwned or Country not owned by current player | please pass to next player");
+ "Blockade Card not owned or Country not owned by current player | please pass to next player");
}
this.d_GamePhase = GamePhase.TAKETURN;
break;
@@ -758,4 +866,15 @@ private Player fetchPlayerByName(String p_playerName) {
}
return null;
}
+
+ private Player fetchTargetPlayer(Player currentPlayer) {
+ // Replace this logic with your actual implementation
+ for (Player player : d_Players) {
+ if (!player.getPlayerName().equals(currentPlayer.getPlayerName())) {
+ // Return the first player that is not the current player as the target player
+ return player;
+ }
+ }
+ return null; // Return null if no suitable target player is found
+ }
}
diff --git a/src/main/java/Model/Bomb.java b/src/main/java/Model/Bomb.java
index e3271b3..15d90cc 100644
--- a/src/main/java/Model/Bomb.java
+++ b/src/main/java/Model/Bomb.java
@@ -1,77 +1,89 @@
package Model;
-/**
- * Class containing logic for implementation of Bomb order
- * @author Alekhya K
- *
- */
-public class Bomb {
- private String d_CountryId;
- private Player d_Player;
- private Player d_CPlayer;
+public class Bomb implements Order {
+ private Player sourcePlayer;
+ private Player targetPlayer;
+ private String countryId;
- /**
- * This constructor will initialize the order object with deploy details.
- * @param p_cplayer source player who will bomb
- * @param p_player target player where the bomb will take effect
- * @param p_countryId adjacent opponent country where the bomb card will take effect
- */
- public Bomb(Player p_cplayer, Player p_player, String p_countryId) {
- d_Player = p_player;
- d_CPlayer = p_cplayer;
- d_CountryId = p_countryId;
+ public Bomb(Player currentPlayer, Player targetPlayer, String countryId) {
+ this.sourcePlayer = currentPlayer;
+ this.targetPlayer = targetPlayer;
+ this.countryId = countryId;
}
/**
* Method which enacts the order
+ *
* @return true if successful, else false
*/
public boolean execute() {
// Check if Source player is negotiating with the target Player
- if (d_CPlayer.getNegotiateList().contains(d_Player)) {
- System.out.println(d_CPlayer.getPlayerName() + " has negotiated " + d_Player.getPlayerName());
+ if (targetPlayer.getNegotiateList().contains(sourcePlayer)) {
+ System.out.println(targetPlayer.getPlayerName() + " has negotiated " + sourcePlayer.getPlayerName());
// Skip execution
return false;
}
- Country l_c = d_Player.getOwnedCountries().get(d_CountryId.toLowerCase());
- if (l_c != null) {
- int l_existingArmies = l_c.getNumberOfArmies();
- double armies = (double) (l_existingArmies / 2);
- l_c.setNumberOfArmies((int) armies);
+ Country targetCountry = targetPlayer.getOwnedCountries().get(countryId.toLowerCase());
+ if (targetCountry != null) {
+ int existingArmies = targetCountry.getNumberOfArmies();
+ double remainingArmies = existingArmies / 2.0;
+ targetCountry.setNumberOfArmies((int) remainingArmies);
return true;
}
return false;
}
/**
- * Getter for current player
- * @return d_Player
+ * Getter for source player
+ *
+ * @return sourcePlayer
+ */
+ public Player getSourcePlayer() {
+ return sourcePlayer;
+ }
+
+ /**
+ * Setter for source player
+ *
+ * @param sourcePlayer player
+ */
+ public void setSourcePlayer(Player sourcePlayer) {
+ this.sourcePlayer = sourcePlayer;
+ }
+
+ /**
+ * Getter for target player
+ *
+ * @return targetPlayer
*/
- public Player getD_Player() {
- return d_Player;
+ public Player getTargetPlayer() {
+ return targetPlayer;
}
/**
- * Setter for current player
- * @param d_Player player
+ * Setter for target player
+ *
+ * @param targetPlayer player
*/
- public void setD_Player(Player d_Player) {
- this.d_Player = d_Player;
+ public void setTargetPlayer(Player targetPlayer) {
+ this.targetPlayer = targetPlayer;
}
/**
- * Getter for ID of Country
- * @return d_CountryId
+ * Getter for country ID
+ *
+ * @return countryId
*/
- public String getD_CountryId() {
- return d_CountryId;
+ public String getCountryId() {
+ return countryId;
}
/**
- * Setter for ID of Country
- * @param d_CountryId country ID
+ * Setter for country ID
+ *
+ * @param countryId country ID
*/
- public void setD_CountryId(String d_CountryId) {
- this.d_CountryId = d_CountryId;
+ public void setCountryId(String countryId) {
+ this.countryId = countryId;
}
}
diff --git a/src/main/java/Model/Negotiate.java b/src/main/java/Model/Negotiate.java
index b20fc1a..0cc574c 100644
--- a/src/main/java/Model/Negotiate.java
+++ b/src/main/java/Model/Negotiate.java
@@ -11,7 +11,7 @@ public class Negotiate implements Order{
private Player d_sourcePlayer, d_targetPlayer;
/**
* Constructor that initializes class variable.
- * @param p_currentPlayer sorce player giving order
+ * @param p_currentPlayer source player giving order
* @param p_targetPlayer target player
*/
public Negotiate(Player p_currentPlayer,Player p_targetPlayer){
diff --git a/src/main/java/Model/Player.java b/src/main/java/Model/Player.java
index d55f51b..211841e 100644
--- a/src/main/java/Model/Player.java
+++ b/src/main/java/Model/Player.java
@@ -12,13 +12,7 @@ public class Player {
private HashMap d_OwnedContinents;
private HashMap d_OwnedCountries;
private int d_OwnedArmies;
-
-
-
private Order d_Order;
-
-
-
private Queue d_OrderList;
ArrayList d_CardDeck;
public List d_NegotiateList;