Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help writing this class. Constructor Detail Brick public Brick(int topin, int leftIn) Creates a basic Brick object at a specified position. The new Brick
Need help writing this class.
Constructor Detail Brick public Brick(int topin, int leftIn) Creates a basic Brick object at a specified position. The new Brick will default with a strength of 3, meaning that it will break after 3 hits by a ball. Parameters: topin - The y position of the top of this Brick in the model. leftin - The x position of the left side of this Brick in the model. Brick public Brick(int topin, int leftIn, int hitsIn) Creates a custom Brick object at a specified position with a specified strength. Parameters: topin - The y position of the top of this Brick in the model. leftin - The x position of the left side of this Brick in the model. hitsin - The initial strength of this Brick. A value greater than zero represents that this Brick will break after that number of hits. A value of 0 represents a "non-brick" or empty space in the model. A value of -1 represents that this Brick cannot be broken at all, regardless of the number of hits. Method Detail getTop public int getTop () Retrieves the y coordinate of the top of this Brick. Returns: The y coordinate of the top edge. getLeft public int getLeft() Retrieves the x coordinate of the left side of this Brick. Returns: The x coordinate of the left edge. getWidth public int getWidth() Retrieves the width of this Brick. Returns: The width of the Brick. getHeight public int getHeight() Retrieves the height of this Brick. Returns: The height of the Brick. getColor public javafx.scene.paint.Color getColor() The current color to represent this Brick's breakability state. Returns: There are five possible Colors that can be returned based on the Brick's current strength: Color.BLACK if this Brick cannot be broken; Color.WHITE if this Brick has been completely broken; and Color.RED, Color.YELLOW, Color.GREEN if this Brick will break after 1, 2, and 3 more hits, consecutively. hit public boolean hit() This mutator method will update this Brick's state data to account for being hit by the Ball once. Returns: true when the hit caused this brick to break completely, false otherwise. is Touching public TouchPosition isTouching (Ball theBall) This method implements a collision detection algorithm to identify whether this Brick is currently being hit by a given Ball object. It will produce a return value to signal which side, if any, is currently being hit. Parameters: theBall - The Ball to examine for collision with this Brick. Returns: A valid Touch Position state representing where theBall is intersecting this Brick. When no collision is detected at all or this Brick is already broken, NONE should be returned. Otherwise, TOP, BOTTOM, LEFT, or RIGHT will be returned corresponding to which side of this Brick is currently being hit by theBall. to String public java.lang.String toString() Retrieves a String representation of this Brick's current object state. The string will be formatted as: "Brick at (tlx, tly, brx, bry)" where tlx/tly are the x and y coordinates of the top left corner and brx/bry are the x and y coordinates of the bottom right corner of this Brick. Overrides: toString in class java.lang.Object Returns: The formatted state information about this Brick. Constructor Detail Brick public Brick(int topin, int leftIn) Creates a basic Brick object at a specified position. The new Brick will default with a strength of 3, meaning that it will break after 3 hits by a ball. Parameters: topin - The y position of the top of this Brick in the model. leftin - The x position of the left side of this Brick in the model. Brick public Brick(int topin, int leftIn, int hitsIn) Creates a custom Brick object at a specified position with a specified strength. Parameters: topin - The y position of the top of this Brick in the model. leftin - The x position of the left side of this Brick in the model. hitsin - The initial strength of this Brick. A value greater than zero represents that this Brick will break after that number of hits. A value of 0 represents a "non-brick" or empty space in the model. A value of -1 represents that this Brick cannot be broken at all, regardless of the number of hits. Method Detail getTop public int getTop () Retrieves the y coordinate of the top of this Brick. Returns: The y coordinate of the top edge. getLeft public int getLeft() Retrieves the x coordinate of the left side of this Brick. Returns: The x coordinate of the left edge. getWidth public int getWidth() Retrieves the width of this Brick. Returns: The width of the Brick. getHeight public int getHeight() Retrieves the height of this Brick. Returns: The height of the Brick. getColor public javafx.scene.paint.Color getColor() The current color to represent this Brick's breakability state. Returns: There are five possible Colors that can be returned based on the Brick's current strength: Color.BLACK if this Brick cannot be broken; Color.WHITE if this Brick has been completely broken; and Color.RED, Color.YELLOW, Color.GREEN if this Brick will break after 1, 2, and 3 more hits, consecutively. hit public boolean hit() This mutator method will update this Brick's state data to account for being hit by the Ball once. Returns: true when the hit caused this brick to break completely, false otherwise. is Touching public TouchPosition isTouching (Ball theBall) This method implements a collision detection algorithm to identify whether this Brick is currently being hit by a given Ball object. It will produce a return value to signal which side, if any, is currently being hit. Parameters: theBall - The Ball to examine for collision with this Brick. Returns: A valid Touch Position state representing where theBall is intersecting this Brick. When no collision is detected at all or this Brick is already broken, NONE should be returned. Otherwise, TOP, BOTTOM, LEFT, or RIGHT will be returned corresponding to which side of this Brick is currently being hit by theBall. to String public java.lang.String toString() Retrieves a String representation of this Brick's current object state. The string will be formatted as: "Brick at (tlx, tly, brx, bry)" where tlx/tly are the x and y coordinates of the top left corner and brx/bry are the x and y coordinates of the bottom right corner of this Brick. Overrides: toString in class java.lang.Object Returns: The formatted state information about this BrickStep 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