Exemplo n.º 1
0
 public override void Combat(int type)
 {
     if (type == 0)
     {
         if (closestUnit is MeleeUnit)
         {
             MeleeUnit M = (MeleeUnit)closestUnit;
             M.Health -= Attack;
         }
         else if (closestUnit is RangedUnit)
         {
             RangedUnit R = (RangedUnit)closestUnit;
             R.Health -= Attack;
         }
         else if (closestUnit is WizzardUnit)
         {
             WizzardUnit R = (WizzardUnit)closestUnit;
             R.Health -= Attack;
         }
     }
     else if (type == 1)
     {
         if (closestBuilding is FactoryBuildings)
         {
             FactoryBuildings FB = (FactoryBuildings)closestBuilding;
             FB.Health -= Attack;
         }
         else if (closestBuilding is ResourceBuilding)
         {
             ResourceBuilding RB = (ResourceBuilding)closestBuilding;
             RB.Health -= Attack;
         }
     }
 }
Exemplo n.º 2
0
        public override void Move(int type)
        {
            //Moves towards closest enemey
            if (Health > MaxHealth * 0.25)
            {
                if (type == 0)
                {
                    if (closestUnit is MeleeUnit)
                    {
                        MeleeUnit closestUnitM = (MeleeUnit)closestUnit;

                        if (closestUnitM.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestUnitM.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestUnitM.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestUnitM.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                    else if (closestUnit is RangedUnit)
                    {
                        RangedUnit closestUnitR = (RangedUnit)closestUnit;

                        if (closestUnitR.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestUnitR.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestUnitR.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestUnitR.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                    else if (closestUnit is WizzardUnit)
                    {
                        WizzardUnit closestUnitR = (WizzardUnit)closestUnit;

                        if (closestUnitR.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestUnitR.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestUnitR.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestUnitR.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                }
                else
                {
                    if (closestBuilding is FactoryBuildings)
                    {
                        FactoryBuildings closestBuildingFB = (FactoryBuildings)closestBuilding;

                        if (closestBuildingFB.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestBuildingFB.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestBuildingFB.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestBuildingFB.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                    else if (closestBuilding is ResourceBuilding)
                    {
                        ResourceBuilding closestBuildingRB = (ResourceBuilding)closestBuilding;

                        if (closestBuildingRB.PosX > posX && PosX < 20)
                        {
                            posX++;
                        }
                        else if (closestBuildingRB.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestBuildingRB.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestBuildingRB.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                }
            }
            else //Moves the unit in a direction that is determined by random
            {
                int direction = r.Next(0, 4);

                if (direction == 0 && PosX < 19)
                {
                    posX++;
                }
                else if (direction == 1 && posX > 0)
                {
                    posX--;
                }
                else if (direction == 2 && posY < 19)
                {
                    posY++;
                }
                else if (direction == 3 && posY > 0)
                {
                    posY--;
                }
            }
        }
Exemplo n.º 3
0
        public override void CheckAttackRange(List <Unit> uni, List <buildings> build)
        {
            units    = uni;
            building = build;

            closestUnit     = ClosestEnemy();
            closestBuilding = ClosestBuilding();

            int enemyType;

            int xDis = 0, yDis = 0;

            int uDistance = 10000, bDistance = 10000;
            int distance;

            if (closestUnit is MeleeUnit)
            {
                MeleeUnit M = (MeleeUnit)closestUnit;
                xDis = Math.Abs((PosX - M.PosX) * (PosX - M.PosX));
                yDis = Math.Abs((PosY - M.PosY) * (PosY - M.PosY));

                uDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }
            else if (closestUnit is RangedUnit)
            {
                RangedUnit R = (RangedUnit)closestUnit;
                xDis = Math.Abs((PosX - R.PosX) * (PosX - R.PosX));
                yDis = Math.Abs((PosY - R.PosY) * (PosY - R.PosY));

                uDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }
            else if (closestUnit is WizzardUnit)
            {
                WizzardUnit R = (WizzardUnit)closestUnit;
                xDis = Math.Abs((PosX - R.PosX) * (PosX - R.PosX));
                yDis = Math.Abs((PosY - R.PosY) * (PosY - R.PosY));

                uDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }

            if (closestBuilding is FactoryBuildings)
            {
                FactoryBuildings FB = (FactoryBuildings)closestBuilding;
                xDis = Math.Abs((PosX - FB.PosX) * (PosX - FB.PosX));
                yDis = Math.Abs((PosY - FB.PosY) * (PosY - FB.PosY));

                bDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }
            else if (closestBuilding is ResourceBuilding)
            {
                ResourceBuilding RB = (ResourceBuilding)closestBuilding;
                xDis = Math.Abs((PosX - RB.PosX) * (PosX - RB.PosX));
                yDis = Math.Abs((PosY - RB.PosY) * (PosY - RB.PosY));

                bDistance = (int)Math.Round(Math.Sqrt(xDis + yDis), 0);
            }

            if (units[0] != null)
            {
                if (uDistance < bDistance)
                {
                    distance  = uDistance;
                    enemyType = 0;
                }
                else
                {
                    distance  = bDistance;
                    enemyType = 1;
                }
            }
            else
            {
                distance  = bDistance;
                enemyType = 1;
            }

            //Checks to see if they are below 25% health so they move rather than attacking
            if (Health > MaxHealth * 0.25)
            {
                if (distance <= AttackRange)
                {
                    IsAttacking = true;
                    Combat(enemyType);
                }
                else
                {
                    IsAttacking = false;
                    Move(enemyType);
                }
            }
            else
            {
                Move(enemyType);
            }
        }
Exemplo n.º 4
0
        public void GenerateBattleField() // method to allow the random number of units, including the ranged and the melee units
        {
            for (int i = 0; i < BuildingNum; i++)
            {
                int    UnitNum = Rd.Next(0, 2);
                string UnitName;
                if (UnitNum == 0)
                {
                    UnitName = "Melee";
                }
                else
                {
                    UnitName = "Ranged";
                }

                ResourceBuilding DiamondMine = new ResourceBuilding(0, 0, 100, Faction.Overwatch, "**");
                BitCoinMine.Add(DiamondMine);

                FactoryBuildings Barrack = new FactoryBuildings(0, 0, 100, Faction.Overwatch, "$$", Rd.Next(3, 10), UnitName);
                Barracks.Add(Barrack);
            }
            for (int i = 0; i < BuildingNum; i++)
            {
                int    UnitNum = Rd.Next(0, 2);
                string UnitName;
                if (UnitNum == 0)
                {
                    UnitName = "Melee";
                }
                else
                {
                    UnitName = "Ranged";
                }

                ResourceBuilding DiamondMine = new ResourceBuilding(0, 0, 100, Faction.Talon, "**");
                BitCoinMine.Add(DiamondMine);

                FactoryBuildings barrack = new FactoryBuildings(0, 0, 100, Faction.Talon, "$$", Rd.Next(3, 10), UnitName);
                Barracks.Add(barrack);
            }
            for (int i = 0; i < BuildingNum; i++)
            {
                WizzardUnit wizzard = new WizzardUnit("Wizard", 0, 0, Faction.Neutral, 20, 2, 3, 1, "^", false);
                wizzardUnits.Add(wizzard);
            }

            foreach (ResourceBuilding u in BitCoinMine)
            {
                for (int i = 0; i < BitCoinMine.Count; i++)
                {
                    int xPos = Rd.Next(0, mapHeight);
                    int yPos = Rd.Next(0, mapWidth);

                    while (xPos == BitCoinMine[i].PosX && yPos == BitCoinMine[i].PosY && xPos == Barracks[i].PosX && yPos == Barracks[i].PosY)
                    {
                        xPos = Rd.Next(0, mapHeight);
                        yPos = Rd.Next(0, mapWidth);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                }
                buildingMap[u.PosY, u.PosX] = (buildings)u;
                buildings.Add(u);
            }


            foreach (FactoryBuildings u in Barracks)
            {
                for (int i = 0; i < Barracks.Count; i++)
                {
                    int xPos = Rd.Next(0, mapHeight);
                    int yPos = Rd.Next(0, mapWidth);

                    while (xPos == Barracks[i].PosX && yPos == Barracks[i].PosY && xPos == BitCoinMine[i].PosX && yPos == BitCoinMine[i].PosY)
                    {
                        xPos = Rd.Next(0, mapHeight);
                        yPos = Rd.Next(0, mapWidth);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                }
                buildingMap[u.PosY, u.PosX] = (buildings)u;
                buildings.Add(u);

                u.SpawnPointY = u.PosY;
                if (u.PosX < 19)
                {
                    u.SpawnPointX = u.PosX + 1;
                }
                else
                {
                    u.SpawnPointX = u.PosX - 1;
                }
            }
            foreach (WizzardUnit u in wizzardUnits)
            {
                for (int i = 0; i < wizzardUnits.Count; i++)
                {
                    int xPos = Rd.Next(0, mapHeight);
                    int yPos = Rd.Next(0, mapWidth);

                    while (xPos == BitCoinMine[i].PosX && yPos == BitCoinMine[i].PosY && xPos == Barracks[i].PosX && yPos == Barracks[i].PosY && xPos == wizzardUnits[i].PosX && yPos == wizzardUnits[i].PosY)
                    {
                        xPos = Rd.Next(0, mapHeight);
                        yPos = Rd.Next(0, mapWidth);
                    }

                    u.PosX = xPos;
                    u.PosY = yPos;
                }
                uniMap[u.PosY, u.PosX] = (Unit)u;
                units.Add(u);
            }
            Populate();
            PlaceBuildings();
        }