예제 #1
0
 public override void Combat(int type) // the method to get the units to fight their enemies and shows them who to fight
 {
     if (type == 0)
     {
         if (ClosestUnit is MelleUnit)
         {
             MelleUnit M = (MelleUnit)ClosestUnit;
             M.Health -= Attack;
         }
         else if (ClosestUnit is RangedUnit)
         {
             RangedUnit R = (RangedUnit)ClosestUnit;
             R.Health -= Attack;
         }
     }
     else if (type == 1)
     {
         if (ClosestBuilding is FactoryBuilding)
         {
             FactoryBuilding Fb = (FactoryBuilding)ClosestBuilding;
             Fb.Health -= Attack;
         }
         else if (ClosestBuilding is ResourceBuilding)
         {
             ResourceBuilding RB = (ResourceBuilding)ClosestBuilding;
             RB.Health -= Attack;
         }
     }
 }
예제 #2
0
        public override Units Position() //checks the Position of the Buildings and which positions to spawn units
        {
            int    Xdis = 0, Ydis = 0;
            double Distance = 1000;
            double temp     = 1000;
            Units  Target   = null;

            foreach (Units b in units)
            {
                if (b is RangedUnit)
                {
                    RangedUnit Fb = (RangedUnit)b;

                    if (FactionType != b.factionType)
                    {
                        Xdis = Math.Abs(PosX - Fb.PosX) * (PosX - Fb.PosX);
                        Ydis = Math.Abs(PosY - Fb.PosY) * (PosY - Fb.PosY);

                        Distance = Math.Round(Math.Sqrt(Xdis + Ydis), 0);
                    }
                }
                else if (b is MelleUnit)
                {
                    MelleUnit Rb = (MelleUnit)b;
                    if (FactionType != b.factionType)
                    {
                        Xdis = Math.Abs(PosX - Rb.PosX) * (PosX - Rb.PosX);
                        Ydis = Math.Abs(PosY - Rb.PosY) * (PosY - Rb.PosY);

                        Distance = Math.Round(Math.Sqrt(Xdis + Ydis), 0);
                    }
                }
                else if (b is WizardUnit)
                {
                    WizardUnit Wu = (WizardUnit)b;
                    if (FactionType != b.factionType)
                    {
                        Xdis = Math.Abs(PosX - Wu.PosX) * (PosX - Wu.PosX);
                        Ydis = Math.Abs(PosY - Wu.PosY) * (PosY - Wu.PosY);

                        Distance = Math.Round(Math.Sqrt(Xdis + Ydis), 0);
                    }
                }

                if (Distance < temp)
                {
                    temp   = Distance;
                    Target = b;
                }
            }

            return(Target);
        }
예제 #3
0
        Move(int type)     // all the move functions for the units once they have spawned and the the Buildings themselves
        {
            if (Health > MaxHealth * 0.5)
            {
                if (ClosestUnit is MelleUnit)
                {
                    MelleUnit closestUnitM = (MelleUnit)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--;
                    }
                }
            }
        }
예제 #4
0
 public void SpawnUnits(int x, int y, Faction fac, string unitType) // Spawning the Units from the Buildings including the melee and ranged Units
 {
     if (unitType == "Ranged")
     {
         RangedUnit Musketeer = new RangedUnit("Musketeer", x, y, 30, 1, 5, 3, fac, "->", false);
         rangedUnit.Add(Musketeer);
         units.Add(Musketeer);
     }
     else if (unitType == "Melee")
     {
         MelleUnit Pekka = new MelleUnit("Pekka", x, y, 50, 1, 10, 1, fac, "#", false);
         melleUnit.Add(Pekka);
         units.Add(Pekka);
     }
 }
예제 #5
0
        public void Populate() // method used to populate the map full of units
        {
            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapHeight; j++)
                {
                    map[i, j] = " ";
                }
            }

            foreach (Units u in units) ////
            {
                if (u is RangedUnit)
                {
                    RangedUnit r = (RangedUnit)u;
                    uniMap[r.PosY, r.PosX] = u;
                }
                else if (u is MelleUnit)
                {
                    MelleUnit m = (MelleUnit)u;
                    uniMap[m.PosY, m.PosX] = u;
                }
                else if (u is WizardUnit)
                {
                    WizardUnit w = (WizardUnit)u;
                    uniMap[w.PosY, w.PosX] = u;
                }
            }

            foreach (Units u in units)
            {
                uniMap[u.posY, u.posX] = u; //////
            }

            foreach (Units u in rangedUnit)
            {
                map[u.posY, u.posX] = "R";
            }
            foreach (Units u in melleUnit)
            {
                map[u.posY, u.posX] = "M";
            }
            foreach (WizardUnit u in wizardUnits)
            {
                map[u.posY, u.posX] = "W";
            }
        }
예제 #6
0
        public override void AttRange(List <Units> uni, List <Building> builds) // checking the range of the building and the units they spawn
        {
            units     = uni;
            buildings = builds;

            ClosestUnit = Position();

            int enemyType;

            int xDis = 0, yDis = 0;

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

            if (ClosestUnit is MelleUnit)
            {
                MelleUnit M = (MelleUnit)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;
            }

            //Checks to see if they are below 50% health so they move rather than attacking
            if (Health > MaxHealth * 0.5)
            {
                if (distance <= atkRange)
                {
                    isAtk = true;
                    Combat(enemyType);
                }
                else
                {
                    isAtk = false;
                    Move(enemyType);
                }
            }
            else
            {
                Move(enemyType);
            }
        }
예제 #7
0
        Combat(int type)     // the method to get the units to fight their enemies and shows them who to fight
        {
            foreach (Units u in units)
            {
                if (u is MelleUnit) //setting the attack variables if the oposition is a melee unit
                {
                    MelleUnit m = (MelleUnit)u;

                    if (m.posX == posX - 1 && m.posY == posY - 1)
                    {
                        m.health -= 1;
                    }
                    else if (m.posX == posY && 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;
                    }
                }
                if (u is RangedUnit)  //setting the attack variables if the oposition is a Ranged unit
                {
                    RangedUnit m = (RangedUnit)u;

                    if (m.posX == posX - 1 && m.posY == posY - 1)
                    {
                        m.health -= 1;
                    }
                    else if (m.posX == posY && 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;
                    }
                }
            }
        }
예제 #8
0
        public override void Move(int type) // all the move functions for the units once they have spawned and the the Buildings themselves
        {
            if (Health > MaxHealth * 0.25)
            {
                if (type == 0)
                {
                    if (ClosestUnit is MelleUnit)
                    {
                        MelleUnit closestUnitM = (MelleUnit)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 WizardUnit) // showing the new wizard who he can attack and when he can attack them
                    {
                        WizardUnit closestUnitW = (WizardUnit)ClosestUnit;

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

                        if (closestUnitW.PosY > posY && PosY < 20)
                        {
                            posY++;
                        }
                        else if (closestUnitW.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                }
                else
                {
                    if (ClosestBuilding is FactoryBuilding)
                    {
                        FactoryBuilding closestBuildingFB = (FactoryBuilding)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 < 19)
                        {
                            posX++;
                        }
                        else if (closestBuildingRB.PosX < posX && posX > 0)
                        {
                            posX--;
                        }

                        if (closestBuildingRB.PosY > posY && PosY < 19)
                        {
                            posY++;
                        }
                        else if (closestBuildingRB.PosY < posY && posY > 0)
                        {
                            posY--;
                        }
                    }
                }
            }
            else
            {
                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--;
                }
            }
        }