コード例 #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 RangedUnits)
         {
             RangedUnits R = (RangedUnits)closestUnit;
             R.Health -= Attack;
         }
         else if (closestUnit is WizzardUnits)
         {
             WizzardUnits R = (WizzardUnits)closestUnit;
             R.Health -= Attack;
         }
     }
     else if (type == 1)
     {
         if (closestBuilding is FactoryBuildings)
         {
             FactoryBuildings FB = (FactoryBuildings)closestBuilding;
             FB.Health -= Attack;
         }
         else if (closestBuilding is ResourceBuildings)
         {
             ResourceBuildings RB = (ResourceBuildings)closestBuilding;
             RB.Health -= Attack;
         }
     }
 }
コード例 #2
0
ファイル: RangedUnits.cs プロジェクト: LegendDRD/POE
 public Direction Directionto(Unit u)     // this changes the directions of the unit
 {
     if (u.GetType() == typeof(RangedUnits))
     {
         RangedUnits m = (RangedUnits)u;
         if (m.Xpos < Xpos)
         {
             return(Direction.Nort);
         }
         else if (m.Xpos > Xpos)
         {
             return(Direction.South);
         }
         else if (m.Ypos < Ypos)
         {
             return(Direction.West);
         }
         else
         {
             return(Direction.East);
         }
     }
     else
     {
         return(Direction.Nort);
     }
 }
コード例 #3
0
ファイル: RangedUnits.cs プロジェクト: LegendDRD/POE
 private int DistanceTo(Unit u)     // this finds the distance of a unit from this unit
 {
     if (u.GetType() == typeof(RangedUnits))
     {
         RangedUnits m = (RangedUnits)u;
         int         d = Math.Abs(Xpos - m.Xpos) + Math.Abs(Ypos - m.Ypos);
         return(d);
     }
     else
     {
         return(0);
     }
 }
コード例 #4
0
ファイル: Map.cs プロジェクト: Michael-Haechler11/GADE-POE
 public void SpawnUnits(int x, int y, Faction fac, string unitType)
 {
     if (unitType == "Ranged")
     {
         RangedUnits sniper = new RangedUnits("sniper", x, y, fac, 30, 1, 5, 3, "->", false);
         rangedUnits.Add(sniper);
         units.Add(sniper);
     }
     else if (unitType == "Melee")
     {
         MeleeUnit Cavalry = new MeleeUnit("Cavalry", x, y, fac, 50, 1, 10, 1, "#", false);
         meleeUnits.Add(Cavalry);
         units.Add(Cavalry);
     }
 }
コード例 #5
0
ファイル: RangedUnits.cs プロジェクト: LegendDRD/POE
    public override bool AttackRange(Unit u)
    {
        if (u.GetType() == typeof(RangedUnits))
        {
            RangedUnits M = (RangedUnits)u;
            if (DistanceTo(u) <= attackRange)
            {
                return(true);
            }

            else if (u.GetType() == typeof(RangedUnits))
            {
                Health -= ((RangedUnits)u).attack;
            }
            else
            {
                return(false);
            }
        }
        return(false);
    }
コード例 #6
0
        public void Load(ContentManager content, Viewport viewport, Camera camera, GraphicsDeviceManager graphics)
        {
            this.gameWindowTexture = content.Load<Texture2D>(@"Textures\GameScreens\GameScreen");
            room = new Rectangle(0, 0, gameWindowTexture.Width, gameWindowTexture.Height);

            this.characterPosition = new Vector2(room.Width/2, room.Height/2);
            this.soldier = new Heroes(characterPosition, 2);

            screen = new Rectangle(viewport.X, viewport.Y, viewport.Width, viewport.Height);

            this.meleUnit = new MeleUnits(new Vector2(500, 500), 1.6f);
            this.rangedUnit = new RangedUnits(new Vector2(480, 480), 0.1f);

            this.soldier.LoadContent(content, "thor_top_view");
            this.cursor.LoadContent(content, "crosshair");
            this.meleUnit.LoadContent(content, "male");
            this.rangedUnit.LoadContent(content, "male");
            this.soldier.Ammo = 100;

            Texture2D bulletTexture = content.Load<Texture2D>(@"Textures\Objects\bullet");

            for (int i = 0; i < this.soldier.Ammo; i++)
            {
                Bullet o = new Bullet(new Vector2(0, 0), bulletTexture);
                PBullets.Add(o);
            }

            for (int i = 0; i < 100; i++)
            {
                Bullet o = new Bullet(new Vector2(0, 0), bulletTexture);
                EnemyBullets.Add(o);
            }

            camera.Position = this.soldier.Position;
        }
