Exemplo n.º 1
0
        public World(int width, int height)
        {
            // Create map
            WidthWorld  = width;
            HeightWorld = height;

            Fields = new Field[WidthWorld, HeightWorld];

            for (var y = 0; y < HeightWorld; y++)
            {
                for (var x = 0; x < WidthWorld; x++)
                {
                    Fields[y, x] = new Field(x, y);
                }
            }

            //Create first anthill


            FactoryAnthill antFactory = new FactoryAnthill(Fields, width, height);
            var            antHill    = (Anthill)antFactory.CreateEnvironment();

            antHill.LoadEnvironment(antFactory);


            ListAnthill = new List <Anthill>
            {
                antHill,
            };

            _lastTimeAddFood = -10000;

            /*
             * System.Threading.Timer timer = null;
             * timer = new System.Threading.Timer((obj) =>
             * {
             *
             *  FactoryAnthill antFactory2 = new FactoryAnthill(Fields, width, height);
             *  var antHill2 = (Anthill)antFactory.CreateEnvironment();
             *  antHill2.LoadEnvironment(antFactory2);
             *  ListAnthill.Add(antHill2);
             *
             *  timer.Dispose();
             * },
             *          null, 1000, System.Threading.Timeout.Infinite); */
        }
Exemplo n.º 2
0
        public void CreateAnthill(Anthill home, World world)
        {
            var Queens = home.ListCharacter.Where(c => c.GetType() == typeof(AntQueen)).ToList();

            if (Queens.Count > 1 && Queens.Last() == this)
            {
                // limit max 3 anthill
                if (world.ListAnthill.Count <= 3)
                {
                    home.ListCharacter.Remove(this);
                    _factoryAnthill = new FactoryAnthill(world.Fields, home.WidthWorld, home.HeightWorld);
                    var newAnthill = (Anthill)_factoryAnthill.CreateEnvironment();
                    newAnthill.LoadEnvironment(_factoryAnthill);
                    world.ListAnthill.Add(newAnthill);
                }
                else
                {
                    home.ListCharacter.Remove(this);
                    this.Life = 0;
                }
            }
        }