public override string ToString() { string boardStr = ""; string indexRow = " "; string brRow = " "; for (int colIndex = 0; colIndex < colCount; colIndex++) { if (colIndex < 10) { indexRow += "0" + colIndex + " "; } else { indexRow += colIndex + " "; } brRow += "---"; } boardStr += indexRow + "\n"; boardStr += brRow + "\n"; for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { string rowStr = ""; if (rowIndex < 10) { rowStr += "0" + rowIndex + "|"; } else { rowStr += rowIndex + "|"; } for (int colIndex = 0; colIndex < colCount; colIndex++) { TileZeroTile tile = tileArray[rowIndex, colIndex]; if (tile == null) { rowStr += "-- "; } else { rowStr += tile.ToString() + " "; } } boardStr += rowStr + "\n"; } return(boardStr); }
// [2016.12.01] // [SC] place active player's tile on a board public void placePlayerTileOnBoard(int playerIndex) { if (!activeGameFlag) { return; } if (playerIndex != activePlayerIndex) { Cfg.log("It is not your turn!"); return; } Player activePlayer = players[activePlayerIndex]; // [SC] check if player can put tiles on a board if (!activePlayer.getCanMove()) { Cfg.log("Cannot move a tile after dropping a tile!"); // [TODO] return; } // [SC] check if board position is selected if (!isSelected()) { Cfg.log("Select a board position at first!"); // [TODO] return; } // [SC] check if player tile is selected if (!activePlayer.isTileSelected()) { Cfg.log("Select a tile at first!"); // [TODO] return; } TileZeroTile tile = activePlayer.getSelectedTile(); int result = putTileOnBoard(selectedRowIndex, selectedColIndex, tile, true); if (result != Cfg.NONE) { Cfg.log(String.Format(" Put tile {0} at position {1}-{2} for {3} points.", tile.ToString(), selectedRowIndex, selectedColIndex, result)); // [SC] increase player's score activePlayer.increaseScore(result); // [SC] remove the tile from the player and reset player selection activePlayer.removeSelectedTile(); // [SC] disable mismatching tiles activePlayer.disableMismatchedTiles(tile.getColorIndex(), tile.getShapeIndex()); // [SC] prevent the player from dropping tiles in the same turn activePlayer.setCanDrop(false); // [SC] reset board selection resetSelected(); } }
// [2016.12.01] // [SC] a function for dropping a tile public void dropPlayerTile(int playerIndex) { if (!activeGameFlag) { return; } if (playerIndex != activePlayerIndex) { Cfg.log("It is not your turn!"); return; } Player activePlayer = players[activePlayerIndex]; // [SC] check if player drop tiles if (!activePlayer.getCanDrop()) { Cfg.log("Cannot drop a tile after putting a tile on a board!"); // [TODO] return; } // [SC] check if bag has tiles if (tileBag.Count == 0) { Cfg.log("Cannot drop a tile! The bag is empty."); // [TODO] return; } // [SC] check if player tile is selected if (!activePlayer.isTileSelected()) { Cfg.log("Select a tile at first!"); // [TODO] return; } TileZeroTile tile = activePlayer.getSelectedTile(); // [SC] make sure that the tile being dropped is not a replacement tile of previously dropped tile if (!tile.getCanDrop()) { Cfg.log("Cannot drop a replacement tile!"); return; } foreach (TileZeroTile newTile in tileBag) { // [SC] make sure that the new tile does not have the same features as the dropped tile if (newTile.getColorIndex() == tile.getColorIndex() && newTile.getShapeIndex() == tile.getShapeIndex()) { continue; } Cfg.log(String.Format(" Dropped tile {0}. Replaced with tile {1}.", tile.ToString(), newTile.ToString())); // [SC] remove the dropped tile from player's stack activePlayer.removeTile(tile); // [SC] add the dropped tile into the bag tileBag.Add(tile); // [SC] remove the new tile from the bag tileBag.Remove(newTile); // [SC] add the new tile to player's stack activePlayer.addTile(newTile); // [SC] make sure that the new tile cannot be dropped in the same turn newTile.setCanDrop(false); // [SC] shuffle the bag tileBag.Shuffle(); // [SC] prevent the player from moving tiles into the board activePlayer.setCanMove(false); break; } }