Exemplo n.º 1
0
 public void MovePiece(int row, int col)
 {
     if (currentFallingPiece != null)
     {
         bool moveLeftAllowed  = col < 0 && !tetrisBoard.IsObstructed(currentFallingPiece, TetrisBoard.ObstructionDirection.LEFT);
         bool moveRightAllowed = col > 0 && !tetrisBoard.IsObstructed(currentFallingPiece, TetrisBoard.ObstructionDirection.RIGHT);
         if (moveLeftAllowed || moveRightAllowed)
         {
             currentFallingPiece.Move(row, col);
             currentFallingPiece.ApplyChange();
             currentFallingPiece.RefreshView();
         }
     }
 }
Exemplo n.º 2
0
    public void RotateIPieceCCW()
    {
        CommonInstall();
        // Use the Assert class to test conditions.

        TetrisPiece piece = factory.Create();

        piece.Init(TetrisPiece.PieceType.I);

        piece.Rotate(TetrisPiece.Rotation.CCW);
        piece.ApplyChange();
        Assert.AreEqual(
            "0100\n" +
            "0100\n" +
            "0100\n" +
            "0100",
            piece.GetString(), "Failed CCW rotate once");

        piece.Rotate(TetrisPiece.Rotation.CCW);
        piece.ApplyChange();
        Assert.AreEqual(
            "0000\n" +
            "0000\n" +
            "1111\n" +
            "0000",
            piece.GetString(), "Failed CCW rotate twice");

        piece.Rotate(TetrisPiece.Rotation.CCW);
        piece.ApplyChange();
        Assert.AreEqual(
            "0010\n" +
            "0010\n" +
            "0010\n" +
            "0010",
            piece.GetString(), "Failed CCW rotate three times");

        piece.Rotate(TetrisPiece.Rotation.CCW);
        piece.ApplyChange();
        Assert.AreEqual(
            "0000\n" +
            "1111\n" +
            "0000\n" +
            "0000",
            piece.GetString(), "Failed CCW rotate four times");
    }
Exemplo n.º 3
0
    public void AttachPiece(TetrisPiece piece, int row, int col)
    {
        piece.SetPos(row, col);
        piece.ApplyChange();
        piece.RefreshView();

        tetrisBoard.AttachPiece(piece);
        tetrisBoard.CheckRowClear();
    }