예제 #1
0
 // Redraw Game Elements
 private void Update(PaintEventArgs e)
 {
     Ball.Draw(e);
     Paddle.Draw(e);
     foreach (Block b in Blocks)
     {
         b.Draw(e);
     }
 }
예제 #2
0
        private void PlaceBlocks(int count)
        {
            var i = 0;

            for (var row = 1; row <= 3; row++)
            {
                for (var column = 0; column < 11; column++)
                {
                    var block = new Block(3 + (column * 7), (row * 2));
                    block.Draw();
                    _blocks[i++] = block;
                }
            }
        }
예제 #3
0
        // Set up Initial game State.
        private void InitializeBoard()
        {
            Graphics Graphics = PlayArea.CreateGraphics();
            int      SpacerX  = 1;
            int      SpacerY  = 1;

            // Set Ball Position
            int X = (PlayArea.Width / 2) - (Ball.Radius / 2);
            int Y = (PlayArea.Height / 2) - (Ball.Radius / 2);

            Ball.Position  = new Position(X, Y);
            Ball.Direction = new Direction(0, 2);

            // Set Paddle Position
            X = (PlayArea.Bounds.Width / 2) - (Paddle.Width / 2);
            Y = PlayArea.Bounds.Height - Paddle.Height;
            Paddle.Position = new Position(X, Y);

            // Draw
            Ball.Draw(Graphics);
            Paddle.Draw(Graphics);

            // X & Y Boundaries For Blocks
            int XLimit = PlayArea.Bounds.Width - PrototypeBlock.Width - SpacerX;
            int YLimit = (PlayArea.Bounds.Height / 2) - PrototypeBlock.Height - SpacerY;

            // Fill Top Of PlayArea With Blocks
            for (X = SpacerX; X < XLimit; X += (SpacerX + PrototypeBlock.Width))
            {
                for (Y = SpacerY; Y < YLimit; Y += (SpacerY + PrototypeBlock.Height))
                {
                    Block Block = new Block(new Position(X, Y));
                    Blocks.Add(Block);
                    Block.Draw(Graphics);
                }
            }

            // Set up Text labels.
            Result.Text       = "Ball: " + BallCount;
            Instructions.Text = "Move paddle with arrow, or A and D Keys.";
        }