Hi everyone!
Forgive me if my problem is fantastically simple to solve, but I'm a first year Computing student, beginner programmer and this is driving me nuts. As part of our portfolio task, we have been asked to make a Ping Pong Table. The code that represents the table, the paddles, the ball movement, the ball bouncing off the walls and some key event listeners to serve the ball, start a new game and quit are all working perfectly.
However, the issue I'm having is with trying to get the scores to work.
This example code, at present, is making the score go up by one until it reaches the score required to win. That score is stored in a final int variable elsewhere. But let's say for example the maximum score is 3. When the player scores a point, the score goes from 0 to 1, then if they score again, 1 to 2. But, when it hits that maximum score ("WINNING_SCORE" in the code) the score just seems to add one forever.
I've tried adding the kidScore = kidScore + 1 to a while loop but that has resulted in the score no longer shifting from zero.
Here is the code as it is so far:
}else if (ballX < BALL_MIN_X){ //Discovers if the co-ordinates of the ball have entered the "score" zone of the table kidScore = kidScore + 1; //Adds one to the score table.setMessageText("Computer: " + computerScore + " Kid " + kidScore); //Sets the score in the table MessageText if (kidScore<WINNING_SCORE){ //Whilst the player's score is below the winning score, the game just carries on from the kid's serve ballX = KID_RACKET_X; ballY = KID_RACKET_Y_START; ballServed = false; }else if (kidScore==WINNING_SCORE){ displayScore(); //If the player has the amount of points to win, this calls the displayScore method }
Any thoughts on how I could fix this?
Many thanks!