Пример #1
0
        public void TryMoveDown()
        {
            //arrange
            Board board = new Board();
            Block block = new Block(board, Color.White);
            block.Position = new Point(4, 4);
            bool x;

            //act
            x = block.TryMoveDown();

            //assert
            Assert.AreEqual(true, x);
        }
Пример #2
0
        public void MoveRight()
        {
            //arrange
            Board board = new Board();
            Block block = new Block(board, Color.White);
            block.Position = new Point(2, 1);

            //act
            block.MoveRight();

            //assert
            Assert.AreEqual(3, block.Position.X);
            Assert.AreEqual(1, block.Position.Y);
        }
Пример #3
0
        public void Rotate()
        {
            //arrange
            Board board = new Board();
            Block block = new Block(board, Color.White);
            block.Position = new Point(8, 6);
            Point offset = new Point(1, 2);

            //act
            block.Rotate(offset);

            //assert
            Assert.AreEqual(9, block.Position.X);
            Assert.AreEqual(8, block.Position.Y);
        }
Пример #4
0
        public void Score_Test1()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;
            Score score = new Score(board);

            //act
            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveRight();
            shape.MoveRight();
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.Drop();

            //assert
            Assert.AreEqual(200, score.score);
            Assert.AreEqual(2, score.Lines);
            Assert.AreEqual(2, score.Level);
        }
Пример #5
0
        public void AddToPile()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;

            //act
            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            //assert
            Assert.IsTrue(board[4, 18].Equals(Color.Yellow));
            Assert.IsTrue(board[5, 18].Equals(Color.Yellow));
            Assert.IsTrue(board[4, 19].Equals(Color.Yellow));
            Assert.IsTrue(board[5, 19].Equals(Color.Yellow));
        }
Пример #6
0
        public void Drop()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;

            //act
            shapeFactory.DeployShape(4);
            shape = board.Shape;
            shape.Drop();

            //assert
            Assert.AreEqual(Color.Lime, board[4,19]);
            Assert.AreEqual(Color.Lime, board[5, 19]);
            Assert.AreEqual(Color.Lime, board[5, 18]);
            Assert.AreEqual(Color.Lime, board[6, 18]);
        }
Пример #7
0
        public void TestMethodShapeI_Drop()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            //act
            shape.Drop();

            //assert
            Assert.AreEqual(3, shape[0].Position.X);
            Assert.AreEqual(19, shape[0].Position.Y);
            Assert.AreEqual(4, shape[1].Position.X);
            Assert.AreEqual(19, shape[1].Position.Y);
            Assert.AreEqual(5, shape[2].Position.X);
            Assert.AreEqual(19, shape[2].Position.Y);
            Assert.AreEqual(6, shape[3].Position.X);
            Assert.AreEqual(19, shape[3].Position.Y);
        }
Пример #8
0
        public void TestMethodShapeI_MoveRight()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            //act
            shape.MoveRight();

            //assert
            Assert.AreEqual(4, shape[0].Position.X);
            Assert.AreEqual(0, shape[0].Position.Y);
            Assert.AreEqual(5, shape[1].Position.X);
            Assert.AreEqual(0, shape[1].Position.Y);
            Assert.AreEqual(6, shape[2].Position.X);
            Assert.AreEqual(0, shape[2].Position.Y);
            Assert.AreEqual(7, shape[3].Position.X);
            Assert.AreEqual(0, shape[3].Position.Y);
        }
Пример #9
0
        public void TestMethodShapeZ_MoveDown()
        {
            //arrange
            IBoard board = new Board();
            ShapeZ shape = new ShapeZ(board);

            //act
            shape.MoveDown();

            //assert
            Assert.AreEqual(4, shape[0].Position.X);
            Assert.AreEqual(1, shape[0].Position.Y);
            Assert.AreEqual(5, shape[1].Position.X);
            Assert.AreEqual(1, shape[1].Position.Y);
            Assert.AreEqual(5, shape[2].Position.X);
            Assert.AreEqual(2, shape[2].Position.Y);
            Assert.AreEqual(6, shape[3].Position.X);
            Assert.AreEqual(2, shape[3].Position.Y);
        }
Пример #10
0
        public void TestMethodShapeO_MoveLeft()
        {
            //arrange
            IBoard board = new Board();
            ShapeO shape = new ShapeO(board);

            //act
            shape.MoveLeft();

            //assert
            Assert.AreEqual(3, shape[0].Position.X);
            Assert.AreEqual(0, shape[0].Position.Y);
            Assert.AreEqual(3, shape[1].Position.X);
            Assert.AreEqual(1, shape[1].Position.Y);
            Assert.AreEqual(4, shape[2].Position.X);
            Assert.AreEqual(0, shape[2].Position.Y);
            Assert.AreEqual(4, shape[3].Position.X);
            Assert.AreEqual(1, shape[3].Position.Y);
        }
