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 kickwav 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:
private int ballx, bally; the x and y coords of the ball
private int movex ;
private int movey ;
private int kickline height ;
private int goalline height ;
private Timer ballTimer, goalieTimer;
Assume the following methods exits:
public boolean goalBlocked returns true if the ball is blocked by the goalie
public boolean goalScored returns true if the ball is inside the goal and not blocked by the goalie
QuestionScreenshot.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
VKRIGHT
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
