Esempio 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;
         }
     }
 }
Esempio n. 2
0
 public void SpawnUnits(int x, int y, Faction fac, string unitType)
 {
     if (unitType == "Ranged")
     {
         RangedUnit sniper = new RangedUnit("sniper", x, y, fac, 30, 1, 5, 3, "->", false);
         rangedUnits.Add(sniper);
         units.Add(sniper);
     }
     else if (unitType == "Melee")
     {
         Debug.Print("Create melee");
         MeleeUnit Cavalry = new MeleeUnit("Cavalry", x, y, fac, 50, 1, 10, 1, "#", false);
         meleeUnits.Add(Cavalry);
         units.Add(Cavalry);
     }
 }
Esempio n. 3
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--;
                }
            }
        }
Esempio n. 4
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);
            }
        }
        public void GenerateBattlefield()
        {
            for (int i = 0; i < unitNum; i++)
            {
                if (rd.Next(0, 2) == 0)
                {
                    RangedUnit sniper = new RangedUnit(0, 0, Faction.Overwatch, 15, 1, 3, 3, "︻デ═一", false);
                    rangedUnits.Add(sniper);
                }
                else
                {
                    MeleeUnit Cavalry = new MeleeUnit(0, 0, Faction.Overwatch, 15, 1, 3, 3, "▬===>", false);
                    meleeUnits.Add(Cavalry);
                }
            }
            for (int i = 0; i < unitNum; i++)
            {
                if (rd.Next(0, 2) == 0)
                {
                    RangedUnit sniper = new RangedUnit(0, 0, Faction.Talon, 15, 1, 3, 3, "︻デ═一", false);
                    rangedUnits.Add(sniper);
                }
                else
                {
                    MeleeUnit Cavalry = new MeleeUnit(0, 0, Faction.Talon, 15, 1, 3, 3, "▬===>", false);
                    meleeUnits.Add(Cavalry);
                }
            }

            foreach (Unit u in rangedUnits)
            {
                for (int i = 0; i < units.Count; i++)
                {
                    int xPos = rd.Next(0, 20);
                    int yPos = rd.Next(0, 20);

                    while (xPos == units[i].posX && yPos == meleeUnits[i].posY && xPos == rangedUnits[i].posX && yPos == rangedUnits[i].posY)
                    {
                        xPos = rd.Next(0, 20);
                        yPos = rd.Next(0, 20);
                    }

                    u.posX = xPos;
                    u.posY = yPos;
                    unitMap[u.posY, u.posX] = (Unit)u;
                }

                units.Add(u);
            }

            foreach (Unit u in meleeUnits)
            {
                for (int i = 0; i < units.Count; i++)
                {
                    int xPos = rd.Next(0, 20);
                    int yPos = rd.Next(0, 20);

                    while (xPos == units[i].posX && yPos == meleeUnits[i].posY && xPos == meleeUnits[i].posX && yPos == meleeUnits[i].posY)
                    {
                        xPos = rd.Next(0, 20);
                        yPos = rd.Next(0, 20);
                    }

                    u.posX = xPos;
                    u.posY = yPos;
                }
                unitMap[u.posY, u.posX] = (Unit)u;
                units.Add(u);
            }
            PlaceUnits();
        }
Esempio n. 6
0
        public override void Move(int type)
        {
            //Moves towards closest enemey
            if (Health > MaxHealth * 0.5)
            {
                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 //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--;
                }
            }
        }
Esempio n. 7
0
        public override void CheckAttackRange(List <Unit> uni, List <buildings> build)
        {
            units    = uni;
            building = build;

            closestUnit = ClosestEnemy();

            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);
            }

            if (units[0] != null)
            {
                if (uDistance < bDistance)
                {
                    distance  = uDistance;
                    enemyType = 0;
                }
                else
                {
                    distance  = bDistance;
                    enemyType = 1;
                }
            }
            else
            {
                distance  = bDistance;
                enemyType = 1;
            }
            if (Health > MaxHealth * 0.5)
            {
                if (distance <= AttackRange)
                {
                    IsAttacking = true;
                    Combat(enemyType);
                }
                else
                {
                    IsAttacking = false;
                    Move(enemyType);
                }
            }
            else
            {
                Move(enemyType);
            }
        }
Esempio n. 8
0
        public override void Combat(int type) //combat method for the wizard to attack the
        {
            foreach (Unit u in units)
            {
                if (u is MeleeUnit)
                {
                    MeleeUnit M = (MeleeUnit)u;

                    if (M.PosX == PosX - 1 && M.PosY == PosY - 1)
                    {
                        M.Health -= 1;
                    }
                    else if (M.PosX == PosX && M.PosY == PosY - 1)
                    {
                        M.Health -= 1;
                    }
                    else if (M.PosX == PosX + 1 && M.PosY == PosY - 1)
                    {
                        M.Health -= 1;
                    }
                    else if (M.PosX == PosX - 1 && M.PosY == PosY)
                    {
                        M.Health -= 1;
                    }
                    else if (M.PosX == PosX + 1 && M.PosY == PosY)
                    {
                        M.Health -= 1;
                    }
                    else if (M.PosX == PosX - 1 && M.PosY == PosY + 1)
                    {
                        M.Health -= 1;
                    }
                    else if (M.PosX == PosX && M.PosY == PosY + 1)
                    {
                        M.Health -= 1;
                    }
                    else if (M.PosX == PosX + 1 && M.PosY == PosY + 1)
                    {
                        M.Health -= 1;
                    }
                }
                else if (u is RangedUnit)
                {
                    RangedUnit R = (RangedUnit)u;

                    if (R.PosX == PosX - 1 && R.PosY == PosY - 1)
                    {
                        R.Health -= 1;
                    }
                    else if (R.PosX == PosX && R.PosY == PosY - 1)
                    {
                        R.Health -= 1;
                    }
                    else if (R.PosX == PosX + 1 && R.PosY == PosY - 1)
                    {
                        R.Health -= 1;
                    }
                    else if (R.PosX == PosX - 1 && R.PosY == PosY)
                    {
                        R.Health -= 1;
                    }
                    else if (R.PosX == PosX + 1 && R.PosY == PosY)
                    {
                        R.Health -= 1;
                    }
                    else if (R.PosX == PosX - 1 && R.PosY == PosY + 1)
                    {
                        R.Health -= 1;
                    }
                    else if (R.PosX == PosX && R.PosY == PosY + 1)
                    {
                        R.Health -= 1;
                    }
                    else if (R.PosX == PosX + 1 && R.PosY == PosY + 1)
                    {
                        R.Health -= 1;
                    }
                }
            }
        }