Beispiel #1
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())
                {
                }
            }
        }
    }
Beispiel #2
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())
                    {
                    }
                }
            }
        }
    }