Beispiel #1
0
    private void UpdateMap()
    {
        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeeleeUnit))
            {
                MeeleeUnit m = (MeeleeUnit)u;
                if (m.health > 1)
                {
                    if (m.health < 25)
                    {
                        switch (r.Next(0, 4))
                        {
                        case 0: ((MeeleeUnit)u).NewPos(Direction.North); break;

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

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

                        case 3: ((MeeleeUnit)u).NewPos(Direction.West); break;
                        }
                    }
                    else if (m.health < 10)
                    {
                        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.withinRange(e))
                            {
                                u.combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.distance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = body;
                }
            }
        }
        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)
                    {
                        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.withinRange(e))
                            {
                                u.combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.distance(map.Units);
                            m.NewPos(m.Directionto(c));
                        }
                    }
                }
                else
                {
                    m.symbol = body;
                }
            }
        }

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

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

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

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

                    else
                    {
                        bool inCombat = false;
                        foreach (Unit e in map.Units)
                        {
                            if (u.withinRange(e))
                            {
                                u.combat(e);
                                inCombat = true;
                            }
                        }
                        if (!inCombat)
                        {
                            Unit c = u.distance(map.Units);
                            w.NewPos(w.Directionto(c));
                        }
                    }
                }
                else
                {
                    w.symbol = body;
                }
            }
        }

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

        foreach (Unit u in map.Units)
        {
            if (u.GetType() == typeof(MeeleeUnit))
            {
                MeeleeUnit mu = (MeeleeUnit)u;
                if (mu.symbol == body)
                {
                    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 == body)
                {
                    int             faction = mu.faction;
                    int             rand    = r.Next(0, 5);
                    FactoryBuilding fb      = (FactoryBuilding)map.Buildings[rand];
                    fb.Spawner(20, 20, faction);
                }
            }
        }
    }
Beispiel #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
    }