示例#1
0
        public static void Run()
        {
            //on startup
            SetWindowSize();
            SetColor();
            Showbanner();
            Player.SetInitialPositon(player1);
            Player.SetInitialPositon(player2);
            Ball.SetInitialPoisition(ball);

            bool end = false;

            while (end == false)
            {
                //game
                Player.Move(player1, ball);
                Player.Move(player2, ball);
                Ball.Move(ball, player1, player2);

                Console.Clear();

                Player.DrawPosition1(player1);
                Player.DrawPosition2(player2);
                Ball.Draw(ball);

                Player.PrintScore(player1, player2);
                SlowDown();
                end = Outcome.Determine(player1, player2);
            }
        }
示例#2
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            leftPad.Draw();
            rightPad.Draw();


            ball.ClearDraw();
            ball.Move(leftPad, rightPad);
            ball.Draw();
        }
示例#3
0
 public void RenderScene()
 {
     if (Running)
     {
         player1.MovePaddles(_playerUp, _playerDown);
         player2.MovePaddles(_enemyUp, _enemyDown);
         ball.Move();
         ball.HandlePaddleCollision(pictureBox1);
         ball.HandlePaddleCollision(pictureBox3);
     }
 }
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (cbStereo.Checked)
     {
         // TODO: Need to rotate the cameras towards the center a bit
         if (Camera.leftEyeView)
         {
             Camera.leftEyeView  = false;
             Camera.cameraMatrix = new Matrix3D(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 445, -300, -500, 1);
         }
         else
         {
             Camera.leftEyeView  = true;
             Camera.cameraMatrix = new Matrix3D(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 455, -300, -500, 1);
         }
     }
     ball.Move();
     tsBallInfo.Text = string.Format("ball position: {0:0.00}, {1:0.0}, {2:0.0}", ball.center.X, ball.center.Y, ball.center.Z);
     opponentPaddle.Move(ball);
     pointsEarned.Text         = "Points: " + PlayerPaddle.points.ToString();
     opponentPointsEarned.Text = "Opponent points: " + EnemyPaddle.points.ToString();
     Invalidate(true);
 }
示例#5
0
 private void timer1_Tick(object sender, System.EventArgs e) //runs one round of the game, when started
 {
     TheBall.UpdateBounds();                                 //gets the ball position
     Invalidate(TheBall.GetBounds());                        //redraws the ball
     if (speed < 5)
     {
         TheBall.Move(); //moves the ball
     }
     else if (speed < 10)
     {
         TheBall.MoveFast();
     }
     else if (speed < 15)
     {
         TheBall.MoveFaster();
     }
     else
     {
         TheBall.MoveFastest();
     }
     TheBall.UpdateBounds();          //updates position of the ball
     Invalidate(TheBall.GetBounds()); //redraws the boll
     CheckForCollision();             //checks for collision
 }
