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 = "X";
                    }
                }
            }
            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 = "X";
                    }
                }
            }

            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 = "X";
                    }
                }
            }

            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 == "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);
                    }
                }
            }
        }