Пример #11
0
        public void MoveRight()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;

            //act
            shapeFactory.DeployShape(2);
            shape = board.Shape;
            shape.MoveRight();

            //assert
            Assert.AreEqual(5, shape[0].Position.X);
            Assert.AreEqual(1, shape[0].Position.Y);
            Assert.AreEqual(5, shape[1].Position.X);
            Assert.AreEqual(0, shape[1].Position.Y);
            Assert.AreEqual(6, shape[2].Position.X);
            Assert.AreEqual(0, shape[2].Position.Y);
            Assert.AreEqual(7, shape[3].Position.X);
            Assert.AreEqual(0, shape[3].Position.Y);
        }
Пример #12
0
        public void GetLength()
        {
            //arrange
            IBoard board = new Board();

            //act
            int dim1 = board.GetLength(0);
            int dim2 = board.GetLength(1);

            //assert
            Assert.AreEqual(10, dim1);
            Assert.AreEqual(20, dim2);
        }
Пример #13
0
        public void TestMethodShapeI_Rotate()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            shape.MoveDown();

            //act
            shape.Rotate();

            //assert
            Assert.AreEqual(5, shape[0].Position.X);
            Assert.AreEqual(3, shape[0].Position.Y);
            Assert.AreEqual(5, shape[1].Position.X);
            Assert.AreEqual(2, shape[1].Position.Y);
            Assert.AreEqual(5, shape[2].Position.X);
            Assert.AreEqual(1, shape[2].Position.Y);
            Assert.AreEqual(5, shape[3].Position.X);
            Assert.AreEqual(0, shape[3].Position.Y);
        }
Пример #14
0
        public void TryRotateFalse()
        {
            //arrange
            Board board = new Board();
            Block block = new Block(board, Color.White);
            block.Position = new Point(8, 6);
            Point offset = new Point(2, 2); // Go to 10,8 -> does not exist
            bool x;

            //act
            x = block.TryRotate(offset);

            //assert
            Assert.AreEqual(false, x);
        }
Пример #15
0
        public void DropsLines()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;

            //act
            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveRight();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveRight();
            shape.MoveRight();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.Drop();

            // Shape placed on top of the pile to be cleared
            // Should be dropped to bottom of board
            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.Drop();

            //assert
            Assert.IsTrue(board[3, 19] == Color.Cyan);
            Assert.IsTrue(board[4, 19] == Color.Cyan);
            Assert.IsTrue(board[5, 19] == Color.Cyan);
            Assert.IsTrue(board[6, 19] == Color.Cyan);
        }
Пример #16
0
        public void OnJoinPile()
        {
            //arrange
            Board board = new Board();
            IShape shape = board.Shape;
            shape.JoinPile += JoinPileHandler;

            //act
            shape.Drop();
        }
Пример #17
0
        public void TestShapeI_InvalidRotate()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            //act
            shape.Rotate();

            // Assert
            Assert.AreEqual(new Point(3, 0), shape[0].Position);
            Assert.AreEqual(new Point(4, 0), shape[1].Position);
            Assert.AreEqual(new Point(5, 0), shape[2].Position);
            Assert.AreEqual(new Point(6, 0), shape[3].Position);
        }
Пример #18
0
        public void TryRotate()
        {
            //arrange
            Board board = new Board();
            Block block = new Block(board, Color.White);
            block.Position = new Point(8, 6);
            Point offset = new Point(1, 2); // Goes to 9,8
            bool x;

            //act
            x = block.TryRotate(offset);

            //assert
            Assert.AreEqual(true, x);
        }
Пример #19
0
        public void TestShapeI_DownRotateDrop()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            //act
            shape.MoveDown();
            shape.Rotate();
            shape.Drop();

            //assert
            Assert.AreEqual(new Point(5, 19), shape[0].Position);
            Assert.AreEqual(new Point(5, 18), shape[1].Position);
            Assert.AreEqual(new Point(5, 17), shape[2].Position);
            Assert.AreEqual(new Point(5, 16), shape[3].Position);
        }
Пример #20
0
        public void TestShapeI_AllLeft()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            //act
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();

            //assert
            Assert.AreEqual(new Point(0, 0), shape[0].Position);
            Assert.AreEqual(new Point(1, 0), shape[1].Position);
            Assert.AreEqual(new Point(2, 0), shape[2].Position);
            Assert.AreEqual(new Point(3, 0), shape[3].Position);
        }
