Beispiel #1
0
        public static void Run(
            LcdBoostProxy lcd,
            NumericInput slider1,
            NumericInput slider2)
        {
            //define an array for just two elements
            var elements = new ILcdBoostElement[2];

            //define text-area #1
            LcdBoostElementTextArea _te1;

            elements[0]        = _te1 = new LcdBoostElementTextArea();
            _te1.Text          = "The 74HC165; 74HCT165 are high-speed Si-gate CMOS devices that comply with JEDEC standard no. 7A.";
            _te1.Bounds.Left   = 0;
            _te1.Bounds.Top    = 0;
            _te1.Bounds.Width  = 20;
            _te1.Bounds.Height = 4;

            //define text-area #2
            LcdBoostElementTextArea _te2;

            elements[1]        = _te2 = new LcdBoostElementTextArea();
            _te2.Text          = "The clock input is a gated-OR structure which allows one input to be used as an active LOW clock enable (CE) input.";
            _te2.Bounds.Left   = 10;
            _te2.Bounds.Top    = 0;
            _te2.Bounds.Width  = 10;
            _te2.Bounds.Height = 10;


            //slider #1
            slider1.SetRange(1, 30);
            slider1.Value          = _te1.Bounds.Width;
            slider1.StatusChanged += (s_, e_) =>
            {
                //the scroller adjust the text-area #1 width.
                _te1.Bounds.Width = slider1.Value;
            };

            //slider #2
            slider2.SetRange(-10, 10);
            slider2.StatusChanged += (s_, e_) =>
            {
                //the scroller adjust the text-area #2 top offset
                _te2.Bounds.Top = slider2.Value;
            };


            //display refreshing clock
            var clock = new Timer(
                _ => lcd.Dump(elements),
                null,
                100,
                100);


            Thread.Sleep(Timeout.Infinite);
        }
Beispiel #2
0
        public static void Run(
            LcdBoostProxy lcd,
            NumericInput paddle)
        {
            //init the random number generator using a pseudo random seed
            _rnd = new Random(DateTime.Now.Millisecond);

            //define an array for containing all the UI-elements
            var elements   = new ILcdBoostElement[TotalBricks + 6];
            var elem_count = 0;

            /**
             * Allocates the resources to be used in the program
             * this is very similar to the "sprite" approach
             **/

            //right-side wall
            var wall = new LcdBoostElementTextArea();

            wall.Text              = "||||";
            wall.Bounds.Left       = 16;
            wall.Bounds.Top        = 0;
            wall.Bounds.Width      = 1;
            wall.Bounds.Height     = 4;
            elements[elem_count++] = wall;


            //number of paddles left
            _elem_paddles_left               = new LcdBoostElementTextArea();
            _elem_paddles_left.Bounds.Left   = 17;
            _elem_paddles_left.Bounds.Top    = 3;
            _elem_paddles_left.Bounds.Width  = 3;
            _elem_paddles_left.Bounds.Height = 1;
            elements[elem_count++]           = _elem_paddles_left;


            //game over indication
            _elem_gameover               = new LcdBoostElementTextArea();
            _elem_gameover.Text          = "-= GAME OVER =-";
            _elem_gameover.IsHidden      = true;
            _elem_gameover.Bounds.Left   = 0;
            _elem_gameover.Bounds.Top    = 2;
            _elem_gameover.Bounds.Width  = _elem_gameover.Text.Length;
            _elem_gameover.Bounds.Height = 1;
            elements[elem_count++]       = _elem_gameover;


            //bricks walls
            _elem_bricks = new LcdBoostElementCharPoint[BrickRows][];

            for (int y = 0; y < BrickRows; y++)
            {
                _elem_bricks[y] = new LcdBoostElementCharPoint[BrickColumns];

                for (int x = 0; x < BrickColumns; x++)
                {
                    var brick = new LcdBoostElementCharPoint();
                    brick.Face             = '=';
                    brick.X                = x;
                    brick.Y                = y;
                    _elem_bricks[y][x]     = brick;
                    elements[elem_count++] = brick;
                }
            }


            //gamer's (moving) paddle
            _elem_paddle               = new LcdBoostElementTextArea();
            _elem_paddle.Text          = "____";
            _elem_paddle.Bounds.Left   = 8;
            _elem_paddle.Bounds.Top    = 3;
            _elem_paddle.Bounds.Width  = 4;
            _elem_paddle.Bounds.Height = 1;
            elements[elem_count++]     = _elem_paddle;


            //controller for the paddle position
            paddle.Value = _elem_paddle.Bounds.Left;
            paddle.SetRange(
                minValue: 0,
                maxValue: lcd.Driver.Width - 4 - _elem_paddle.Bounds.Width
                );
            paddle.StatusChanged += (s_, e_) =>
            {
                _elem_paddle.Bounds.Left = paddle.Value;
            };


            //score indication
            _elem_score               = new LcdBoostElementTextArea();
            _elem_score.Text          = ":";
            _elem_score.Bounds.Left   = 17;
            _elem_score.Bounds.Top    = 0;
            _elem_score.Bounds.Width  = 3;
            _elem_score.Bounds.Height = 1;
            elements[elem_count++]    = _elem_score;


            //ball
            _elem_ball             = new LcdBoostElementCharPoint();
            _elem_ball.Face        = 'o';
            elements[elem_count++] = _elem_ball;


            /**
             * Create a new session of game.
             * The session contains only the dynamic data used
             * by the game. The logic is meant to be outside.
             * That's much like a functional approach
             **/
            var session = new GameSession();

            session.NewBall();


            /**
             * Master clock for the game refresh
             *
             * Notice that the clock is handling the display refresh
             * at 10 fps, but the game logic has to be slowed down
             * because would be too fast to play
             **/
            int clock_counter = 0;
            var clock         = new Timer(
                _ =>
            {
                //invoke the game logic
                Worker(
                    session,
                    clock_counter++
                    );

                //refresh display
                lcd.Dump(elements);
            },
                null,
                100,
                100);


            Thread.Sleep(Timeout.Infinite);
        }