예제 #1
0
        public void CreateGameBoard()
        {
            // Specify the Width and Heights for each of our tiles
            tileWidth  = this.gameViewWidth / this.gridCellSize;
            tileHeight = this.gameViewHeight / this.gridCellSize;

            // Specify our tile width and tile centre values
            float tileCenterX = tileWidth / 2;
            float tileCenterY = tileHeight / 2;

            // Initialise our tile counter value
            int counter = 65;

            // Build our game board with images from our array
            for (int row = 0; row < gridCellSize; row++)
            {
                for (int column = 0; column < gridCellSize; column++)
                {
                    // Create a new tile by instantiating a new instance of our GameTile class
                    GameTile tile = new GameTile(row, column);
                    tile.Frame  = new CGRect(0, 0, tileWidth, tileHeight);
                    tile.Image  = tile.DrawTileText(UIImage.FromFile("game_tile.png"), Convert.ToChar(counter).ToString(), UIColor.White, 65);
                    tile.Center = new CGPoint(tileCenterX, tileCenterY);
                    tile.UserInteractionEnabled = true;

                    // Store our Tile Coordinates within our ArrayList object
                    GameTileCoords.Add(new CGPoint(tileCenterX, tileCenterY));

                    // Add the tile to our Tile Images
                    gameTileImagesArray.Add(tile);
                    gameBoardView.AddSubview(tile);

                    // Increment to the next tile position and image within array.
                    tileCenterX = tileCenterX + tileWidth;
                    counter     = counter + 1;
                }

                tileCenterX = tileWidth / 2;
                tileCenterY = tileCenterY + tileHeight;
            }
            // Remove the last tile from the gameBoard and our gameTileImagesArray
            var emptyTile = gameTileImagesArray[gameTileImagesArray.Count - 1];

            emptyTile.RemoveFromSuperview();
            gameTileImagesArray.RemoveAt(gameTileImagesArray.Count - 1);
        }