public bool Move(Direction direction) { if (current == Tetromino.Zero) { return(false); } if (Move(current, direction)) { current = current.Move(direction); return(true); } return(false); }
public override void Paint(Graphics graphics) { base.Paint(graphics); //绘制投影 if (ProjectEnabled && IsTetrominoFalling) { Tetromino proj = current; EraseTetromino(current); while (IsEmpty(proj)) { proj = proj.Move(Direction.Down); } proj = proj.Move(Direction.Up); DrawTetromino(current, false); Point[] cells = new Point[] { new Point(proj.XC, proj.YC), new Point(proj.X1, proj.Y1), new Point(proj.X2, proj.Y2), new Point(proj.X3, proj.Y3) }; SolidBrush brush = new SolidBrush(Color.FromArgb(32, 192, 0, 0)); foreach (Point cell in cells) { if (!IsEmpty(cell.Y, cell.X)) { continue; } Rectangle tile = new Rectangle(6 + cell.X * TileSize, 6 + cell.Y * TileSize, TileSize - 2, TileSize - 2); graphics.FillRectangle(brush, tile); } } }
protected Tetromino RotateTetromino(Tetromino t) { Tetromino rotated = t.Rotate(); EraseTetromino(t); //旋转后可能与其他块有重叠,故略微挪动以找到空位 foreach (Direction direction in Enum.GetValues(typeof(Direction))) { if (IsEmpty(rotated.Move(direction))) { DrawTetromino(rotated, false); return(rotated); } } DrawTetromino(t, false); return(Tetromino.Zero); }
protected bool Move(Tetromino t, Direction direction) { Tetromino moved = t.Move(direction); //先将传入的tetromino从tiles中抹掉 EraseTetromino(t); if (IsEmpty(moved)) { //若可写入则写入tiles DrawTetromino(moved, false); return(true); } else { //如果非空则将传入的tetromino写回tiles,即不运动 t.Type = moved.Type; DrawTetromino(t, false); return(false); } }
public static void Move(Tetromino tetromino, Brush[,] fieldMatrix, MoveContext context) { RemoveTetrominoFromFieldMatrix(tetromino, fieldMatrix); tetromino.Move(context); UpdateField(tetromino, fieldMatrix); }