public void ballRegenerationCheck_XPositionWithinLimits_ReturnsFalse() { Pong_PCC.Ball ball = new Pong_PCC.Ball(640, 480, 10, 10, 5, 60); int[] xPositions = new int[] { -10, 15, 100, 400, 615, 650 }; for (int i = 0; i < xPositions.Length; i++) { ball.XPosition = xPositions[i]; bool actual = ball.ballRegenerationCheck(1); Assert.IsFalse(actual); } }
private void OnTimedEvent(object sender, ElapsedEventArgs e) { uint distancePerTick = 5; //Amount of y px moved per tick //Checks if key is pressed down and moves accordingly // Done in timer to avoid keyboard repeat delay when holding if (leftPaddle.negativeMovement == true) { leftPaddle.negativeMove(distancePerTick); pboxGameboard.Invalidate(); } else if (leftPaddle.positiveMovement == true) { leftPaddle.positiveMove(distancePerTick); pboxGameboard.Invalidate(); } if (rightPaddle.negativeMovement == true) { rightPaddle.negativeMove(distancePerTick); pboxGameboard.Invalidate(); } else if (rightPaddle.positiveMovement == true) { rightPaddle.positiveMove(distancePerTick); pboxGameboard.Invalidate(); } ball.moveBall(); //Moves the ball each tick //Processing only done when ball moving in the direction of the paddle if (leftPaddle.BallDirection == true) { //Result of whether or not ball has hit paddle (1=hit the paddle, -1= missed the paddle) int result = ball.paddleDetection((int)leftPaddle.YPosition); //Change the y position of the ball automatically if playing singleplayer if (singlePlayer) { leftPaddle.moveY(ball.PredictedYPosition, boardSizeY / 240); } if (result == 1) { //Changes the direction the ball is heading towards leftPaddle.BallDirection = false; rightPaddle.BallDirection = true; } else if (result == -1) { bool regeneration = ball.ballRegenerationCheck(-1); //If missed, wait until ball is 50px beyond edge of panel if (regeneration) { //Change the score of the opposite paddle rightPaddle.Score += 1; //Creates new thread to start the update method Thread labelThread = new Thread(new ThreadStart(updateThread)); labelThread.Start(); //Finds new y from launch point if (singlePlayer) { ball.yDetection(); } } } } else if (rightPaddle.BallDirection == true) { //Result of whether or not ball has hit paddle (1=hit the paddle, -1= missed the paddle) int result = ball.paddleDetection((int)rightPaddle.YPosition); if (result == 1) { //Changes the projected y position to new point if (singlePlayer == true) { ball.yDetection(); } //Changes the direction the ball is heading towards rightPaddle.BallDirection = false; leftPaddle.BallDirection = true; } else if (result == -1) { bool regeneration = ball.ballRegenerationCheck(1); //If missed, wait until ball is 50px beyond edge of panel if (regeneration) { //Change the score of the opposite paddle leftPaddle.Score += 1; //Creates new thread to start the update method Thread labelThread = new Thread(new ThreadStart(updateThread)); labelThread.Start(); //Finds new y from launch point if (singlePlayer) { ball.yDetection(); } } } } //Add 10ms to the time elapsed ball.RoundTimeElapsed += 10; ball.sideDetection(); //Check if the ball hit the sides, processing done in the class pboxGameboard.Invalidate(); //Redraw the gameboard }