Can you guys add the *pseudocode* (please add /pseudocode *only*/) for some of t
ID: 3777113 • Letter: C
Question
Can you guys add the *pseudocode* (please add /pseudocode *only*/) for some of the essential functionality of this PaddleBallController class stub below? public class PaddleBallController implements ActionListener, MouseMotionListener { // Add the field declarations // The constructor: public PaddleBallController() { // Instantiate the Ball, Paddle, and Display objects/fields // Pass THIS object to the Display object // Setup a new Timer: this will generate the events that drive the game // Register with THIS object // Register the mouse event handler // Register THIS object as the listener } // Method to have the game ball and game paddle draw themselves public void drawGame(Graphics g) { } // Deal with Timer Events public void actionPerformed(ActionEvent e) { // Ball moves within size of the display area // Determine if the ball is in contact with the paddle // Is the top of the ball now in contact with the paddle? // Cause the GUI/Display Object to redraw itself } // Check for user moving the Paddle via MouseEvents public void mouseDragged(MouseEvent me) { } public void mouseMoved(MouseEvent me) { } }
Explanation / Answer
package breakout;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
public class Paddle extends Sprite implements Commons {
String paddle = "../images/paddle.png";
int dx;
public Paddle() {
ImageIcon ii = new ImageIcon(this.getClass().getResource(paddle));
image = ii.getImage();
width = image.getWidth(null);
heigth = image.getHeight(null);
resetState();
}
public void move() {
x += dx;
if (x <= 2)
x = 2;
if (x >= Commons.PADDLE_RIGHT)
x = Commons.PADDLE_RIGHT;
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = -2;
} if (key == KeyEvent.VK_RIGHT) {
dx = 2;
}
}
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = 0;
}
if (key == KeyEvent.VK_RIGHT) {
dx = 0;
}
}
public void resetState() {
x = 200;
y = 360;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.