Ejemplo n.º 1
0
        public IEnumerator Init(Grid grid, LevelColorScheme levelColorScheme)
        {
            if (Grid != null)
            {
                Debug.Log("Level is already created!");
                yield break;
            }

            Grid = grid;

            TileHolders = new TileHolder[Grid.Size];

            var start = this.transform.position;
            var wait  = new WaitForSeconds(timeOnRowCreate);

            for (int i = 0; i < Grid.SizeX; i++)
            {
                for (int j = 0; j < Grid.SizeY; j++)
                {
                    TileHolders[Grid.CoordinateToIndex(i, j)] = Instantiate <TileHolder>(tilePrefab, transform);
                    TileHolders[Grid.CoordinateToIndex(i, j)].transform.position = new Vector3(i, 0, j) * spacing;
                    TileHolders[Grid.CoordinateToIndex(i, j)].Init(Grid[i, j], this, levelColorScheme);
                }

                yield return(wait);
            }
        }
Ejemplo n.º 2
0
        public void GridCoordinateToIndexReturnCorrectValue()
        {
            var grid = new Grid(2, 3);

            int index = grid.CoordinateToIndex(1, 0);

            Assert.AreEqual(3, index);
        }
Ejemplo n.º 3
0
        public float UpdateCorners()
        {
            var index00 = Grid.CoordinateToIndex(0, 0);
            var index01 = Grid.CoordinateToIndex(0, Grid.SizeY - 1);
            var index10 = Grid.CoordinateToIndex(Grid.SizeX - 1, 0);
            var index11 = Grid.CoordinateToIndex(Grid.SizeX - 1, Grid.SizeY - 1);

            corner00.position = TileHolders[index00].transform.position;
            corner01.position = TileHolders[index01].transform.position;
            corner10.position = TileHolders[index10].transform.position;
            corner11.position = TileHolders[index11].transform.position;
            return(Vector3.Distance(corner00.position, corner11.position));
        }