Question: import javafx.geometry.Point2D; public class Ball { private Point2D location ; private int direction ; private int speed ; private boolean isBeingHeld ; public Ball(Point2D loc)

 import javafx.geometry.Point2D; public class Ball { private Point2D location; private intdirection; private int speed; private boolean isBeingHeld; public Ball(Point2D loc) { location= loc; direction = 0; speed = 0; isBeingHeld = false; }// The get/set methods public Point2D getLocation() { return location; } publicint getDirection() { return direction; } public int getSpeed() { return speed;} public boolean isBeingHeld() { return isBeingHeld; } public void setLocation(Point2D newLocation){ location = newLocation; } public void setDirection(int newDirection) { direction =newDirection; } public void setSpeed(int newSpeed) { speed = newSpeed; } publicvoid setIsBeingHeld(boolean newHoldStatus) { isBeingHeld = newHoldStatus; } public String toString() {return "Ball" + " at (" + (int)location.getX() + "," + (int)location.getY()+ ") facing " + direction + " degrees going " +

import javafx.geometry.Point2D; public class Ball { private Point2D location; private int direction; private int speed; private boolean isBeingHeld; public Ball(Point2D loc) { location = loc; direction = 0; speed = 0; isBeingHeld = false; } // The get/set methods  public Point2D getLocation() { return location; } public int getDirection() { return direction; } public int getSpeed() { return speed; } public boolean isBeingHeld() { return isBeingHeld; } public void setLocation(Point2D newLocation) { location = newLocation; } public void setDirection(int newDirection) { direction = newDirection; } public void setSpeed(int newSpeed) { speed = newSpeed; } public void setIsBeingHeld(boolean newHoldStatus) { isBeingHeld = newHoldStatus; } public String toString() { return "Ball" + " at (" + (int)location.getX() + "," + (int)location.getY() + ") facing " + direction + " degrees going " + speed + " pixels per second"; } } 

public class Game { public static final int MAX_GAME_OBJECTS = 1000; Object[] gameObjects; int objectCount; public Game() { gameObjects = new Object[MAX_GAME_OBJECTS]; objectCount = 0; } public void add(Object obj) { if (objectCount MAX_GAME_OBJECTS) gameObjects[objectCount++] = obj; } // The get methods  public Object[] getGameObjects() { return gameObjects; } public int getObjectCount() { return objectCount; } public String toString() { return "Game with " + objectCount + " objects"; } public void displayObjects() { for (int i=0; iobjectCount; i++) System.out.println(gameObjects[i]); } } 

import javafx.geometry.Point2D; public class Wall { private Point2D location; private int width; private int height; public Wall(Point2D loc, int w, int h) { location = loc; width = w; height = h; } // The get/set methods  public Point2D getLocation() { return location; } public int getWidth() { return width; } public int getHeight() { return height; } public void setLocation(Point2D newLocation) { location = newLocation; } public String toString() { return "Wall" + " at (" + (int)location.getX() + "," + (int)location.getY() + ") with width " + width + " and height " + height; } } 

import javafx.geometry.Point2D; import javafx.scene.paint.Color; public class Player { private Point2D location; private int direction; private int speed; private String name; private Color color; private boolean hasBall; private int score; public Player(String n, Color c, Point2D loc, int dir) { location = loc; direction = dir; speed = 0; name = n; color = c; hasBall = false; score = 0; } // The get/set methods  public Point2D getLocation() { return location; } public int getDirection() { return direction; } public int getSpeed() { return speed; } public String getName() { return name; } public Color getColor() { return color; } public boolean hasBall() { return hasBall; } public int getScore() { return score; } public void setLocation(Point2D newLocation) { location = newLocation; } public void setDirection(int newDirection) { direction = newDirection; } public void setSpeed(int newSpeed) { speed = newSpeed; } public void setHasBall(boolean newHasBall) { hasBall = newHasBall; } public void setScore(int newScore) { score = newScore; } public String toString() { String s = "Player" + " " + name + " at (" + (int)location.getX() + "," + (int)location.getY() + ") facing " + direction + " degrees"; if (hasBall) s += " with the ball"; return s; } } 

import javafx.geometry.Point2D; public class Prize { private Point2D location; private int value; public Prize(Point2D loc, int val) { location = loc; value = val; } // The get/set methods  public Point2D getLocation() { return location; } public int getValue() { return value; } public String toString() { return "Prize" + " at (" + (int)location.getX() + "," + (int)location.getY() + ") with value " + value; } } 

import javafx.geometry.Point2D; public class Trap { private Point2D location; public Trap(Point2D loc) { location = loc; } // The get method  public Point2D getLocation() { return location; } public String toString() { return "Trap" + " at (" + (int)location.getX() + "," + (int)location.getY() + ")"; } } 

import javafx.geometry.Point2D; import javafx.scene.paint.Color; public class GameTestProgram { public static void main(String args[]) { Game g; g = new Game(); // Add some walls  g.add(new Wall(new Point2D(0,0), 10, 200)); g.add(new Wall(new Point2D(10,0), 170, 10)); g.add(new Wall(new Point2D(180,0), 10, 200)); g.add(new Wall(new Point2D(10,190), 170, 10)); g.add(new Wall(new Point2D(80,60), 100, 10)); g.add(new Wall(new Point2D(10,90), 40, 10)); g.add(new Wall(new Point2D(100,100), 10, 50)); // Add some prizes  g.add(new Prize(new Point2D(165,25), 1000)); g.add(new Prize(new Point2D(65,95), 500)); g.add(new Prize(new Point2D(145,165), 750)); // Add some traps  g.add(new Trap(new Point2D(125,35))); g.add(new Trap(new Point2D(145, 145))); // Add some players  g.add(new Player("Blue Guy", Color.BLUE, new Point2D(38,156), 90)); g.add(new Player("Yellow Guy", Color.YELLOW, new Point2D(55,37), 270)); g.add(new Player("Green Guy", Color.GREEN, new Point2D(147,116), 0)); // Add the ball  g.add(new Ball(new Point2D(90, 90))); System.out.println("Here are the Game Objects:"); g.displayObjects(); } } 

Trap The project begins with files that are used to represent a Game of "ball tag" in which a Player (who is "it") chases other players around a Walled environment with a Ball and tries to hit them with it. When the a player gets hit with the ball, they become "it" and try throw the ball at the other players. Each time a player hits another he/she gains points and when a player gets hit, he/she loses points. Prize Ball Assume that the environment has rectangular walls that prevent movement in certain directions. Also assume that there are Traps where a player cannot run into, otherwise he/she loses points. Lastly, assume that there are Prizes that the players can collect for bonus points while running around. Player Some classes for this game have been developed and they form the class hierarchy shown below: Object Ball Game Wall | Player Prize Trap Examine the classes and look at the attributes (i.e., instance variables). You will notice that there is a lot of duplicate information. For example, Ball, Wall, Player, Prize and Trap all keep track of a location, and Ball and Player both have a direction and speed. This is not very nice. To eliminate the duplication, we will re-organize the classes by abstraction (i.e., by extracting the common attributes and behaviors). One way of doing this would be to see what all objects have in common. It seems that all objects except Game have a location. So we will begin by getting that information out from the objects and storing it in a common class which they can all inherit from

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 Databases Questions!