コード例 #7
0
    public void Display()
    {
        foreach (Unit u in map.Unit)
        {
            if (u.GetType() == typeof(MeleeUnit))
            {
                MeleeUnit m = (MeleeUnit)u;



                if (m.symbol == "=")
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueKnight, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedKnight, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
                else
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueLance, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedLance, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
            }
        }
        foreach (Unit u in map.Unit)
        {
            if (u.GetType() == typeof(RangedUnits))
            {
                RangedUnits m = (RangedUnits)u;



                if (m.symbol == "}")
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueArcher, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedArcher, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
                else
                {
                    if (m.Fact == 1)
                    {
                        GameObject clone = Instantiate(BlueMusk, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    else
                    {
                        GameObject clone = Instantiate(RedMusk, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        clone.transform.parent = transform;
                    }
                    if (m.isDead())
                    {
                    }
                }
            }
        }


        foreach (Unit u in map.Unit)
        {
            if (u.GetType() == typeof(Emperor))
            {
                Emperor emperor = (Emperor)u;



                if (emperor.Fact == 1)
                {
                    GameObject clone = Instantiate(BLueEmp, new Vector2(emperor.Xpos, emperor.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(RedEmp, new Vector2(emperor.Xpos, emperor.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (emperor.isDead())
                {
                }
            }
        }
        foreach (Building b in map.Building)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding m = (FactoryBuilding)b;



                if (m.Fact == 1)
                {
                    GameObject clone = Instantiate(BlueFactory, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(RedFactory, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDestoryed())
                {
                }
            }
        }
        foreach (ResourceBuilding b in map.RB)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding m = (ResourceBuilding)b;



                if (m.Fact == 1)
                {
                    GameObject clone = Instantiate(BlueResource, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                else
                {
                    GameObject clone = Instantiate(RedResource, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                    clone.transform.parent = transform;
                }
                if (m.isDestoryed())
                {
                }
            }
        }
    }
コード例 #8
0
    private void UpdateMap()
    {
        foreach (Unit u in map.Unit)
        {
            bool inCombat = false;

            if (u.GetType() == typeof(MeleeUnit))
            {
                MeleeUnit m = (MeleeUnit)u;
                if (m.health > 0)
                {
                    foreach (Unit e in map.Unit) // working code
                    {
                        if (u.AttackRange(e))
                        {
                            u.Combat(e);
                            inCombat = true;
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Unit);
                            m.NewMovePos(m.Directionto(c));
                        }
                    }

                    if (m.health < 100)
                    {
                        switch (Random.Range(0, 4))
                        {
                        case 0: ((MeleeUnit)u).NewMovePos(Direction.Nort); break;

                        case 1: ((MeleeUnit)u).NewMovePos(Direction.East); break;

                        case 2: ((MeleeUnit)u).NewMovePos(Direction.South); break;

                        case 3: ((MeleeUnit)u).NewMovePos(Direction.West); break;
                        }
                    }
                }
                else
                {
                    m.isDead();
                    if (m.isDead())
                    {
                    }
                }
            }
        }
        foreach (Unit u in map.Unit)
        {
            bool inCombat = false;

            if (u.GetType() == typeof(RangedUnits))
            {
                RangedUnits ranged = (RangedUnits)u;
                if (ranged.health > 0)
                {
                    foreach (Unit e in map.Unit)     // working code
                    {
                        if (u.AttackRange(e))
                        {
                            u.Combat(e);
                            inCombat = true;
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Unit);
                            ranged.NewMovePos(ranged.Directionto(c));
                        }
                    }

                    if (ranged.health < 25)
                    {
                        switch (Random.Range(0, 4))
                        {
                        case 0: ((RangedUnits)u).NewMovePos(Direction.Nort); break;

                        case 1: ((RangedUnits)u).NewMovePos(Direction.East); break;

                        case 2: ((RangedUnits)u).NewMovePos(Direction.South); break;

                        case 3: ((RangedUnits)u).NewMovePos(Direction.West); break;
                        }
                    }
                }
                else
                {
                    ranged.isDead();
                    if (ranged.isDead())
                    {
                    }
                }
            }
        }
        foreach (Unit u in map.Unit)
        {
            bool inCombat = false;

            if (u.GetType() == typeof(Emperor))
            {
                Emperor m = (Emperor)u;
                if (m.health > 0)
                {
                    foreach (Unit e in map.Unit) // working code
                    {
                        if (u.AttackRange(e))
                        {
                            u.Combat(e);
                            inCombat = true;
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Unit);
                            m.NewMovePos(m.Directionto(c));
                        }
                    }

                    if (m.health < 25)
                    {
                        switch (Random.Range(0, 4))
                        {
                        case 0: ((Emperor)u).NewMovePos(Direction.Nort); break;

                        case 1: ((Emperor)u).NewMovePos(Direction.East); break;

                        case 2: ((Emperor)u).NewMovePos(Direction.South); break;

                        case 3: ((Emperor)u).NewMovePos(Direction.West); break;
                        }
                    }
                }
                else
                {
                    m.isDead();
                    if (m.isDead())
                    {
                    }
                }
            }
        }
    }
コード例 #9
0
    public void Clickon()
    {
        Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

        if (hit)
        {
            float x = hit.collider.transform.position.x;
            float y = hit.collider.transform.position.y;

            foreach (Unit u in map.Unit)
            {
                if (u.GetType() == typeof(RangedUnits))
                {
                    RangedUnits r = (RangedUnits)u;
                    if (r.Xpos == x && r.Ypos == y)
                    {
                        texts.text = r.Tostring();
                    }
                }
                else if (u.GetType() == typeof(MeleeUnit))
                {
                    MeleeUnit m = (MeleeUnit)u;
                    if (m.Xpos == x && m.Ypos == y)
                    {
                        texts.text = m.Tostring();
                    }
                }
            }
            foreach (FactoryBuilding u in map.Building)
            {
                if (u.GetType() == typeof(FactoryBuilding))
                {
                    FactoryBuilding r = (FactoryBuilding)u;
                    if (r.Xpos == x && r.Ypos == y)
                    {
                        texts.text = r.toString();
                    }
                }
                else if (u.GetType() == typeof(FactoryBuilding))
                {
                    FactoryBuilding m = (FactoryBuilding)u;
                    if (m.Xpos == x && m.Ypos == y)
                    {
                        texts.text = m.toString();
                    }
                }
            }
            foreach (ResourceBuilding u in map.RB)
            {
                if (u.GetType() == typeof(ResourceBuilding))
                {
                    ResourceBuilding r = (ResourceBuilding)u;
                    if (r.Xpos == x && r.Ypos == y)
                    {
                        texts.text = r.toString();
                    }
                }
                else if (u.GetType() == typeof(ResourceBuilding))
                {
                    ResourceBuilding m = (ResourceBuilding)u;
                    if (m.Xpos == x && m.Ypos == y)
                    {
                        texts.text = m.toString();
                    }
                }
            }
        }
    }
コード例 #10
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 RangedUnits)
                {
                    RangedUnits closestUnitR = (RangedUnits)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 WizzardUnits)
                {
                    WizzardUnits closestUnitR = (WizzardUnits)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 ResourceBuildings)
                {
                    ResourceBuildings closestBuildingRB = (ResourceBuildings)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 = Random.Range(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--;
            }
        }
    }
コード例 #11
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 = Mathf.Abs((PosX - M.PosX) * (PosX - M.PosX));
            yDis = Mathf.Abs((PosY - M.PosY) * (PosY - M.PosY));

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

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

            uDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }

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

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

            bDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }

        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);
        }
    }
