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 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 that implements the KeyListener interface and monitors the users key events of the game
private class DirectionListener implements _____
{public void_______(KeyEvent event)
{if (keyCode == event.________)
goalieTimer.________()}
if(________.isRunning())
{int keyCode = even.getKeyCode();
if(keyCode == event._____)
{ballx _______ ____________;
repaint();
}
if(keyCode==event.VK_RIGHT)
{ballx+=movex
repaint();
}
if (keyCode == event.__________)
{try
{PlaySound.myplay("_________");
}
catch (InterruptedException ie) {System.out.println (ie+ " error");}
_________.start();
}
}
}
public void keyTyped (KeyEvent event){}
public void keyReleased (KeyEvent event) {}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
