-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from RancyKaur/build2-cpy
AIRLIFT AND BOMB
- Loading branch information
Showing
6 changed files
with
178 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters