Exemplo n.º 1
0
 public void BoardDetectsBottomLinesEvenIfNoCurrentPieceExists()
 {
     var board = new Board(2, 3);
     board.AddNewBlock(1, 2);
     board.AddNewBlock(0, 2);
     //BB
     //BB
     Assert.AreEqual(2, board.GetBlocks().Count());
     board.Advance();
     Assert.AreEqual(0, board.GetBlocks().Count());
 }
Exemplo n.º 2
0
 public void BoardDetectsMultipleLines()
 {
     var board = new Board(2, 3);
     board.AddNewBlock(0, 2);
     board.AddNewBlock(1, 2);
     board.AddNewBlock(1, 1);
     board.AddNewBlock(0, 1);
     //BB
     //BB
     Assert.AreEqual(4, board.GetBlocks().Count());
     board.Advance();
     Assert.AreEqual(0, board.GetBlocks().Count());
 }
Exemplo n.º 3
0
 public void WhenFullLinesIsDetectedOnlyFullLineBlocksAreRemoved()
 {
     var board = new Board(2, 4);
     board.AddNewBlock(1, 1);
     board.AddNewBlock(0, 1);
     board.AddNewBlock(1, 2);
     board.AddNewBlock(1, 3);
     board.AddNewBlock(0, 3);
     //BB
     // B
     //BB
     Assert.AreEqual(5, board.GetBlocks().Count());
     board.Advance();
     //
     // B
     //
     Assert.AreEqual(1, board.GetBlocks().Count());
 }
Exemplo n.º 4
0
 public void WhenFullLinesIsDetectedBlocksAreMovedDown()
 {
     var board = new Board(2, 4);
     var block1 = board.AddNewBlock(0, 0);
     board.AddNewBlock(1, 1);
     board.AddNewBlock(0, 1);
     var block2 = board.AddNewBlock(1, 2);
     board.AddNewBlock(1, 3);
     board.AddNewBlock(0, 3);
     //B
     //BB
     // B
     //BB
     Assert.AreEqual(6, board.GetBlocks().Count());
     board.Advance();
     //
     //
     //B
     // B
     Assert.AreEqual(2, board.GetBlocks().Count());
     Assert.AreEqual(0, block1.X);
     Assert.AreEqual(2, block1.Y);
     Assert.AreEqual(1, block2.X);
     Assert.AreEqual(3, block2.Y);
 }
Exemplo n.º 5
0
        public void WhenCurrentPieceReachesBottomVerifyesIfThereIsLineEvenForComplexPieces()
        {
            var board = new Board(3, 5);
            var block1 = new Block(0, 0);
            var block2 = new Block(2, 0);
            board.AddNewPiece(new[] { block1, block2 });
            board.AddNewBlock(1, 4);
            // P P
            //
            //
            //
            //  X
            Assert.AreEqual(1, board.GetBlocks().Count());
            board.Advance(); //1
            board.Advance();
            board.Advance();
            board.Advance(); //4
            board.Advance();

            Assert.IsNull(board.CurrentPiece);
            Assert.AreEqual(0, board.GetBlocks().Count());
        }
Exemplo n.º 6
0
 public void WhenCurrentPieceReachesBottomVerifyesIfThereIsLine()
 {
     var board = new Board(2, 3);
     board.AddNewBlock(1, 2);
     board.AddNewPiece(); //0
     board.Advance(); //1
     board.Advance(); //2
     board.Advance(); //La pieza se apoyó.
     Assert.AreEqual(0, board.GetBlocks().Count());
 }
Exemplo n.º 7
0
 public void WhenCurrentPieceColidesWithIsolatedBlocksEvenForComplexPieces()
 {
     var board = new Board(3, 3);
     var block1 = new Block(0, 0);
     var block2 = new Block(2, 0);
     board.AddNewPiece(new[] { block1, block2 });
     board.AddNewBlock(2, 2);
     board.AddNewBlock(1, 0);
     // PXP
     //
     //   X
     Assert.AreEqual(2, board.GetBlocks().Count());
     board.Advance(); //1
     Assert.AreEqual(2, board.GetBlocks().Count());
     Assert.IsNotNull(board.CurrentPiece);
     board.Advance(); //2
     Assert.IsNull(board.CurrentPiece);
     Assert.AreEqual(4, board.GetBlocks().Count());
 }
Exemplo n.º 8
0
        public void PiecesAreLeanedAlsoOnIsolatedBlocks()
        {
            var board = new Board(2, 4);
            //
            //
            //B
            //
            var isolated = board.AddNewBlock(0, 2);
            board.AddNewPiece();
            var pieceBlock = board.CurrentPiece.GetBlocks().Single();
            board.Advance();
            board.Advance();
            Assert.AreEqual(2, board.GetBlocks().Count());
            Assert.IsTrue(board.GetBlocks().Contains(isolated));
            Assert.IsTrue(board.GetBlocks().Contains(pieceBlock));

            Assert.AreEqual(2, isolated.Y);
            Assert.AreEqual(0, isolated.X);

            Assert.AreEqual(1, pieceBlock.Y);
            Assert.AreEqual(0, pieceBlock.X);
        }
Exemplo n.º 9
0
        public void CanSaveToString()
        {
            var board = new Board(3, 5);

            board.AddNewBlock(0, 0);
            board.AddNewBlock(2, 0);

            board.AddNewBlock(1, 1);
            board.AddNewBlock(2, 1);

            board.AddNewBlock(0, 2);
            board.AddNewBlock(1, 2);

            board.AddNewBlock(2, 3);

            board.AddNewBlock(0, 4);
            board.AddNewBlock(2, 4);

            Assert.AreEqual(
                "X X" +
                " XX" +
                "XX " +
                "  X" +
                "X X",
                board.SaveToString()
            );
        }
Exemplo n.º 10
0
 public void CanGetCellBlock()
 {
     var board = new Board(3, 3);
     board.AddNewBlock(2, 2);
     board.AddNewBlock(1, 0);
     Assert.IsNotNull(board.GetBlock(2, 2));
     Assert.IsNotNull(board.GetBlock(1, 0));
     Assert.IsNull(board.GetBlock(2, 1));
 }