Пример #1
0
        /// <summary>
        /// Returns vertical boundaries for rendering map blocks around center block.
        /// [minY,maxY].
        /// </summary>
        /// <param name="map">Map.</param>
        /// <param name="centerBlock">Center block.</param>
        /// <param name="verticalBlockCount">NUmber of blocks to be rendered in vertical direction.</param>
        /// <returns>Array with two items. First is the Y coordinate of the top block to be rendered, second is the Y coordinate of the bottom block to be rendered.</returns>
        private int[] GetYBoundaries(MapBlock[,] map, MapBlock centerBlock, int verticalBlockCount)
        {
            int[] boundaries = new int[2];

            // number of blocks on each side from center block
            int numOfTopBlocks    = verticalBlockCount / 2;
            int numOfBottomBlocks = (int)Math.Ceiling(verticalBlockCount / 2.0) - 1;

            // too close to the top border
            if (centerBlock.Y - numOfTopBlocks < 0)
            {
                boundaries[0] = 0;
                boundaries[1] = verticalBlockCount - 1;


                // too close to the bottom border
            }
            else if (centerBlock.Y + numOfBottomBlocks >= map.GetLength(1))
            {
                boundaries[0] = map.GetLength(1) - verticalBlockCount;
                boundaries[1] = map.GetLength(1) - 1;


                // ok, somewhere in the middle
            }
            else
            {
                boundaries[0] = centerBlock.Y - numOfTopBlocks;
                boundaries[1] = centerBlock.Y + numOfBottomBlocks;
            }

            return(boundaries);
        }
Пример #2
0
        /// <summary>
        /// Returns horizontal boundaries for rendering map blocks around center block.
        /// [minX,maxX].
        /// </summary>
        /// <param name="map">Map.</param>
        /// <param name="centerBlock">Center blocks.</param>
        /// <param name="horizontalBlockCount">Number of blocks to be rendered in horizontal direction.</param>
        /// <returns>Array with two items. First is the X coordinate of the leftmost block to be rendered, second is the X coordinate of the rightmost block to be rendered.</returns>
        private int[] GetXBoundaries(MapBlock[,] map, MapBlock centerBlock, int horizontalBlockCount)
        {
            int[] boundaries = new int[2];

            // number of blocks on each side from center block
            int numOfLeftBlocks  = horizontalBlockCount / 2;
            int numOfRightBlocks = (int)Math.Ceiling(horizontalBlockCount / 2.0) - 1;

            // too close to the right border
            if (centerBlock.X + numOfRightBlocks >= map.GetLength(0))
            {
                boundaries[1] = map.GetLength(0) - 1;
                boundaries[0] = map.GetLength(0) - horizontalBlockCount;

                // too close to the left border
            }
            else if (centerBlock.X - numOfLeftBlocks < 0)
            {
                boundaries[0] = 0;
                boundaries[1] = horizontalBlockCount - 1;

                // ok, somewhere in the middle
            }
            else
            {
                boundaries[0] = centerBlock.X - numOfLeftBlocks;
                boundaries[1] = centerBlock.X + numOfRightBlocks;
            }

            return(boundaries);
        }
Пример #3
0
        /// <summary>
        /// Initializes this map with given values and assigns parentMap to each MapBlock.
        /// </summary>
        /// <param name="grid">Map, dimensions should match with width and height.</param>
        public void InitializeMap(MapBlock[,] grid)
        {
            Width  = grid.GetLength(0);
            Height = grid.GetLength(1);
            Grid   = grid;

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    grid[i, j].AssignToMap(this);
                }
            }
        }
Пример #4
0
    //public override void Build()
    //{
    //    base.Build();
        //colliders[0] = new GameObject();
        //colliders[0].transform.SetParent(transform);
        //colliders[0].AddComponent<BoxCollider>();
        //colliders[0].GetComponent<BoxCollider>().isTrigger = true;
        //colliders[0].GetComponent<BoxCollider>().size = new Vector3(totalSizeX, 0.5f, 10f);
        //colliders[0].GetComponent<BoxCollider>().center = new Vector3(0, 0, totalSizeZ / 2 + 5f);
        //colliders[0].AddComponent<UP>();
        //colliders[0].layer = 0;

        //colliders[1] = new GameObject();
        //colliders[1].transform.SetParent(transform);
        //colliders[1].AddComponent<BoxCollider>();
        //colliders[1].GetComponent<BoxCollider>().isTrigger = true;
        //colliders[1].GetComponent<BoxCollider>().size = new Vector3(totalSizeX, 0.5f, 10f);
        //colliders[1].GetComponent<BoxCollider>().center = new Vector3(0, 0, -totalSizeZ / 2 - 5f -1);
        //colliders[1].AddComponent<DOWN>();
        //colliders[1].layer = 0;

        //colliders[2] = new GameObject();
        //colliders[2].transform.SetParent(transform);
        //colliders[2].AddComponent<BoxCollider>();
        //colliders[2].GetComponent<BoxCollider>().isTrigger = true;
        //colliders[2].GetComponent<BoxCollider>().size = new Vector3(10f, 0.5f, totalSizeZ);
        //colliders[2].GetComponent<BoxCollider>().center = new Vector3(totalSizeX / 2 + 5f, 0, 0);
        //colliders[2].AddComponent<RIGHT>();
        //colliders[2].layer = 0;

        //colliders[3] = new GameObject();
        //colliders[3].transform.SetParent(transform);
        //colliders[3].AddComponent<BoxCollider>();
        //colliders[3].GetComponent<BoxCollider>().isTrigger = true;
        //colliders[3].GetComponent<BoxCollider>().size = new Vector3(10f, 0.5f, totalSizeZ);
        //colliders[3].GetComponent<BoxCollider>().center = new Vector3(-totalSizeX / 2 - 5f - 1, 0);
        //colliders[3].AddComponent<LEFT>();
        //colliders[3].layer = 0;
    //}

    // Set a block properties with this X and Y coord
    public void setBlock(int X, int Y, ref MapBlock block)
    {
        if (map == null)
            return;
        if (map.GetLength(0) <= Y || map.GetLength(1) <= X)
            return;
        map[Y, X] = block;
        Transform block_transform = blocks[X + Y * map.GetLength(1)].transform.GetChild(0);
        block_transform.GetChild(0).gameObject.SetActive(block.Food > 0);
        block_transform.GetChild(1).gameObject.SetActive(block.Lenemate > 0);
        block_transform.GetChild(2).gameObject.SetActive(block.Deraumere > 0);
        block_transform.GetChild(3).gameObject.SetActive(block.Sibur > 0);
        block_transform.GetChild(4).gameObject.SetActive(block.Mendiane > 0);
        block_transform.GetChild(5).gameObject.SetActive(block.Phiras > 0);
        block_transform.GetChild(6).gameObject.SetActive(block.Thystame > 0);
    }
