public void RotateCw() { Cell[,] tmp = new Cell[ROW_SIZE, COL_SIZE]; for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { tmp[i, j] = cells[j, COL_SIZE - i - 1]; } } /* for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { cells[i, j] = tmp[i, j]; } } * */ cells = tmp; }
/// <summary> /// copies board and stores /// </summary> /// <param name="board">연쇄 전 pile의 board</param> public void SetOriginalBoard(Cell[,] board) { lock (thisLock) { copiedBoard = (Cell[,])board.Clone(); } }
public void RotateCcw() { Cell[,] tmp = new Cell[ROW_SIZE, COL_SIZE]; for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { tmp[j, COL_SIZE - i - 1] = cells[i, j]; } } //TODO: cells = tmp;라고 하면 안되는 이유가 뭐야? 되지 않나? 어쩌피 레퍼런스 가리키고 있는거 아닌가? /* for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { cells[i, j] = tmp[i, j]; } } * */ cells = tmp; }
private void PutBlock(int row, int col, Block block, Cell[,] board) { for (int i = 0; i < Block.ROW_SIZE; i++) { for (int j = 0; j < Block.COL_SIZE; j++) { if (!(block.IsEmpty(i,j))) { board[row + i, col + j] = block[i, j]; } } } }
private bool isCellCollision(int row, int col, Cell cell) { // 빈 칸이면 무조건 안전합니다. 항상 맨 처음 비교합니다. if (cell.IsEmpty) return false; // always safe if (col < 0) return true; // should not happen if (row < 0) return true; // too low if (col >= COL_SIZE) return true; // should not happen if (row >= ROW_SIZE + 3) return true; // too high if (!IsCellEmpty(row,col)) return true; // if board cell is not empty, it collides return false; }
private void FloodFill(int row, int col, bool[,] visit, CellColor par, Cell[,] board) { if (row < 0 || row >= ROW_SIZE + 3) return; if (col < 0 || col >= COL_SIZE) return; if (visit[row, col]) return; if (board[row, col].IsEmpty) return; if (board[row, col].Color != par) return; // in same color visit[row, col] = true; if (row + 1 < ROW_SIZE + 3) FloodFill(row + 1, col, visit, board[row + 1, col].Color,board); // connect upper FloodFill(row - 1, col, visit, par, board); FloodFill(row, col + 1, visit, par, board); FloodFill(row, col - 1, visit, par, board); }
private bool CalcDrop(List<Animation.Drop> dropCells, Cell[,] board) { //(1) calculate drops bool retVal = false; bool[,] visit = new bool[ROW_SIZE + 3, COL_SIZE];//flood fill color array bool flgDown; // flag for gravity down do { flgDown = false; for (int i = 0; i < ROW_SIZE + 3; i++) { for (int j = 0; j < COL_SIZE; j++) { visit[i, j] = false; } } for (int j = 0; j < COL_SIZE; j++) { FloodFill(0, j, visit, board[0, j].Color, board); } for (int i = 1; i < ROW_SIZE + 3; i++) { for (int j = 0; j < COL_SIZE; j++) { if (visit[i, j] == false && ((board[i, j].IsEmpty) == false)) { int k; flgDown = true; board[i - 1, j] = board[i, j]; board[i, j] = new BlankCell(); for (k = 0; k < dropCells.Count; k++) { if (dropCells[k].rowAfter == i && dropCells[k].col == j) { Animation.Drop newdrop = new Animation.Drop(); newdrop.rowBefore = dropCells[k].rowBefore; newdrop.rowAfter = i - 1; newdrop.col = j; dropCells[k] = newdrop; break; } } if (k >= dropCells.Count) { Animation.Drop newdrop = new Animation.Drop(); newdrop.rowBefore = i; newdrop.rowAfter = i - 1; newdrop.col = j; dropCells.Add(newdrop); } } } } if (flgDown) { retVal = true; } } while (flgDown); return retVal; }
public Animator(Cell[,] copiedBoard, List<EraseDropPair> animation) { this.copiedBoard = copiedBoard; this.animation = animation; }