示例#1
0
        /*
         * Instantiate GameCanvas and add game elements into it: ball, paddle and bricks.
         * */
        private void setupGameField(int rows, int columns)
        {
            //Canvas size width 600 height 350
            //Settting up canvas
            GameCanvas            = new Canvas();
            GameCanvas.Height     = spCanvas.Height;
            GameCanvas.Width      = spCanvas.Width;
            GameCanvas.Background = new SolidColorBrush(Colors.Black);
            spCanvas.Children.Add(GameCanvas);
            GameCanvas.Tapped += GameCanvas_Tapped;

            //Adding bricks 3.0
            _bricks = new List <Brick>();
            LevelBuilder lb = new LevelBuilder();

            _bricks = lb.getNewRandomLevelLayout(rows, columns, GameCanvas);

            foreach (Brick brick in _bricks)
            {
                GameCanvas.Children.Add(brick.getBrick());
            }

            //Adding Paddle 1.0
            paddle = new Paddle((int)(GameCanvas.Width / 2) - 50, (int)(GameCanvas.Height) - 6, 100, 6);
            Canvas.SetLeft(paddle.getPaddle(), paddle.getX());
            Canvas.SetTop(paddle.getPaddle(), paddle.getY());
            GameCanvas.Children.Add(paddle.getPaddle());

            //Adding Ball 1.0
            ball = new Ball(paddle.getX() + (paddle.getWidth() / 2), paddle.getY() - 11, 10, 10);
            Canvas.SetLeft(ball.getBall(), ball.getX());
            Canvas.SetTop(ball.getBall(), ball.getY());
            GameCanvas.Children.Add(ball.getBall());
        }
示例#2
0
 private void startGame()
 {
     //Decide whether the ball goes right or left at the start
     if ((ball.getX() > GameCanvas.Width / 2) && (!isStarted))
     {
         ball.setXVector(ball.getXVector() * -1);
     }
     //set started to true and start timer
     isStarted = true;
     _timer.Start();
 }