Question: Given the SoccerGame animation which appears in the screen below: When the player presses enter, the goalie begins moving back and forth across the front

Given the SoccerGame animation which appears in the screen below:
When the player presses enter, the goalie begins moving back and forth across the front of the goal.
The player can position the soccer ball by using the Left and Right arrow keys.
When the user presses the space bar, a kick sound (kick.wav) is played and the soccer ball is moved vertically from its location on the kick line at the bottom of the screen (kickline) toward the goal on the screen.
If it hits the goal threshold (goalline), and the goalie is not blocking the path of the ball, a goal is scored and the goal.wav file is played.
If the goalie is blocking the path, the ball instantly returns back to the kick line.
Assume the following global variables in the panel class exist:
1- private int ballx, bally;// the x and y coords of the ball
2- private int movex =5;
3- private int movey =15;
4- private int kickline = height 60;
5- private int goalline = height 360;
6- private Timer ballTimer, goalieTimer;
Assume the following methods exits:
1- public boolean goalBlocked()// returns true if the ball is blocked by the goalie
2- public boolean goalScored()// returns true if the ball is inside the goal and not blocked by the goalie
Question16-Screenshot.jpg
Given the SoccerGame Write the code for a private class that implements the KeyListener interface and monitors the users key events of the game.
private class DirectionListener implements
{
@Override
public void
(KeyEvent event){
int keyCode = event.getKeyCode();
if (keyCode == event.
){
ballx
;
repaint();
}
if (keyCode ==
.VK_RIGHT){
ballx += movex;
repaint();
}
if (keyCode == event.
){
try {
PlaySound.myplay("
");
}
catch (InterruptedException ie){
System.out.println (ie +" error");
}
.start();
}
if (keyCode == event.
){
goalieTimer.
();
}
}
@Override
public void keyTyped (KeyEvent event){}
@Override
public void keyReleased (KeyEvent event){}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!