Question
Adjust the first few lines of the Player and Ball constructors in order to get the code to compile by calling the new constructor that
Adjust the first few lines of the Player and Ball constructors in order to get the code to compile by calling the new constructor that you made in MovableObject which now takes 3 parameters, not just the one. When making your changes ... think about which initial direction, speed and location that you want to pass as parameters ... are they fixed values or parameters ? Your Ball constructor should have 2 lines remaining in it once you are done and your Player constructor should have 5 lines. Both Ball and Player should now compile ok.
Add a constructor to the StationaryObject class which calls super(loc); to simply set the initial location. Although there are no shared attributes between Wall, Trap and Prize, we will still make them inherit from StationaryObject in case we need to add additional shared attributes or behaviors in the future. The StationaryObject, Wall, Trap and Prize classes should all compile (i.e., no red) ok. Make sure that they do before you continue.
Cant seem to understand this part ^. Please add comments with detail! thanks
CODE:
import javafx.geometry.Point2D; import javafx.scene.paint.Color; public class Player extends MovableObject { private String name; private Color color; private boolean hasBall; private int score; public Player(String n, Color c, Point2D loc, int dir) { super(loc); name = n; color = c; hasBall = false; score = 0; }
import javafx.geometry.Point2D; public class MovableObject extends GameObject { protected int direction; protected int speed; public MovableObject(int d, int s, Point2D loc){ super(loc); direction = d; speed = s; } }
import javafx.geometry.Point2D; public class GameObject { protected Point2D location; public GameObject(Point2D loc){ location = loc; } public Point2D getLocation() { return location; } public void setLocation(Point2D newLocation) { location = newLocation; } }
import java.awt.geom.Point2D; public class StationaryObject extends GameObject { }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started