public static GameState Start() { PoweredTile[,] board = new PoweredTile[2, 2]; SpawnTile(board); SpawnTile(board); return(GetGameState(board)); }
private static PoweredTile[,] GetBoard(GameState state) { PoweredTile[,] board = new PoweredTile[state.GetSize(), state.GetSize()]; foreach (GameTile tile in state) { GameTileState tileState = state.GetTileState(tile); board[tileState.GetRow(), tileState.GetColumn()] = new PoweredTile(tile, tileState.GetPower()); } return(board); }
private static PoweredTile[,] Promote(PoweredTile[,] board) { PoweredTile[,] promoted = new PoweredTile[board.GetLength(0) + 1, board.GetLength(0) + 1]; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(0); j++) { promoted[i, j] = board[i, j]; } } return(promoted); }
private static PoweredTile[,] RotateClockwise(PoweredTile[,] board) { PoweredTile[,] rotated = new PoweredTile[board.GetLength(0), board.GetLength(0)]; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(0); j++) { rotated[board.GetLength(0) - 1 - j, i] = board[i, j]; } } return(rotated); }
private static bool FloatTiles(PoweredTile[,] board, IDictionary <GameTile, GameTileState> oldTileStates) { bool floated = false; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(0); j++) { PoweredTile current = board[i, j]; if (current != null) { int k; for (k = i; k > 0; k--) { PoweredTile upper = board[k - 1, j]; if (upper != null) { if (!upper.upped && upper.power == current.power) { current.power++; current.upped = true; oldTileStates[upper.tile] = new GameTileState(upper.power, k - 1, j); k--; } break; } } if (i != k) { board[i, j] = null; board[k, j] = current; floated = true; } } } } return(floated); }
private static int GetHighestPower(PoweredTile[,] board) { int max = int.MinValue; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(0); j++) { PoweredTile current = board[i, j]; if (current != null && current.power > max) { max = current.power; } } } return(max); }
private static GameState GetGameState(PoweredTile[,] board) { Dictionary <GameTile, GameTileState> tileStates = new Dictionary <GameTile, GameTileState>(); for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(0); j++) { PoweredTile current = board[i, j]; if (current != null) { tileStates[current.tile] = new GameTileState(current.power, i, j); } } } return(new GameState(board.GetLength(0), tileStates)); }