示例#1
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())
                    {
                    }
                }
            }
        }
    }
示例#2
0
    private void UpdateMap() // this will cycle through all the units and buildisngs to see if they need to move and whether or not they have been killed in combat
    {
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeleeUnit))
            {
                MeleeUnit m = (MeleeUnit)u;
                if (m.health > 1)
                {
                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((MeleeUnit)u).NewPos(Direction.North); break;

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

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

                        case 3: ((MeleeUnit)u).NewPos(Direction.West); break;
                        }
                    }
                    else if (m.health < 10)  // this method will check a units health to see if it below 10 and if it is there will be a 50% chance of that unit changing alleigance to the other team and the unit will gain a small amount of health as compensation for changing team
                    {
                        int teamChange = r.Next(0, 2);
                        if (teamChange == 0)
                        {
                            if (m.faction == 1)
                            {
                                m.faction = 0;
                                m.health  = m.health + 5;
                            }
                            else
                            {
                                m.faction = 1;
                                m.health  = m.health + 5;
                            }
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinAttackRange(e))
                            {
                                u.combatWithUnit(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = "X";
                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit m = (RangedUnit)u;
                if (m.health > 1)
                {
                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((RangedUnit)u).NewPos(Direction.North); break;

                        case 1: ((RangedUnit)u).NewPos(Direction.East); break;

                        case 2: ((RangedUnit)u).NewPos(Direction.South); break;

                        case 3: ((RangedUnit)u).NewPos(Direction.West); break;
                        }
                    }
                    else if (m.health < 10)  // this method will check a units health to see if it below 10 and if it is there will be a 50% chance of that unit changing alleigance to the other team and the unit will gain a small amount of health as compensation for changing team
                    {
                        int teamChange = r.Next(0, 2);
                        if (teamChange == 0)
                        {
                            if (m.faction == 1)
                            {
                                m.faction = 0;
                                m.health  = m.health + 5;
                            }
                            else
                            {
                                m.faction = 1;
                                m.health  = m.health + 5;
                            }
                        }
                    }
                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinAttackRange(e))
                            {
                                u.combatWithUnit(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = "X";

                    if (m.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (m.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(m.Xpos, m.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(WizardUnit))
            {
                WizardUnit w = (WizardUnit)u;
                if (w.health > 1)
                {
                    if (w.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((WizardUnit)u).NewPos(Direction.North); break;

                        case 1: ((WizardUnit)u).NewPos(Direction.East); break;

                        case 2: ((WizardUnit)u).NewPos(Direction.South); break;

                        case 3: ((WizardUnit)u).NewPos(Direction.West); break;
                        }
                    }

                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinAttackRange(e))
                            {
                                u.combatWithUnit(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.UnitDistance(map.Units);
                            w.NewPos(w.Directionto(c));
                        }
                    }
                }
                else
                {
                    w.symbol = "X";
                    if (w.faction == 1)
                    {
                        GameObject dup = Instantiate(RedDeath, new Vector2(w.Xpos, w.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else if (w.faction == 0)
                    {
                        GameObject dup = Instantiate(BlueDeath, new Vector2(w.Xpos, w.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                    else
                    {
                        GameObject dup = Instantiate(NeutralDeath, new Vector2(w.Xpos, w.Ypos), Quaternion.identity);
                        dup.transform.parent = transform;
                    }
                }
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(ResourceBuilding))
            {
                ResourceBuilding rb = (ResourceBuilding)b;
                rb.ResourceGenerate();
            }
        }

        foreach (Building b in map.Buildings)
        {
            if (b.GetType() == typeof(FactoryBuilding))
            {
                FactoryBuilding fb = (FactoryBuilding)b;
            }
        }
        #region SpawningOfUnits
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeleeUnit))
            {
                MeleeUnit mu = (MeleeUnit)u;
                if (mu.symbol == "X")
                {
                    int             faction = mu.faction;
                    int             rand    = r.Next(0, 5);
                    FactoryBuilding fb      = (FactoryBuilding)map.Buildings[rand];
                    fb.Spawner(20, 20, faction);
                }
            }
        }

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(RangedUnit))
            {
                RangedUnit mu = (RangedUnit)u;
                if (mu.symbol == "X")
                {
                    int             faction = mu.faction;
                    int             rand    = r.Next(0, 5);
                    FactoryBuilding fb      = (FactoryBuilding)map.Buildings[rand];
                    fb.Spawner(20, 20, faction);
                }
            }
        }
        #endregion
    }