private void MakeTiles() { if (effects_enabled) { audioManager.PlaySoundEffect(SoundEffect.Standard); } // Clean up the GridLayout mainLayout.RemoveAllViews(); // Calculate the width/height of the tiles tileWidth = (int)(gameViewWidth / gridSize); // Initialize ArrayLists tilesArray = new ArrayList(); coordsArray = PuzzleMixer.GetPuzzleArray((gridSize * gridSize), gridSize, NumChanges, true, rnd); board = CreateBoard(); int tileIndex = 0; for (int row = 0; row < gridSize; row++) { for (int col = 0; col < gridSize; col++) { if (coordsArray[tileIndex] == 0) // this is the empty tile { emptySpot = new Point(row, col); board[row][col] = gridSize * gridSize - 1; tileIndex++; continue; } board[row][col] = coordsArray[tileIndex] - 1; // Create the tile (TextTileView) TextTileView textTile = new TextTileView(this) { // Set the tile with the layout parameter LayoutParameters = GetTileLayoutParams(row, col), TextSize = 40, Text = coordsArray[tileIndex].ToString(), Gravity = GravityFlags.Center, PositionX = row, PositionY = col }; textTile.SetBackgroundColor(Color.Green); textTile.SetTextColor(Color.Black); // Subscribe to the tile's Touch event handler textTile.Touch += TileTouched; // Add the tile to the game's grid layout mainLayout.AddView(textTile); // Keep the tile and its coordenate in the arrays tilesArray.Add(textTile); tileIndex++; } } ResetSolver(); NumberOfMoves = 0; movesTextView.Text = string.Format("Moves: {0}", 0); }
private void MakeTiles() { // Clean up the GridLayout mainLayout.RemoveAllViews(); // Calculate the width/height of the tiles tileWidth = gameViewWidth / 4; // Initialize ArrayLists tilesArray = new ArrayList(); coordsArray = new ArrayList(); // Counter for the tile numbers int count = 1; for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { // Create the tile (TextTileView) TextTileView textTile = new TextTileView(this); // Set the tile with the layout parameter textTile.LayoutParameters = GetTileLayoutParams(row, col); textTile.SetBackgroundColor(Color.Green); textTile.Text = count++.ToString(); textTile.SetTextColor(Color.Black); textTile.TextSize = 40; textTile.Gravity = GravityFlags.Center; // Subscribe to the tile's Touch event handler textTile.Touch += TileTouched; // Add the tile to the game's grid layout mainLayout.AddView(textTile); // Keep the tile and its coordenate in the arrays tilesArray.Add(textTile); coordsArray.Add(new Point(row, col)); } } mainLayout.RemoveView((TextTileView)tilesArray[15]); tilesArray.RemoveAt(15); Randomize(); }