Exemplo n.º 1
0
        public void TestBlockLanded()
        {
            TBoard        BoardCell   = new TBoard();
            TBlockShapeA  BlockShapeA = new TBlockShapeA();
            List <TBlock> Blocks      = new List <TBlock> ();

            //move down the blockA untill it touchs the ground of the board and
            //prove whether it can stack on it or not
            for (int row = 0; row < 22; row++)
            {
                BlockShapeA.MoveDown();
                if (BoardCell.CheckLanding(BlockShapeA.GetBlocks))
                {
                    BoardCell.BlockLanding(BlockShapeA.GetBlocks);
                }
            }

            Blocks = BlockShapeA.GetBlocks;

            Assert.AreEqual(200, Blocks[0].X);
            Assert.AreEqual(550, Blocks[0].Y);

            Assert.AreEqual(225, Blocks[1].X);
            Assert.AreEqual(550, Blocks[1].Y);

            Assert.AreEqual(200, Blocks[2].X);
            Assert.AreEqual(575, Blocks[2].Y);

            Assert.AreEqual(225, Blocks[3].X);
            Assert.AreEqual(575, Blocks[3].Y);
        }
Exemplo n.º 2
0
        public void TestBlockErase()
        {
            TBoard        BoardCell   = new TBoard();
            List <TBlock> Blocks      = new List <TBlock> ();
            TBlockShapeA  BlockShapeA = new TBlockShapeA();

            //fill the shape on the ground with leaving two block space as a hole so that
            //when blockA landed(filled) on that hole, it clears the line

            for (int i = 0; i < 8; i++)
            {
                TBlock Block = new TBlock();
                BoardCell.BoardCells[i * 25, 550] = Block;
            }

            for (int i = 0; i < 6; i++)
            {
                int    a     = 250;
                TBlock Block = new TBlock();
                BoardCell.BoardCells[a + (i * 25), 550] = Block;
            }

            for (int row = 0; row < 22; row++)
            {
                BlockShapeA.MoveDown();
                if (BoardCell.CheckLanding(BlockShapeA.GetBlocks))
                {
                    BoardCell.BlockLanding(BlockShapeA.GetBlocks);
                    BoardCell.EraseFullLine();
                }
            }

            for (int i = 0; i < 8; i++)
            {
                Assert.IsTrue(BoardCell.BoardCells [i * 25, 550] == null);
            }

            for (int i = 0; i < 6; i++)
            {
                int a = 250;
                Assert.IsTrue(BoardCell.BoardCells [a + (i * 25), 550] == null);
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            //Open the game window
            SwinGame.OpenGraphicsWindow("GameMain", 900, 700);
            //SwinGame.ShowSwinGameSplashScreen();

            TBoard      BoardCell  = new TBoard();
            TBlockShape BlockShape = null;

            //Run the game loop
            while (false == SwinGame.WindowCloseRequested())
            {
                //Fetch the next batch of UI interaction
                SwinGame.ProcessEvents();

                //Clear the screen and draw the framerate
                SwinGame.ClearScreen(Color.Black);

                //assign random shape to the parent TBlockShape BlockShape
                if (BlockShape == null)
                {
                    Random Rnd = new Random();
                    switch (Rnd.Next(7))
                    {
                    case 0: BlockShape = new TBlockShapeA(); break;

                    case 1: BlockShape = new TBlockShapeB(); break;

                    case 2: BlockShape = new TBlockShapeC(); break;

                    case 3: BlockShape = new TBlockShapeD(); break;

                    case 4: BlockShape = new TBlockShapeE(); break;

                    case 5: BlockShape = new TBlockShapeF(); break;

                    case 6: BlockShape = new TBlockShapeG(); break;
                    }
                }

                BlockShape.DrawShape();
                BoardCell.DrawBoard();
                BlockShape.DropDown();

                //Checks for the condition whether it's ready to land.
                if (BoardCell.CheckLanding(BlockShape.GetBlocks))
                {
                    BoardCell.BlockLanding(BlockShape.GetBlocks);
                    if (BoardCell.GameEnd == true)
                    {
                        BoardCell.ClearCell();
                        SwinGame.ClearScreen();
                        SwinGame.LoadBitmapNamed("gameover", "SwinGameAni.png");
                        SwinGame.DrawBitmap("gameover", 330, 300);
                        SwinGame.RefreshScreen();
                        SwinGame.Delay(5000);
                        SwinGame.ReleaseAllResources();
                        BoardCell.GameEnd        = false;
                        BoardCell.LineClearCount = 0;
                        BoardCell.Score          = 0;
                    }

                    BoardCell.EraseFullLine();

                    BlockShape = null;
                }


                if (SwinGame.KeyTyped(KeyCode.vk_LEFT))
                {
                    BlockShape.MoveLeft();
                }

                if (SwinGame.KeyTyped(KeyCode.vk_RIGHT))
                {
                    BlockShape.MoveRight();
                }

                if (SwinGame.KeyTyped(KeyCode.vk_DOWN))
                {
                    //BlockShape.MoveDown();
                }

                if (SwinGame.KeyTyped(KeyCode.vk_UP))
                {
                    BlockShape.Rotate();
                }



                //SwinGame.DrawFramerate(0,0);
                //Draw onto the screen
                SwinGame.RefreshScreen(20);
            }
        }