예제 #1
0
파일: Field.cs 프로젝트: yolomachine/Match3
        private void Generate()
        {
            TileArray = new Tile[Settings.ColsCount, Settings.RowsCount];
            for (int i = 0; i < Settings.ColsCount; ++i)
            {
                for (int j = 0; j < Settings.RowsCount; ++j)
                {
                    Tile tile = RandomTile();
                    tile.LoadContent();
                    xOffset         = xOffset ?? (Settings.ViewportWidth - (Settings.ColsCount - 1) * tile.Width) / 2;
                    yOffset         = yOffset ?? (Settings.ViewportHeight - (Settings.RowsCount - 1) * tile.Height) / 2;
                    tile.Position   = new Vector2((float)xOffset + i * tile.Width, (float)yOffset + j * tile.Height);
                    tile.Col        = i;
                    tile.Row        = j;
                    TileArray[i, j] = tile;
                }
            }

            List <List <Tile> > blocks;

            while ((blocks = FindBlocks()).Count > 0)
            {
                foreach (List <Tile> block in blocks)
                {
                    foreach (Tile tile in block)
                    {
                        Replace(ref TileArray[tile.Col, tile.Row], RandomTile());
                    }
                }
            }
        }
예제 #2
0
파일: Field.cs 프로젝트: yolomachine/Match3
        private void Replace(ref Tile oldTile, Tile newTile)
        {
            int     row      = oldTile.Row;
            int     col      = oldTile.Col;
            Vector2 position = oldTile.Position;

            oldTile          = newTile;
            oldTile.Row      = row;
            oldTile.Col      = col;
            oldTile.Position = position;
            oldTile.LoadContent();
        }