Пример #5
0
        public void TestSimpleMapGeneratorSeed()
        {
            IMapGenerator simpleMapGenerator = MapGeneratorFactory.CreateSimpleMapGenerator();
            int           w    = 5;
            int           h    = 10;
            int           seed = 87452;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            MapBlock[,] grid  = simpleMapGenerator.GenerateGrid(w, h, seed);
            MapBlock[,] grid2 = simpleMapGenerator.GenerateGrid(w, h, seed);

            Assert.IsNotNull(grid, "Grid 1 is null!");
            Assert.IsNotNull(grid2, "Grid 2 is null!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            Assert.AreEqual(w, grid2.GetLength(0), "Wrong width of map grid 2!");
            Assert.AreEqual(h, grid2.GetLength(1), "Wrong height of map grid 2!");

            // all map block should be same
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int entrances = 0;
                    foreach (Direction dir in allDirections)
                    {
                        Assert.AreEqual(grid[i, j].EntranceInDirection(dir).Exists(), grid2[i, j].EntranceInDirection(dir).Exists(), $"Map block at position [{i},{j}] has different entrance in direction {dir}.");
                        if (grid[i, j].EntranceInDirection(dir).Exists())
                        {
                            entrances++;
                        }
                    }

                    Assert.IsTrue(entrances > 0, $"Block at [{i},{j}] has no entrance!");
                }
            }
        }
Пример #6
0
        public void TestSimpleMapGenerator()
        {
            IMapGenerator simpleMapGenerator = MapGeneratorFactory.CreateSimpleMapGenerator();
            int           w = 5;
            int           h = 10;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            Map map = simpleMapGenerator.GenerateMap(w, h, IMapGeneratorConstants.NO_SEED);

            MapBlock[,] grid = map.Grid;

            Assert.IsNotNull(grid, "Null grid returned!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            Assert.IsNotNull(map.WinningBlock, "Winning block is null!");
            Assert.AreEqual((w - 1) / 2, map.WinningBlock.X, "Wrong X coordinate of winning block.");
            Assert.AreEqual((h - 1) / 2, map.WinningBlock.Y, "Wrong Y coordinate of winning block.");

            // test that no map block has all entrances closed
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int entrances = 0;
                    foreach (Direction dir in allDirections)
                    {
                        if (grid[i, j].EntranceInDirection(dir).Exists())
                        {
                            entrances++;
                        }
                    }

                    Assert.IsTrue(entrances > 0, $"Block at [{i},{j}] has no entrance!");
                }
            }
        }
Пример #7
0
        public void TestOpenMapGenerator()
        {
            IMapGenerator openMapGenerator = MapGeneratorFactory.CreateOpenMapGenerator();
            int           w = 10;
            int           h = 15;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            MapBlock[,] grid = openMapGenerator.GenerateGrid(w, h, 0);
            Assert.IsNotNull(grid, "Null grid returned!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }

            Map map = openMapGenerator.GenerateMap(w, h, 0);

            Assert.IsNotNull(map, "Null map returned!");
            Assert.AreEqual(w, map.Width, "Wrong map width!");
            Assert.AreEqual(h, map.Height, "Wrong map height!");
            MapBlock[,] grid2 = map.Grid;
            Assert.AreEqual(grid.GetLength(0), grid.GetLength(0), "Widths of grids don't match!");
            Assert.AreEqual(grid.GetLength(1), grid.GetLength(1), "Widths of grids don't match!");
            Assert.IsNotNull(map.WinningBlock, "Winning block is null!");
            Assert.AreEqual((w - 1) / 2, map.WinningBlock.X, "Wrong X coordinate of winning block.");
            Assert.AreEqual((h - 1) / 2, map.WinningBlock.Y, "Wrong Y coordinate of winning block.");

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid2[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }
        }