public void CalcGhost(int[,] ghostInfoRow, int row, int col, Block block) { if (IsBlockCollision(row, col, block)) { throw new Exception("블럭이 올바른 위치에서 놓이지 않았음. 놓일 수 없는 위치임. DropBlock"); } Cell[,] copiedBoard = (Cell[,])board.Clone(); int lastRow = row; for (int i = row - 1; i + Block.ROW_SIZE >= 0; i--) { if (IsBlockCollision(i, col, block)) break; lastRow = i; } PutBlock(lastRow, col, block, copiedBoard); List<Animation.Drop> dropCells = new List<Animation.Drop>(); CalcDrop(dropCells, copiedBoard); for (int i = 0; i < Block.ROW_SIZE; i++) { for (int j = 0; j < Block.COL_SIZE; j++) { try { Animation.Drop found = dropCells.First(p => p.col == (j + col) && p.rowBefore == (i + lastRow)); ghostInfoRow[i, j] = found.rowAfter; } catch/* (InvalidOperationException e)*/ { ghostInfoRow[i, j] = i + lastRow; } } } }
public BlockList(int colorCnt=5) { leftPivot=0; rightPivot=0; blocks = new Block[900 + Core.Random.rand(100)]; for (int i = 0; i < blocks.Length; i++) { blocks[i] = new Block(4, colorCnt); } }
/// <summary> /// Copy Constructor /// </summary> /// <param name="from"></param> public Block(Block from) { this.cells = new Cell[ROW_SIZE, COL_SIZE]; for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { this.cells[i, j] = from.cells[i, j]; } } }
protected virtual bool BlockRegen() { if (isAnimationMode) return false; if (gameOver) return false; BlockList.Instance.NextBlock(isLeft); block = BlockList.Instance.GetBlock(isLeft); row = Pile.ROW_SIZE - 2; col = (Pile.COL_SIZE + 1) / 2; if (pile.IsBlockCollision(row, col, block)) { gameOver = true; } else { //regen succeeded pile.CalcGhost(ghostInfoRow, row, col, block); } return true; }
public void Set(int index, int block) { lock (thisLock) { blocks[index] = new Block(block); } }
/// <summary> Drop <param name="block">block</param> at somewhere. It doesn't simulate any removal of lines nor gravity drop. /// <param name="row">row</param>(bottom of the field: 0) & <param name="col">col</param>(left of the field: 0) /// </summary> public void DropBlock(int row, int col, Block block) { if (IsBlockCollision(row, col, block)) { throw new Exception("블럭이 올바른 위치에서 놓이지 않았음. 놓일 수 없는 위치임. DropBlock"); } int lastRow = row; for (int i = row-1; i+Block.ROW_SIZE >= 0; i--) { if (IsBlockCollision(i, col, block)) break; lastRow = i; } PutBlock(lastRow, col, block, board); }
private void RemoveBlock(int row, int col, Block block) { 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] = new BlankCell(); } } } }
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]; } } } }
public bool IsBlockCollision(int row, int col, Block block) { for (int i = 0; i < Block.ROW_SIZE; i++) { for (int j = 0; j < Block.COL_SIZE; j++) { if (isCellCollision(row + i, col + j, block[i, j])) return true; } } return false; }