Example #1
0
        public Cage(CageType type, Vector2 pos, Game game, Balancing balance, bool preview)
        {
            List <Vector2> wallpositions = type.WallPositions;

            _type    = type;
            State    = preview ? DisplayState.Preview : DisplayState.Normal;
            _game    = game;
            _balance = balance;
            _world   = game.World;

            _game.Cages.Add(this);

            _pooList     = new List <PooEntity>();
            _foodList    = new List <FoodEntity>();
            _animalList  = new List <AnimalEntity>();
            _speciesList = new List <Species>();
            _walls       = new List <CageWallEntity>();
            _visitorList = new List <VisitorEntity>();

            for (int i = 0; i < wallpositions.Count; i++)
            {
                CageWallEntity wall    = new CageWallEntity(this);
                Vector2        wallpos = pos + wallpositions[i];
                Tile           tile    = _world[wallpos];
                tile.Entity = wall;
                _walls.Add(wall);
            }

            RecomputeEnclosedTiles(pos);
            RecomputeSurroundingTiles(pos);

            foreach (var tile in EnclosedTiles)
            {
                tile.Cage = this;
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WindowWidth  = 100;
            Console.WindowHeight = 60;

            var data    = new DataManager();
            var balance = new Balancing();
            var game    = new Game(Console.WindowWidth - 22, Console.WindowHeight - 3, new Vector2(0, 3), balance, data);
            var menu    = new ActionMenu(new Vector2(Console.WindowWidth - 22, 0), 22, 18);
            var menu2   = new InfoBar(game, new Vector2(0, 0), Console.WindowWidth - 22, 3);
            var menu3   = new CageMenu(new Vector2(Console.WindowWidth - 22, 18), 22, Console.WindowHeight - 18, game);
            var watch   = new Stopwatch();
            var key     = new KeyPressManager(Console.WindowWidth - 20, Console.WindowHeight - 3, game);

            double menuUpdateInterval      = 5;
            double timeSinceLastMenuUpdate = menuUpdateInterval;

            // Test code

            var cageType = CageType.ReadFromFile("../../../data/cages/cross.cage");

            var species = new Species("Cow");

            species.Symbol    = 'c';
            species.PooPeriod = 2;

            var cage = new Cage(cageType, new Vector2(3, 3), game, balance, false);

            game.Cages.SelectedCage = cage;

            var cow1 = new AnimalEntity(species);
            var cow2 = new AnimalEntity(species);

            cow1.Tile = cage.EnclosedTiles[0];
            cow2.Tile = cage.EnclosedTiles[2];

            // End of test code

            watch.Start();

            while (true)
            {
                double dt = 0.001 * (double)watch.ElapsedMilliseconds;
                watch.Restart();

                game.Update(dt);
                ///<summary>
                ///key input handling
                ///</summary>
                //key.KeyInput();

                game.World.Draw();

                timeSinceLastMenuUpdate += dt;
                if (timeSinceLastMenuUpdate >= menuUpdateInterval)
                {
                    menu.Draw();
                    menu2.Draw();
                    menu3.Draw();
                    timeSinceLastMenuUpdate = 0;
                }

                // This is to avoid an 'empty' line at the bottom of the screen
                Console.SetCursorPosition(0, 0);

                if (1.0 / _fps * 0.001 > dt)
                {
                    Thread.Sleep(Math.Max(0, (int)((long)(1.0 / _fps * 1000.0) - watch.ElapsedMilliseconds)));
                }
            }
        }