예제 #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Window.AllowUserResizing = true;
            IsMouseVisible           = true;

            // TODO: Add your initialization logic here
            base.Initialize();

            int genEnd = map.GetLength(0);

            loadMap();
            DiamondSquareTerrainGenerator terrainGenerator = new DiamondSquareTerrainGenerator(10, new Random());

            terrainGenerator.generate(map, 0, genEnd);

            GrassTerrainGenerator grassTerrainGenerator = new GrassTerrainGenerator();

            grassTerrainGenerator.generate(map, 0, genEnd);

            //mapCacher = new ArrayMapCacher(map.GetLength(0), map.GetLength(1), map);
            player = new Player(playerSprite, new Vector2(60, 200));
            entities.Add(player);

            keyManager = new KeysManager(player);


            keyManager.registerKeybind(Keys.F, new SaveKeybind(mapLoader));
            keyManager.registerKeybind(Keys.R, new NewMapKeybind(mapLoader, this));

            //spawnSnake();

            camera = new Camera(map, entities, this, new ArrayMapCacher(), GraphicsDevice, spriteBatch, player, graphics, tileTextureMap, frameCounter, spriteFont);
        }
예제 #2
0
        public void testTerrainHeightMapMatch()
        {
            Map map = new Map(256, 200, "testMap");

            int    seed    = 123123123;
            Random random1 = new Random(seed);
            DiamondSquareTerrainGenerator terrainGenerator = new DiamondSquareTerrainGenerator(5, random1);

            terrainGenerator.generate(map, 0, 400);


            Random random2 = new Random(seed);

            terrainGenerator = new DiamondSquareTerrainGenerator(5, random2);
            int[] sameHeightMap = terrainGenerator.generateHeightMap(401, random2.Next(50, 100), random2.Next(50, 100));

            bool sameHeights = true;

            for (int i = 0; i < map.GetLength(0); i++)
            {
                int height = sameHeightMap[i];

                if (!map[i, height].filled)
                {
                    sameHeights = false;
                }

                if (map[i, height - 1].filled)
                {
                    sameHeights = false;
                }
            }

            Assert.IsTrue(sameHeights);
        }