Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 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;
         }
     }
 }
Ejemplo n.º 5
0
 public void addTanks(RiskPlayer player, Land land, int nTank)
 {
     player.removeTanks(nTank);
     land.addTanksOnLand(nTank);
 }
Ejemplo n.º 6
0
 public void moveTanks(Land startLand, Land endLand, int nTank)
 {
     startLand.removeTanksOnLand(nTank);
     endLand.addTanksOnLand(nTank);
 }
Ejemplo n.º 7
0
        public bool areNeighbor(string firstLand, string secondLand)
        {
            Land start = findLandByName(firstLand);

            return(start.isNeighbor(secondLand));
        }
Ejemplo n.º 8
0
 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()));
 }