示例#6
0
        public void timer1_Tick(object sender, EventArgs e)
        {
            gfx.Clear(Color.LightBlue);



            paddle1.draw(gfx);
            paddle2.draw(gfx);
            ball.Draw(gfx);
            if (ball.game)
            {
                ball.Move(ClientSize.Width, ClientSize.Height, paddle1, paddle2);
            }
            if (paddle1.drawHitBox == true && paddle2.drawHitBox == true)
            {
                //paddle1 hitbox
                gfx.DrawRectangle(bluePen, paddle1.hitbox.X, paddle1.hitbox.Y, paddle1.hitbox.Width, paddle1.hitbox.Height);

                //paddle2 hitbox right
                gfx.DrawRectangle(bluePen, paddle2.hitbox.X, paddle2.hitbox.Y, paddle2.hitbox.Width, paddle2.hitbox.Height);
            }
            if (bot)
            {
                if (ball.y < ClientSize.Height - 100 && ball.y > 5)
                {
                    paddle2.y        = ball.hitbox.Y;
                    paddle2.hitbox.Y = paddle2.y;
                }
            }


            greenPen.DashPattern = new float[] { 4.0F, 2.0F, 1.0F, 3.0F };
            // Draw a line.

            gfx.DrawLine(greenPen, ball.left, 0, paddle1.x - 40, ClientSize.Height);
            gfx.DrawLine(greenPen, ball.right, 0, ball.right, ClientSize.Height);


            // Change the SmoothingMode to none.
            gfx.SmoothingMode =
                System.Drawing.Drawing2D.SmoothingMode.None;

            drawText(gfx, "Rally: " + ball.rally, 48, 296, 9);
            drawText(gfx, "Paddle 1: " + ball.score1, 20, 23, 37);
            drawText(gfx, "Paddle 2: " + ball.score2, 20, 707, 37);

            if (ball.x <= ball.left)
            {
                //if ball is on left wall, point to right player
                ball.rally = 0;
                Console.Beep(300, 500);
                ball.game = false;
                ball.score2++;
                paddle1.y = ClientSize.Height / 2;
                paddle2.y = ClientSize.Height / 2;
                ball.x    = ClientSize.Width / 2;
                ball.y    = ClientSize.Height / 2;
                if (ball.score2 == 3)
                {
                    MessageBox.Show("Player 2 Won!");
                }
                else
                {
                    MessageBox.Show("Player 2 Won 1 Point");
                }
                paddle1.hitbox.Y = paddle1.y;
                paddle2.hitbox.Y = paddle2.y;
                ball.game        = true;
            }
            if (ball.x >= ball.right)
            {
                //if ball is on right wall, point is to left player
                ball.rally = 0;
                Console.Beep(300, 500);
                ball.game = false;
                ball.score1++;
                paddle1.y = ClientSize.Height / 2;
                paddle2.y = ClientSize.Height / 2;
                ball.x    = ClientSize.Width / 2;
                ball.y    = ClientSize.Height / 2;
                if (ball.score1 == 3)
                {
                    timer1.Enabled = false;
                    MessageBox.Show("Player 1 Won!");
                    ball.x    = ClientSize.Width / 2;
                    ball.y    = ClientSize.Height / 2;
                    paddle1.y = ClientSize.Height / 2;
                    paddle2.y = ClientSize.Height / 2;

                    ball.score1    = 0;
                    ball.score2    = 0;
                    ball.rally     = 0;
                    timer1.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Player 1 Won 1 Point");
                }

                paddle1.hitbox.Y = paddle1.y;
                paddle2.hitbox.Y = paddle2.y;
                ball.game        = true;
            }

            if (ball.score2 == 3)
            {
                timer1.Enabled = false;
                MessageBox.Show("Player 2 Won!");
                ball.x    = ClientSize.Width / 2;
                ball.y    = ClientSize.Height / 2;
                paddle1.y = ClientSize.Height / 2;
                paddle2.y = ClientSize.Height / 2;

                ball.score1    = 0;
                ball.score2    = 0;
                ball.rally     = 0;
                timer1.Enabled = true;
            }
        }
示例#7
0
        protected override bool Logic()
        {
            _gameField.ClearField();

            if (_ball.X == 2)
            {
                if (_ball.Y > _player1.Y - 3 && _ball.Y < _player1.Y + 3)
                {
                    _ball.SetDirection((Ball.Direction)_rand.Next(4, 7));
                }
            }

            if (_ball.X == _gameField.Width - 3)
            {
                if (_ball.Y > _player2.Y - 3 && _ball.Y < _player2.Y + 3)
                {
                    _ball.SetDirection((Ball.Direction)_rand.Next(1, 4));
                }
            }

            if (_ball.X == 0 || _ball.X == _gameField.Width - 1)
            {
                if (_ball.X == 0)
                {
                    _score2++;
                }
                else
                {
                    _score1++;
                }
                _player1.ResetPosition(1, _gameField.Height / 2);
                _player2.ResetPosition(_gameField.Width - 2, _gameField.Height / 2);
                _ball.ResetPosition(_gameField.Width / 2, _gameField.Height / 2);
            }



            if (_ball.Y == 0)
            {
                if (_ball.Dir == Ball.Direction.LeftUp)
                {
                    _ball.SetDirection(Ball.Direction.LeftDown);
                }
                else
                {
                    _ball.SetDirection(Ball.Direction.RightDown);
                }
            }

            if (_ball.Y == _gameField.Height - 1)
            {
                if (_ball.Dir == Ball.Direction.LeftDown)
                {
                    _ball.SetDirection(Ball.Direction.LeftUp);
                }
                else
                {
                    _ball.SetDirection(Ball.Direction.RightUp);
                }
            }

            _player1.Move();
            _player2.Move();
            _ball.Move();
            return(false);
        }