Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Need help writing this class. Please use intro Java if possible. public class Level extends java.lang. Object This class models a basic game level in

Need help writing this class. Please use intro Java if possible.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

public class Level extends java.lang. Object This class models a basic game level in the brick breaker game. It allows for the creation of new levels, simulation of game steps, and retrieval of current state information. All levels contain a grid of 5 rows and 7 columns of Bricks (some of which may have been broken), a single Ball, and a single Paddle. Constructor Summary Constructors Constructor and Description Level (int widthIn, int heightIn) Creates a default level with a given dimension. Level(int widthIn, int heightIn, java.lang.String[] brickConfig) Creates a level with a given dimension and specified brick configuration. Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Ball getBall() Retrieves the Ball object in this Level. Brick [] [] getBricks() Retrieves a 5 by 7 array of Brick objects corresponding to the current grid of Bricks in the model. GameState getGameStatus() Retrieves state information about the game's current progress based on the last simulated step. Paddle getPaddle() Retrieves the Paddle object in this Level. void updateOne Step () This method updates this level's model data based on simulating one timestep in the game. public Level (int widthin, int heightIn) Creates a default level with a given dimension. The default brick configuration is a 5 row and 7 column grid of Brick objects, each which requires 3 hits to break. Bricks are arranged starting 40 pixels from the top edge of the screen and 10 pixels from the left edge of the screen. Bricks should be spaced with 5 pixels between each Brick in both dimensions. The Ball will start in the center of the screen, and the Paddle's top-left edge should be positioned at the left edge and 20 pixels up from the bottom of the screen. Parameters: widthin - The logical width of the new level in pixels. heightIn - The logical height of the new level in pixels. Level public Level (int widthin, int heightIn, java.lang.String() brickconfig) Creates a level with a given dimension and specified brick configuration. The Brick configuration is specified through an array of String values where each character corresponds to a single Brick. This array of Strings is guaranteed to contain 5 valid Strings, each of which will have 7 characters. Characters in the string will correspond to one value in {", 'o', '1', '2', '3'} where: ** signifies a brick that cannot be broken 'o' signifies a "ghost brick" that is already broken '1' signifies a brick that requires one hit to break '2' signifies a brick that requires two hits to break '3' signifies a brick that requires three hits to break Input strings are assumed valid and no error checking is provided. Bricks are arranged starting 40 pixels from the top edge of the screen and 10 pixels from the left edge of the screen. Bricks should be spaced with 5 pixels between each Brick in both dimensions. The Ball will start in the center of the screen, and the Paddle's top-left edge should be positioned at the left edge and 20 pixels up from the bottom of the screen. Parameters: widthIn - The logical width of the new level in pixels. heightIn - The logical height of the new level in pixels. brickConfig - The configuration array specifying the grid of Bricks to use in this new level. public void updateOneStep () This method updates this level's model data based on simulating one timestep in the game. Specifically the following will occur: (1) The ball will be moved based on its last known trajectory, (2) The ball will bounce off the side walls of the screen horizontally if hitting the left or right sides, and vertically if hitting the top. (3) The ball will bounce in the appropriate direction off the paddle if they are touching (4) The ball will bounce in the appropriate direction off any Brick it is currently touching and the Brick will react as required when hit by a Ball. (5) The end game state (won or lost) will be updated if all possible Bricks are broken or the Ball hits the bottom of the screen, respectively. getBall public Ball getBall() Retrieves the Ball object in this Level. Returns: The Ball used in the model.. getPaddle public Paddle getPaddle() Retrieves the Paddle object in this Level. Returns: The Paddle used in the model. getBricks public Brick[] [] getBricks() Retrieves a 5 by 7 array of Brick objects corresponding to the current grid of Bricks in the model. Returns: Data for the Bricks in the game level. getGameStatus public GameState getGameStatus() Retrieves state information about the game's current progress based on the last simulated step. Returns: The appropriate state if the user has won or LOST the game. If neither, PLAYING will be reported. public class Level extends java.lang. Object This class models a basic game level in the brick breaker game. It allows for the creation of new levels, simulation of game steps, and retrieval of current state information. All levels contain a grid of 5 rows and 7 columns of Bricks (some of which may have been broken), a single Ball, and a single Paddle. Constructor Summary Constructors Constructor and Description Level (int widthIn, int heightIn) Creates a default level with a given dimension. Level(int widthIn, int heightIn, java.lang.String[] brickConfig) Creates a level with a given dimension and specified brick configuration. Method Summary All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Ball getBall() Retrieves the Ball object in this Level. Brick [] [] getBricks() Retrieves a 5 by 7 array of Brick objects corresponding to the current grid of Bricks in the model. GameState getGameStatus() Retrieves state information about the game's current progress based on the last simulated step. Paddle getPaddle() Retrieves the Paddle object in this Level. void updateOne Step () This method updates this level's model data based on simulating one timestep in the game. public Level (int widthin, int heightIn) Creates a default level with a given dimension. The default brick configuration is a 5 row and 7 column grid of Brick objects, each which requires 3 hits to break. Bricks are arranged starting 40 pixels from the top edge of the screen and 10 pixels from the left edge of the screen. Bricks should be spaced with 5 pixels between each Brick in both dimensions. The Ball will start in the center of the screen, and the Paddle's top-left edge should be positioned at the left edge and 20 pixels up from the bottom of the screen. Parameters: widthin - The logical width of the new level in pixels. heightIn - The logical height of the new level in pixels. Level public Level (int widthin, int heightIn, java.lang.String() brickconfig) Creates a level with a given dimension and specified brick configuration. The Brick configuration is specified through an array of String values where each character corresponds to a single Brick. This array of Strings is guaranteed to contain 5 valid Strings, each of which will have 7 characters. Characters in the string will correspond to one value in {", 'o', '1', '2', '3'} where: ** signifies a brick that cannot be broken 'o' signifies a "ghost brick" that is already broken '1' signifies a brick that requires one hit to break '2' signifies a brick that requires two hits to break '3' signifies a brick that requires three hits to break Input strings are assumed valid and no error checking is provided. Bricks are arranged starting 40 pixels from the top edge of the screen and 10 pixels from the left edge of the screen. Bricks should be spaced with 5 pixels between each Brick in both dimensions. The Ball will start in the center of the screen, and the Paddle's top-left edge should be positioned at the left edge and 20 pixels up from the bottom of the screen. Parameters: widthIn - The logical width of the new level in pixels. heightIn - The logical height of the new level in pixels. brickConfig - The configuration array specifying the grid of Bricks to use in this new level. public void updateOneStep () This method updates this level's model data based on simulating one timestep in the game. Specifically the following will occur: (1) The ball will be moved based on its last known trajectory, (2) The ball will bounce off the side walls of the screen horizontally if hitting the left or right sides, and vertically if hitting the top. (3) The ball will bounce in the appropriate direction off the paddle if they are touching (4) The ball will bounce in the appropriate direction off any Brick it is currently touching and the Brick will react as required when hit by a Ball. (5) The end game state (won or lost) will be updated if all possible Bricks are broken or the Ball hits the bottom of the screen, respectively. getBall public Ball getBall() Retrieves the Ball object in this Level. Returns: The Ball used in the model.. getPaddle public Paddle getPaddle() Retrieves the Paddle object in this Level. Returns: The Paddle used in the model. getBricks public Brick[] [] getBricks() Retrieves a 5 by 7 array of Brick objects corresponding to the current grid of Bricks in the model. Returns: Data for the Bricks in the game level. getGameStatus public GameState getGameStatus() Retrieves state information about the game's current progress based on the last simulated step. Returns: The appropriate state if the user has won or LOST the game. If neither, PLAYING will be reported

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions