public bool IsBlocking(TetrisBlock block, int x, int y) { for (int ix = 0; ix < block.GetBlockWidth(); ix++) { for (int iy = 0; iy < block.GetBlockHeight(); iy++) { if (direction == Direction.RIGHT) { if (block.blocks[iy,ix] == null) { continue; } } else { if (block.blocks[block.GetBlockHeight()-1-iy,ix] == null) { continue; } } int ny = iy+y; int nx = ix+x; if (ny < 0 || nx < 0 || nx >= blocks.GetLength(1) || ny >= blocks.GetLength(0)) { continue; } if (blocks[iy+y, ix+x] != null) { return true; } } } return false; }
public bool PutBlock(TetrisBlock block, int x, int y, bool canWin) { bool b = false; for (int ix = 0; ix < block.GetBlockWidth(); ix++) { for (int iy = 0; iy < block.GetBlockHeight(); iy++) { int magicY = iy ; if (direction == Direction.LEFT) { magicY = block.GetBlockHeight()-1-iy; } if (block.blocks[magicY, ix] != null) { int ny = iy+y; int nx = ix+x; if (ny < 0 || nx < 0 || nx >= blocks.GetLength(1) || ny >= blocks.GetLength(0)) { if (canWin) { b = true; Fail(); break; } else { return false; } } blocks[iy+y, ix+x] = block.blocks[magicY, ix]; } } if (b) { break; } } float xVal = FieldDefinition.instance.height-y-block.GetBlockHeight()+1; if (direction == Direction.LEFT) { xVal = -(FieldDefinition.instance.height-y); } if (block.GetComponent<PositionTween>() == null) { block.gameObject.AddComponent<PositionTween>(); } block.GetComponent<PositionTween>().TweenTo( new Vector3( xOffset + xVal, x, 0), 0.2f); block.GetComponent<PositionTween>().tweenEndCallback = ScanForLines; return true; }