Beispiel #1
0
 private GameEngine()
 {
     Board      = new CMatrix(GameConstans.BOARD_WIDTH, GameConstans.BOARD_HEIGHT);
     Player     = new CMatrix(1, 1);
     NextFigure = new CMatrix(1, 1);
     State      = GameState.Stopped;
 }
Beispiel #2
0
 public void DrawMatrix(int columnPos, int rowPos, CMatrix matrix, Graphics gfx)
 {
     for (var row = 0; row < matrix.RowsCount; row++)
     {
         for (var column = 0; column < matrix.ColumnsCount; column++)
         {
             if (matrix[column, row].HasElement)
             {
                 var currentBrick = matrix[column, row].Peek();
                 currentBrick.X = GameHelper.IndexToPixel(column + columnPos);
                 currentBrick.Y = GameHelper.IndexToPixel(row + rowPos);
                 currentBrick.Draw(gfx);
             }
         }
     }
 }
Beispiel #3
0
 public void DrawMatrix(CMatrix matrix, Graphics gfx) => DrawMatrix(0, 0, matrix, gfx);
Beispiel #4
0
        private CMatrix GenerateFigure(FigureType type, Color color)
        {
            CMatrix result;

            switch (type)
            {
            case FigureType.I:
                result = new CMatrix(5, 5);
                result[2, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     // 00100
                result[2, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 00100
                result[2, 2].Set(new Brick(GameConstans.BRICKSIZE, color));     // 00100
                result[2, 3].Set(new Brick(GameConstans.BRICKSIZE, color));     // 00100
                                                                                // 00000
                break;

            case FigureType.J:
                result = new CMatrix(3, 3);
                result[1, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     // 010
                result[1, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 010
                result[0, 2].Set(new Brick(GameConstans.BRICKSIZE, color));     // 110
                result[1, 2].Set(new Brick(GameConstans.BRICKSIZE, color));     //
                break;

            case FigureType.L:
                result = new CMatrix(3, 3);
                result[1, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     // 010
                result[1, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 010
                result[1, 2].Set(new Brick(GameConstans.BRICKSIZE, color));     // 011
                result[2, 2].Set(new Brick(GameConstans.BRICKSIZE, color));
                break;

            case FigureType.O:
                result = new CMatrix(2, 2);
                result[0, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     //
                result[1, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     // 11
                result[0, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 11
                result[1, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     //
                break;

            case FigureType.S:
                result = new CMatrix(3, 3);
                result[1, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     //
                result[2, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     // 011
                result[0, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 110
                result[1, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 000
                break;

            case FigureType.T:
                result = new CMatrix(3, 3);
                result[1, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     // 010
                result[0, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 110
                result[1, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 010
                result[1, 2].Set(new Brick(GameConstans.BRICKSIZE, color));     //
                break;

            case FigureType.Z:
                result = new CMatrix(3, 3);
                result[0, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     //
                result[1, 0].Set(new Brick(GameConstans.BRICKSIZE, color));     // 110
                result[1, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 011
                result[2, 1].Set(new Brick(GameConstans.BRICKSIZE, color));     // 000
                break;

            default:
                result = new CMatrix(1, 1);
                break;
            }
            return(result);
        }