Exemplo n.º 1
0
        public string attack(string attacker, string defender, int nTankAttacker, int nTankDefender)
        {
            Land attackerLand = findLandByName(attacker);
            Land defenderLand = findLandByName(defender);

            int currentAttackerTanks = attackerLand.getTanksOnLand();
            int currentDefenderTanks = defenderLand.getTanksOnLand();

            string result = "";

            if (checkedRispectiveOwners(attackerLand, defenderLand) && checkedTankNumbers(currentAttackerTanks, currentDefenderTanks, nTankAttacker, nTankDefender))
            {
                gameManager.attack(attackerLand, defenderLand, nTankAttacker, nTankDefender);

                if (defenderLand.getTanksOnLand() == 0)
                {
                    int tanksMoving = nTankAttacker - (currentAttackerTanks - attackerLand.getTanksOnLand());
                    gameManager.passLand(attackerLand, defenderLand, currentPlayer, getPlayerByName(getPlayerByLand(attacker)), tanksMoving);
                }
            }
            else
            {
                result = "Lands not belonging to their respective owners or tank number is not correct";
            }

            return(result);
        }
Exemplo 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);
        }
Exemplo 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);
        }