コード例 #12
0
ファイル: Map.cs プロジェクト: LegendDRD/POE
    public Map(int maxX, int maxY, int numUnits, int numbuilding)
    {
        building = new Building[numbuilding];
        rb       = new ResourceBuilding[numbuilding];
        unit     = new Unit[numUnits];
        for (int i = 0; i < numUnits; i++)
        {
            if (i <= 10)
            {
                MeleeUnit M = new MeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(60, 100) * 10, r.Next(5, 20), 1, 1, i % 2, "=", "Knight");
                Unit[i] = M;
            }


            if (i > 10 && i < 20)
            {
                RangedUnits R = new RangedUnits(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, "}", "Archer");
                Unit[i] = R;
            }

            if (i >= 20 && i < 22)
            {
                Emperor E = new Emperor(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, "#", "Emperor");
                unit[i] = E;
            }
            if (i >= 22 && i < 27)
            {
                RangedUnits E = new RangedUnits(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, "->", "Muksmen");
                unit[i] = E;
            }
            if (i > 26)
            {
                MeleeUnit Lance = new MeleeUnit(r.Next(0, maxX), r.Next(0, maxY), r.Next(10, 20) * 10, r.Next(5, 20), 1, 1, i % 2, ">", "Lance");
                unit[i] = Lance;
            }
        }
        for (int i = 0; i < numbuilding; i++)
        {
            if (i <= 5)
            {
                FactoryBuilding fb = new FactoryBuilding(r.Next(-14, 20), r.Next(-22, maxY), r.Next(5, 20), 1, "F", r.Next(0, 1), r.Next(5, 10), buildingx);
                building[i] = fb;
            }


            if (i > 5)
            {
                FactoryBuilding fbr = new FactoryBuilding(r.Next(50, maxX), r.Next(-22, maxY), r.Next(5, 20), 0, "F", r.Next(0, 1), r.Next(5, 10), buildingx);
                building[i] = fbr;
            }
        }
        for (int i = 0; i < numbuilding; i++)
        {
            if (i <= 5)
            {
                ResourceBuilding fb = new ResourceBuilding(r.Next(-14, 20), r.Next(-22, maxY), r.Next(5, 20), 1, "RB", r.Next(0, 1), r.Next(5, 10), 400);
                rb[i] = fb;
            }


            if (i > 5)
            {
                ResourceBuilding fbr = new ResourceBuilding(r.Next(50, 80), r.Next(-22, maxY), r.Next(5, 20), 0, "RB", r.Next(0, 1), r.Next(5, 10), 400);
                rb[i] = fbr;
            }
        }
    }
コード例 #13
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 = Mathf.Abs((PosX - M.PosX) * (PosX - M.PosX));
            yDis = Mathf.Abs((PosY - M.PosY) * (PosY - M.PosY));

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

            uDistance = (int)Mathf.Round(Mathf.Sqrt(xDis + yDis));
        }

        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);
        }
    }
コード例 #14
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 RangedUnits)
            {
                RangedUnits R = (RangedUnits)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;
                }
            }
        }
    }