private Land findLandByName(string name) { Land result = null; foreach (Continent continent in world) { List <Land> lands = continent.getLands(); foreach (Land land in lands) { if (land.getName() == name) { result = land; } } } return(result); }
public string getLandData(string land) { string result = ""; Land selectedLand = findLandByName(land); if (selectedLand != null) { result += land + System.Environment.NewLine; result += findContinentByLand(selectedLand).getName() + System.Environment.NewLine; result += getPlayerByLand(land) + System.Environment.NewLine; result += selectedLand.getTanksOnLand() + System.Environment.NewLine; foreach (Land neighbor in selectedLand.getNeighbors()) { result += neighbor.getName() + System.Environment.NewLine; } } return(result); }
public string moveTanks(string startLand, string endLand, int nTank) { Land firstLand = findLandByName(startLand); Land secondLand = findLandByName(endLand); string result = ""; if (currentPlayer.hasLand(startLand) && currentPlayer.hasLand(endLand) && (firstLand.getTanksOnLand() - 1) >= nTank) { gameManager.moveTanks(firstLand, secondLand, nTank); } else { result = "One of the lands don't belong to the current player or the number of tanks you want to " + "move is not allowed!"; } return(result); }
private void checkResults(List <int> attackerDices, List <int> defenderDices, Land attacker, Land defender) { for (int i = 0; i < attackerDices.Count; i++) { // Se il difensore ha tank con cui difendersi if (i <= defenderDices.Count - 1) { // Se attaccante vince il difensore perde 1 tank if (attackerDices[i] > defenderDices[i]) { defender.removeTanksOnLand(1); } else // altrimenti attaccante perde 1 tank { attacker.removeTanksOnLand(1); } } else { return; } } }
public void addTanks(RiskPlayer player, Land land, int nTank) { player.removeTanks(nTank); land.addTanksOnLand(nTank); }
public void moveTanks(Land startLand, Land endLand, int nTank) { startLand.removeTanksOnLand(nTank); endLand.addTanksOnLand(nTank); }
public bool areNeighbor(string firstLand, string secondLand) { Land start = findLandByName(firstLand); return(start.isNeighbor(secondLand)); }
private bool checkedRispectiveOwners(Land attacker, Land defender)//controlla che lo stato attacante è di sua proprietà e quello difensivo non sia suo { return(currentPlayer.hasLand(defender.getName()) && !currentPlayer.hasLand(attacker.getName())); }