Пример #21
0
        public void DropsLines2()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;

            //act
            board[0, 19] = Color.Red;
            board[1, 19] = Color.Red;
            board[2, 19] = Color.Red;
            board[3, 19] = Color.Red;
            board[6, 19] = Color.Red;
            board[7, 19] = Color.Red;
            board[8, 19] = Color.Red;
            board[9, 19] = Color.Red;

            board[0, 18] = Color.Red;
            board[2, 18] = Color.Red;
            board[3, 18] = Color.Red;
            board[7, 18] = Color.Red;
            board[8, 18] = Color.Red;

            board[0, 17] = Color.Red;
            board[1, 17] = Color.Red;
            board[2, 17] = Color.Red;
            board[3, 17] = Color.Red;
            board[6, 17] = Color.Red;
            board[7, 17] = Color.Red;
            board[8, 17] = Color.Red;
            board[9, 17] = Color.Red;

            board[0, 16] = Color.Red;
            board[2, 16] = Color.Red;
            board[3, 16] = Color.Red;
            board[7, 16] = Color.Red;
            board[8, 16] = Color.Red;

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(0);
            shape = board.Shape;
            shape.MoveDown();
            shape.Rotate();
            shape.Drop();

            //assert
            Assert.IsTrue(board[0, 19] == Color.Red);
            Assert.IsTrue(board[0, 18] == Color.Red);
            Assert.IsTrue(board[2, 19] == Color.Red);
            Assert.IsTrue(board[2, 18] == Color.Red);
            Assert.IsTrue(board[3, 19] == Color.Red);
            Assert.IsTrue(board[3, 18] == Color.Red);
            Assert.IsTrue(board[7, 19] == Color.Red);
            Assert.IsTrue(board[7, 18] == Color.Red);
            Assert.IsTrue(board[8, 19] == Color.Red);
            Assert.IsTrue(board[8, 18] == Color.Red);
        }
Пример #22
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Instantiate Tetris logic
            IBoard board = new Board();
            Score score = new Score(board);

            // Add to board's GameOver event
            board.GameOver += gameOver;

            // Instantiate sprite classes
            int size = 25;
            boardSprite = new BoardSprite(this, board, size);
            shapeSprite = new ShapeSprite(this, board, score, size);
            scoreSprite = new ScoreSprite(this, score);

            // Add sprite classes
            Components.Add(boardSprite);
            Components.Add(shapeSprite);
            Components.Add(scoreSprite);

            // Set height and width of screen
            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth = 500;
            graphics.ApplyChanges();

            // Initialize font
            font = Content.Load<SpriteFont>("scoreFont");

            base.Initialize();

            //Create button
            int x = 5;
            int y = 200;
            button_state = BState.UP;
            button_color = Color.White;
            button_timer = 0.0;
            button_rectangle = new Rectangle(x, y, 100, 40);
            IsMouseVisible = true;

            background_color = Color.Black;

            /**Music
            Song song = Content.Load<Song>("music");
            MediaPlayer.Play(song);
            */
        }
Пример #23
0
        public void TestMethodShapeS_Reset()
        {
            //arrange
            IBoard board = new Board();
            ShapeS shape = new ShapeS(board);

            shape.MoveDown();

            //act
            shape.Reset();

            //assert
            Assert.AreEqual(new Point(4, 1), shape[0].Position);
            Assert.AreEqual(new Point(5, 1), shape[1].Position);
            Assert.AreEqual(new Point(5, 0), shape[2].Position);
            Assert.AreEqual(new Point(6, 0), shape[3].Position);
        }
Пример #24
0
        public void TestShapeI_AllRight()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            //act
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();

            //assert
            Assert.AreEqual(new Point(6, 0), shape[0].Position);
            Assert.AreEqual(new Point(7, 0), shape[1].Position);
            Assert.AreEqual(new Point(8, 0), shape[2].Position);
            Assert.AreEqual(new Point(9, 0), shape[3].Position);
        }
Пример #25
0
        public void OnGameOver()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;

            // add event handler
            board.GameOver += GameOverHandler;

            //act
            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            // Should not work
            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();
        }
Пример #26
0
        public void TestShapeI_DownRotateRight()
        {
            //arrange
            IBoard board = new Board();
            ShapeI shape = new ShapeI(board);

            //act
            shape.MoveDown();
            shape.Rotate();
            shape.MoveLeft();

            //assert
            Assert.AreEqual(new Point(4, 3), shape[0].Position);
            Assert.AreEqual(new Point(4, 2), shape[1].Position);
            Assert.AreEqual(new Point(4, 1), shape[2].Position);
            Assert.AreEqual(new Point(4, 0), shape[3].Position);
        }
Пример #27
0
        public void OnLinesCleared()
        {
            //arrange
            Board board = new Board();
            IShapeFactory shapeFactory = board.ShapeFactory;
            IShape shape;

            // add event handler
            board.LinesCleared += LinesClearedHandler;

            //act
            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveLeft();
            shape.MoveLeft();
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveRight();
            shape.MoveRight();
            shape.Drop();

            shapeFactory.DeployShape(3);
            shape = board.Shape;
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.MoveRight();
            shape.Drop();
        }
Пример #28
0
        public void ValidConstructor()
        {
            //arrange
            IBoard board = new Board();

            //assert
            Assert.IsInstanceOfType(board, typeof(IBoard));
        }
Пример #29
0
        public void TryMoveRightFalse()
        {
            //arrange
            Board board = new Board();
            Block block = new Block(board, Color.White);
            block.Position = new Point(9, 1);
            bool x;

            //act
            x = block.TryMoveRight();

            //assert
            Assert.AreEqual(false, x);
        }