Question: Java question: When the user presses enter, goalie begin moving back and forth across the front of the goal.Player can moving left and right using
Java question: When the user presses enter, goalie begin moving back and forth across the front of the goal.Player can moving left and right using arrow keys. When user press the space bar kick sound (kick.wav) is played and the soccer ball is moved vertically from its location on the kick line at the ottom of the screen (kickline) toward the goal on the screen. If it hits the goal threshold (goalline), and goalie is no blocking the path of the ball, a goal is scored and the goal.wav file is played. If the goalie is blocked the path, the ball instantly return back to the kick line.
Assume following global variables in panel class exist:
1. private int ballx, bally //the x and y coord of the ball
2 private int movex = 5;
3. private int movey = 15;
4. private int kickline = 360; //y coord of kick line
5. private int goalline = 60 // y coord of goal line
6. private Timer ballTimer, goalieTimer;
Assume the following method exits;
public boolean goalScored()//return true when the ball is inside the goal and noot blocked by the goalie
Given the SoccerGame Write the code for a private class called BallListener that implements the ActionListener interface and animates the ball image. Assume the ballTimer has already been instantiated with this object as its listener. Assume it will move the ball up from the kickline until it touches or crosses the goalline by adjusting the y coordinate of the ball. At that time, the ballTimer object must be stopped and the clocked or goal scored conditions tested. If blocked (or goal area is missed entirely) the ball must return to the kickline. If a goal is scored, the goal.wav sound is played using the static method myplay in the PlaySound class, which takes a url arg, with try catch protecting it from an InterruptedException.
private class BallListener implements_________{
public void ________(ActionEvent event)
{
if (____>__________)
{
bally -= ____;
______________;
}
else {
___________.stop();
if(!_____________)
{
bally = kicklne;
_____________;
}
else {
goalieTimer.stop();
try{PlaySound.myplay("____________");
}
catch(InterruptedException ie)
{System.out.println(ie +" error");
}
}
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
