Playing some Pong!

Getting the project ready.

  1. Make a new Eclipse Project
  2. Download pong
  3. Import pongai.jar
  4. When importing pongai.jar it will ask if you if you want to overwrite a couple of files, just click yes or yes to all

Make some modifications!

Adding some AI: Find in the code where there is the line "// Computer AI code goes here!" The following should go right below that line. Step 1:
    paddles[ 1 ].setLocation( paddles[ 1 ].getLocation( ).x, ball.getLocation( ).y ) ;
Step 2 (get rid of the line above and put the below in its place):
double speed = .015 ;
if( Math.abs( paddles[ 1 ].getLocation( ).y - ball.getLocation( ).y ) > speed )
{
	if( paddles[ 1 ].getLocation( ).x > ball.getLocation( ).x )
	{
		if( paddles[ 1 ].getLocation( ).y < ball.getLocation( ).y )
		{
			paddles[ 1 ].translate( 0, speed ) ;
		}
		else
		{
			paddles[ 1 ].translate( 0, -speed ) ;
		}
	}
	else
	{
		if( paddles[ 1 ].getLocation( ).y < ball.getLocation( ).y )
		{
			paddles[ 1 ].translate( 0, -speed ) ;
		}
		else
		{
			paddles[ 1 ].translate( 0, speed ) ;
		}
	}
}