First off is for the computer's paddle.
public class ComputerPaddle
{
// Declare needed variables.
private int yPos = 0, score;
final int XPOS = 460;
// This takes the y position of the ball and applies it to
// the y position of the ComputerPaddle.
public ComputerPaddle(int ballPos)
{
//Sets the y position and sets the score to 0.
setPos(BallPos);
setScore(0);
}
public void setPos(int pos)
{
// Same setup as the HumanPaddle.
this.yPos = pos;
// If the y position from the upper left-hand corner is
// 70 pixels from the bottom of the applet,
if(yPos > 230)
{
// Set it back to 70 pixels away.
setPos(230);
}
// If the y position from the upper left-hand corner is
// less than zero (outside the applet),
else if(yPos < 0)
{
// Set the y position to 0.
setPos(0);
}
}
public int getPos()
{
>>return yPos();<<
}
I got two errors for this part of it. The error was that it couldn't find the value for the method marked with the >><<. The second error is that it depends on Ball.java, which I'll get to in a second. (I hate how horribly vague Terminal is.)
Now, the Ball.java came up with an 'unexpected type' on the area marked with the >><<.
public class Ball
{
// Delcare the variables we need.
// The variables for the x and y positions...
private int xPos,yPos;
// The variables for the x and y direction of the ball.
// 'dy' is -5 because the applet window has an invisible
// 'grid'. This grid has it's origin at (0, 0), which is in
// the top left-hand corner of the applet.
public int dx = 5, dy = -5;
public Ball()
{
// Set the initial ball position to around the center
// of the applet screen.
setPos(250, 140);
}
public void setPos(int x, int y)
{
// Set the position of the ball.
this.xPos = x;
this.yPos = y;
}
public int getX()
{
// Get the x position of the ball.
return xPos;
}
public int getY()
{
// Get the y position of the ball.
return yPos;
}
// Now we create the method used to move the ball.
public void move()
{
// It takes the x and y position and then adds their
// current direction of movement to them, giving us
// a shift in the ball's position on the applet grid.
>> setPos(this.getX() = dx, this.getY() + dy); <<
}
So, can anyone help me with these small problems?
Cheers!
skymonkier

New Topic/Question
Reply



MultiQuote






|