Posted by: Java_help April 22, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        
Please help me with this. Thank you in advance :)



This homework is geared towards fine tuning your programming and understanding of GUI/graphics/threading skills. You will be adopting a working (but not correct) game of ping pong in Java, porting it from Applet to Java Swing. You will also be practicing your thread programming skills.
 
I have made the basic Ping Pong source code available. Please download the code, and make sure you can get it running. To help you along, I’m outlining step by step guidelines for you to follow.
 
1) Basic port
  1. First start by getting the applet version to run.
  2. You need to use threads in this project.
  3. Now look over the code and understand how the pieces work together.
  4. Create a new Java project. You will be porting each of the classes from the example code to swing, so its better to code in empty class and fill in the details….feel free to rename or rethink the pieces of the program, make sure each of the next steps runs before continuing to the next step, MAKE SURE TO ADD COMMENTS TO YOUR CODE.
    1. Don’t do anything except get a blank window to open up (and close/exit correctly).
    2. Port the field class so that you can display a colored field (switch the background color to whatever you like.
    3. Port the ball class, so that you can get a bouncing ball on the screen. Don’t forget to play around with the ball color.
    4. Get the ball to bounce around the screen (for this step you can leave it as it is so that it bounces off the back wall back into the game
    5. Port the paddle so that it shows up in the game.
 
2) More complicated coding
  1. Add a score counter; so you can show the current score
  2. Add a miss counter; to show how many times the paddle missed the ball
  3. Add a hit counter; so that every time the ball is hit, the number is incremented….i.e. every time the ball and paddle meet, the number goes up by one.
  4. Convert the ball class, it so that it works for the current window’s size….and not as it is done…i.e. if I resize the window, it will still work.
  5. Make sure you are not hard coding any of your code to a specific window size
  6. Change it so that if the ball misses the paddle (to the right of the paddle) it disappears and the miss counter is incremented.
  7. Every 10 times you hit the ball you should get 1 point (on the score counter).
 
3) Test to see if you can play a regular game of ping pong.
 
 
Submit your .java source code files as your assignment submission.
Read Full Discussion Thread for this article