Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Structure Because you will be working on the same project all semester, it is extremely important to organize it correctly from the beginning. Pay

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Program Structure Because you will be working on the same project all semester, it is extremely important to organize it correctly from the beginning. Pay careful attention to the class structure described below and make sure your program follows this structure accurately The primary class in the program encapsulates the notion of a Game. A game in turn contains several components, including (1) a GameWorld which holds a collection of game objects and other state variables, and (2) a play) method to accept and execute user commands. Later, we will learn that a component such as GameWorld that holds the program's data is often called a model The top-level Game class also manages the flow of control in the game (such a class is therefore sometimes called a controller). The controller enforces rules such as what actions a player may take and what happens as a result. This class accepts input in the form of keyboard commands from the human player and invokes appropriate methods in the game world to perform the requested commands-that is, to manipulate data in the game model. In this first version of the program the top-level Game class will also be responsible for displaying information about the state of the game. In future assignments we will learn about a separate kind of component called a view which will assume that responsibility When you create your CN1 project, you should name the main class as Starter. Then you should modify the start) method of the Starter class so that it would construct an instance of the Game class. The other methods in Starter (i.., init(), stop), destroy()) should not be altered or deleted. The Game class must extend from the build-in Form class (which ives in com.codenamel.ui package). The Game constructor instantiates a GameWorld calls a GameWorld method init) to set the initial state of the game, and then starts the 1 of 13 game by calling a Game method play. The play )method then accepts keyboard commands from the player and invokes appropriate methods in GameWorld to manipulate and display the data and game state values in the game model. Since CN1 does not support getting keyboard input from command prompt (i.e., the standard input stream, System.in supported in Java is not available in CN1) the commands will be entered via a text field added to the form (the Game class). Refer to "Appendix - CN1 Notes" for the code that accepts keyboard commands through the text field located on the form. The following shows the pseudo-code implied by the above description. It is important for things that we will do later that your program follows this o rganization: class Starter //other methods import com.codenamel.ui.Form; public class Game extends Formt public void starto private GameWorld gw public Game ) if (current !nul1) current. show) return gw new GameWorld () gw.init) play ) new Game) //other methods private void play) // code here to accept and /execute user commands that // operate on the game world //(refer to "Appendix CN1 //Notes" for accepting //keyboard commandsvia a text //field located on the form) public class GameWorld ( public void initot //code here to create the //initial game objects/setup /additional methods here to //manipulate world objects and // related game state data Game World Objects For now, assume that the game world size is fixed and covers 1024(width) x 768(height) area (although we are going to change this later). The origin of the "world" (location (0,0)) is the lower left hand corner. The game world contains a collection which aggregates objects of abstract type GameObject. There are two kinds of abstract game objects called: "fixed objects" of type Fixed with fixed locations (which are fixed in place) and "moveable objects" of type Movable with changeable locations (which can move or be moved about the world). For this first version of the game there are two concrete types that fixed objects are instantiated from which are called: Base and Energy Station; and there are two concrete types that moveable objects are instantiated from which are called: Robot and Drone. Later we may add other kinds of game objects (both fixed kinds and moveable kinds) as well The various game objects have attributes (fields) and behaviors (methods) as defined below. These definitions are requirements which must be properly implemented in your program. All game objects have an integer attribute size. All game objects provide the ability for external code to obtain their size. However, they do not provide the ability to have their size changed once it is created. As will be specified in the later assignments, each type of game 2 of 13 object has a different shape which can be bounded by a square. The size attribute provides the length of this bounding square. All bases and all robots have the same size (chosen by you), assigned when they are created (e.g, size of all bases can be 10 and size of all robots can be 40). Sizes of the rest of the game objects are chosen randomly when created, and constrained to a reasonable positive integer value (e.g., between 10 to 50). For instance, size of one of the energy station may be 15 while size of energy station can may be 20 All game objects have a location, defined by floating point(you can use float or double to represent it) non-negative values X and Y which initially should be in the range 0.0 to 1024.0 and 0.0 to 768.0, respectively. The point (X,Y) is the center of the object. Hence, initial locations of all game objects should always be set to values such that the objects centers are contained in the world. All game objects provide the ability for external code to obtain their location. By default, game objects provide the ability to have their location changed, unless it is explicitly stated that a certain type of game object has a location which cannot be changed once it is created. Except bases and robots, initial locations of all the game objects should be assigned randomly when created * All game objects have a color, defined by a int value (use static rgb ) method of CN1's built-in ColorUtil class to generate colors). All objects of the same class have the same color (chosen by you), assigned when the object is created (e.g, bases could be blue, robots could be red, energy stations can be green). All game objects provide the ability for external code to obtain their color. By default, game objects provide the ability to have their color changed, unless it is explicitly stated that a certain type of game object has a color which cannot be changed once it is created * Bases are fixed game objects that have attribute sequenceNumber. Each base is a numbered marker that acts as a "waypoint" on the track; following the track is accomplished by moving over the top of bases in sequential order. Bases are not allowed to change color once they are created. All bases should be assigned to locations chosen by you, when they are created Energy stations are fixed game objects that have an attribute capacity (amount of energy an energy station contains). The initial capacity of the energy station is proportional to its size. If the player robot is running low on energy, it must go to an energy station that is not empty before it runs out of energy; otherwise it cannot move * All fixed game objects are not allowed to change location once they are created Drones are moveable (but not steerable) objects which fly over the track. They add (or subtract) small random values (e.g., 5 degrees) to their heading while they move so as to not run in a straight line. If the drone's center hits a side of the world, it changes heading and does not move out of bounds. If a drone flies directly over a robot it causes damage to the robot; the damage caused by a drone is half the damage caused by colliding with another robot but otherwise affects the performance of the robot in the same way as described above. Drones are not allowed to change color once they are created. Speed of 4 of 13 drones should be initialized to a reasonable random value (e.g., ranging between 5 and 10) at the time of instantiation. Heading of drones should be initialized to a random value (ranging between 0 and 359) at the time of instantiation. The preceding paragraphs imply several associations between classes: an inheritance hierarchy, interfaces such as for steerable objects, and aggregation associations between objects and where they are held. You are to develop a UML diagram for the relationships, and then implement it in CN1. Appropriate use of encapsulation, inheritance, aggregation, abstract classes, and interfaces are important grading criteria. Note that an additional important criterion is that another programmer must not be able to misuse your classes, e.g., if the object is specified to have a fix color, another programmer should not be able to change its color after it is instantiated You must use a tool to draw your UML (e.g., Violet or any other UML drawing tool) and output your UML as a pdf file (e.g., print your UML to a pdf file). Your UML must show al important associations between your entities (and important built-in classes that your entities have associations with) and utilize correct graphical notations. For your entities you must use three-box notation and show all the important fields and methods. You must indicate the visibility modifiers of your fields and methods, but you are not required to show parameters in methods and return types of the methods me When the game starts the player has three "lives" (chances to reach the last base). The game has a clock which counts up starting from zero; in this first version of the game the objective is to have the player robot complete the track (which starts from the first base and ends at the last base) in the minimum amount of time. Currently, there is only one robot (the player robo inthe gme. Later wedothe robots (non-player robots) and the objective will also include completing the track before the other robots do The player uses keystroke commands to turn the robot's steering wheel; this can cause the robot's heading to change (turning the steering wheel only effects the robot's heading under certain conditions; see above). The robot moves one unit at its current speed in the direction it is currently heading each time the game clock "ticks" (see below) The robot starts out at the first base (#1). The player must move the robot so that it intersects the bases in increasing numerical order. Each time the robot reaches the next higher-numbered base, the robot is deemed to have successfully moved that far along the track and its lastBaseReached field is updated. Intersecting bases out of order (that is, reaching a base whose number is more than one greater than the most recently reached base or whose number is less than or equal to the most recently reached base) has no effect on the ame The energy level of the robot continually goes down as the game continues (energy level goes down even if the robot has zero speed since the electronics on the robot is continually working). If the robot's energy level reaches zero it can no longer move. The player must therefore occasionally move the robot off the track to go to (intersect with) an energy station, which has the effect of increasing the robot's energy level by the capacity of the energy station. After the robot intersects with the energy station, the capacity of that energy station is reduced to zero and a new energy station with randomly-specified size and location is added into the game Collisions with other robots or with drones cause damage to the robot; if the robot sustains too much damage it can no longer move. If the robot can no longer move (i.e., due to having maximum damage or no energy), the game stops, the player "loses a life", and the game world is re-initialized (but the number of clock ticks is not set back to zero). When the player loses all three lives the game ends and the program exits by printing the following text message in console: "Game over, you failed!". If the player robot reaches the last base on the track, the game also ends with the following message displayed on the console: "Game over you win! Total time: #, where # indicates the number of clock ticks it took the player robot to reach the last flag on the track since the start of the game. In later versions of the game, if a non-player robot reaches the last base before the player does, the game will also end with the following message displayed on the console: "Game over, a non-player robot wins!" The program keeps track of following "game state" values: current clock time and lives remaining. Note that these values are part of the model and therefore belong in the GameWorld class. Commands Once the game world has been created and initialized, the Game constructor is to call a method name play) to actually begin the game. play accepts single-character commands from the player via the text field located on the form (the Game class) as indicated in the "Appendix C1 Notes Any undefined or illegal input should generate an appropriate error message on the console and ignore the input. Single keystrokes invoke action the human hits "enter" after typing each command. The allowable input commands and their meanings are defined below (note that commands are case sensitive): "a' - tell the game world to accelerate (immediately increase the speed of) the player robot by a small amount. Note that the effect of acceleration is to be limited based on damage level energy level, and maximum speed as described above b-tell the game world to brake (immediately reduce the speed of) the player robot by a small amount. Note that the minimum speed for a robot is zero .(the letter "ell")- tell the game world to change the steering direction of the player robot by 5 degrees to the left (in the negative direction on the compass). Note that this changes the direction of the robot's steering wheel; it does not directly (immediately) affect the robot's heading. See the tick" command, below Y-tell the game world to change the steering direction of the player robot by 5 degrees to the right (in the positive direction on the compass). As above, this changes the direction of the robot's steering wheel, not the robot's heading . 'c-PRETEND that the player robot has collided with some other robot, tell the game world that this collision has occurred. (For this version of the program we won't actually have any other robot in the simulation, but we need to provide for testing the effect of such collisions.) Colliding with another robot increases the damage level of the player robot and fades the color of the robot (i.e., the robot color becomes lighter red-throughout the game, the robot will have different shades of red); if the damage results in the player robot not being able to move then the game stops (the player loses a life). 6 of 13 'a number between 1-9-PRETEND that the player robot has collided with the base number x (which must have a value between 1-9): tell the game world that this collision has occurred. The effect of moving over a base is to check to see whether the number x is exactly one greater than the base indicated by lastBaseReached field of the robot and if so to record in the robot the fact that the robot has now reached the next sequential base on the track (update the lastBaseReached field of the robot) 'e-PRETEND that the player robot has collided with (intersected with) an energy station; tell the game world that this collision has occurred. The effect of colliding an energy station is to increase the robot's energy level by the capacity of the energy station, reduce the capacity of the energy station to zero, fade the color of the energy station (e.g., change it to light green) and add a new energy station with randomly-specified size and location into the game .g' - PRETEND that a drone has flown over (collided with, gummed up) the player robot. The effect of colliding with a drone is to increase the damage to the robot as described above under the description of drones and fades the color of the robot (i.e., the robot color becomes lighter red) 't-tell the game world that the-game clock" has ticked. A clock tick in the game world has the following effects: (1) if the player robot moves (e.g., did not run out of energy or does not have the maximum damage or zero speed), then the robot's heading should be incremented or decremented by the robot's steeringDirection (that is, the steering wheel turns the robot) (2) Drones also update their heading as indicated above. (3) all moveable objects are told to update their positions according to their current heading and speed, and (4) the robot's energy level is reduced by the amount indicated by its energyConsumptionRate. (5) the elapsed time "game clock" is incremented by one (the game clock for this assignment is simply a variable which increments with each tick) d -generate a display by outputting lines of text on the console describing the current game/player-robot state values. The display should include (1) the number of lives left, (2) the current clock value (elapsed time), (3) the highest base number the robot has reached sequentially so far, (4) the robot's current energy level and (5) robot's current damage level All output should be appropriately labeled in easily readable format. m-tell the game world to output a "map" showing the current world (see below) X-exit, by calling the method system .exit (0) to terminate the program. Your program should confirm the user's intent (see 'y and 'n' commands below) to quit before actually exiting y-user has confirmed the exit by saying yes . n'-user has not confirmed the exit by saying no semester, your program will determine these collisions automatically1. Some of commands above indicate that you PRETEND a collision happens, Later this In later assignments we will see how to actually detect on-screen collisions such as this; for now we are simply relying on the user to tell the program via a command when collisions have occurred. Inputting a collision command is deemed to be a statement that the collision occurred; it does not matter where objects involved in the collision actually happen to be for this version of the game as long as they exist in the game. 7 of 13 methoa The code to perform each command must be encapsulated in a separate method When the Game gets a command which requires manipulating the GameWorld, the Game must invoke a method in the GameWorld to perform the manipulation (in other words, it is not appropriate for the Game class to be directly manipulating objects in the GameWorld, it must do so by calling an appropriate GameWorld method). The methods in GameWorld, might in turn call other methods that belong to other classes tab manpug tbe Game When the player enters any of the above commands, an appropriate message should be displayed in console (e.g., after 'b' is entered, print to console something like "breaks are applied") Program Structure Because you will be working on the same project all semester, it is extremely important to organize it correctly from the beginning. Pay careful attention to the class structure described below and make sure your program follows this structure accurately The primary class in the program encapsulates the notion of a Game. A game in turn contains several components, including (1) a GameWorld which holds a collection of game objects and other state variables, and (2) a play) method to accept and execute user commands. Later, we will learn that a component such as GameWorld that holds the program's data is often called a model The top-level Game class also manages the flow of control in the game (such a class is therefore sometimes called a controller). The controller enforces rules such as what actions a player may take and what happens as a result. This class accepts input in the form of keyboard commands from the human player and invokes appropriate methods in the game world to perform the requested commands-that is, to manipulate data in the game model. In this first version of the program the top-level Game class will also be responsible for displaying information about the state of the game. In future assignments we will learn about a separate kind of component called a view which will assume that responsibility When you create your CN1 project, you should name the main class as Starter. Then you should modify the start) method of the Starter class so that it would construct an instance of the Game class. The other methods in Starter (i.., init(), stop), destroy()) should not be altered or deleted. The Game class must extend from the build-in Form class (which ives in com.codenamel.ui package). The Game constructor instantiates a GameWorld calls a GameWorld method init) to set the initial state of the game, and then starts the 1 of 13 game by calling a Game method play. The play )method then accepts keyboard commands from the player and invokes appropriate methods in GameWorld to manipulate and display the data and game state values in the game model. Since CN1 does not support getting keyboard input from command prompt (i.e., the standard input stream, System.in supported in Java is not available in CN1) the commands will be entered via a text field added to the form (the Game class). Refer to "Appendix - CN1 Notes" for the code that accepts keyboard commands through the text field located on the form. The following shows the pseudo-code implied by the above description. It is important for things that we will do later that your program follows this o rganization: class Starter //other methods import com.codenamel.ui.Form; public class Game extends Formt public void starto private GameWorld gw public Game ) if (current !nul1) current. show) return gw new GameWorld () gw.init) play ) new Game) //other methods private void play) // code here to accept and /execute user commands that // operate on the game world //(refer to "Appendix CN1 //Notes" for accepting //keyboard commandsvia a text //field located on the form) public class GameWorld ( public void initot //code here to create the //initial game objects/setup /additional methods here to //manipulate world objects and // related game state data Game World Objects For now, assume that the game world size is fixed and covers 1024(width) x 768(height) area (although we are going to change this later). The origin of the "world" (location (0,0)) is the lower left hand corner. The game world contains a collection which aggregates objects of abstract type GameObject. There are two kinds of abstract game objects called: "fixed objects" of type Fixed with fixed locations (which are fixed in place) and "moveable objects" of type Movable with changeable locations (which can move or be moved about the world). For this first version of the game there are two concrete types that fixed objects are instantiated from which are called: Base and Energy Station; and there are two concrete types that moveable objects are instantiated from which are called: Robot and Drone. Later we may add other kinds of game objects (both fixed kinds and moveable kinds) as well The various game objects have attributes (fields) and behaviors (methods) as defined below. These definitions are requirements which must be properly implemented in your program. All game objects have an integer attribute size. All game objects provide the ability for external code to obtain their size. However, they do not provide the ability to have their size changed once it is created. As will be specified in the later assignments, each type of game 2 of 13 object has a different shape which can be bounded by a square. The size attribute provides the length of this bounding square. All bases and all robots have the same size (chosen by you), assigned when they are created (e.g, size of all bases can be 10 and size of all robots can be 40). Sizes of the rest of the game objects are chosen randomly when created, and constrained to a reasonable positive integer value (e.g., between 10 to 50). For instance, size of one of the energy station may be 15 while size of energy station can may be 20 All game objects have a location, defined by floating point(you can use float or double to represent it) non-negative values X and Y which initially should be in the range 0.0 to 1024.0 and 0.0 to 768.0, respectively. The point (X,Y) is the center of the object. Hence, initial locations of all game objects should always be set to values such that the objects centers are contained in the world. All game objects provide the ability for external code to obtain their location. By default, game objects provide the ability to have their location changed, unless it is explicitly stated that a certain type of game object has a location which cannot be changed once it is created. Except bases and robots, initial locations of all the game objects should be assigned randomly when created * All game objects have a color, defined by a int value (use static rgb ) method of CN1's built-in ColorUtil class to generate colors). All objects of the same class have the same color (chosen by you), assigned when the object is created (e.g, bases could be blue, robots could be red, energy stations can be green). All game objects provide the ability for external code to obtain their color. By default, game objects provide the ability to have their color changed, unless it is explicitly stated that a certain type of game object has a color which cannot be changed once it is created * Bases are fixed game objects that have attribute sequenceNumber. Each base is a numbered marker that acts as a "waypoint" on the track; following the track is accomplished by moving over the top of bases in sequential order. Bases are not allowed to change color once they are created. All bases should be assigned to locations chosen by you, when they are created Energy stations are fixed game objects that have an attribute capacity (amount of energy an energy station contains). The initial capacity of the energy station is proportional to its size. If the player robot is running low on energy, it must go to an energy station that is not empty before it runs out of energy; otherwise it cannot move * All fixed game objects are not allowed to change location once they are created Drones are moveable (but not steerable) objects which fly over the track. They add (or subtract) small random values (e.g., 5 degrees) to their heading while they move so as to not run in a straight line. If the drone's center hits a side of the world, it changes heading and does not move out of bounds. If a drone flies directly over a robot it causes damage to the robot; the damage caused by a drone is half the damage caused by colliding with another robot but otherwise affects the performance of the robot in the same way as described above. Drones are not allowed to change color once they are created. Speed of 4 of 13 drones should be initialized to a reasonable random value (e.g., ranging between 5 and 10) at the time of instantiation. Heading of drones should be initialized to a random value (ranging between 0 and 359) at the time of instantiation. The preceding paragraphs imply several associations between classes: an inheritance hierarchy, interfaces such as for steerable objects, and aggregation associations between objects and where they are held. You are to develop a UML diagram for the relationships, and then implement it in CN1. Appropriate use of encapsulation, inheritance, aggregation, abstract classes, and interfaces are important grading criteria. Note that an additional important criterion is that another programmer must not be able to misuse your classes, e.g., if the object is specified to have a fix color, another programmer should not be able to change its color after it is instantiated You must use a tool to draw your UML (e.g., Violet or any other UML drawing tool) and output your UML as a pdf file (e.g., print your UML to a pdf file). Your UML must show al important associations between your entities (and important built-in classes that your entities have associations with) and utilize correct graphical notations. For your entities you must use three-box notation and show all the important fields and methods. You must indicate the visibility modifiers of your fields and methods, but you are not required to show parameters in methods and return types of the methods me When the game starts the player has three "lives" (chances to reach the last base). The game has a clock which counts up starting from zero; in this first version of the game the objective is to have the player robot complete the track (which starts from the first base and ends at the last base) in the minimum amount of time. Currently, there is only one robot (the player robo inthe gme. Later wedothe robots (non-player robots) and the objective will also include completing the track before the other robots do The player uses keystroke commands to turn the robot's steering wheel; this can cause the robot's heading to change (turning the steering wheel only effects the robot's heading under certain conditions; see above). The robot moves one unit at its current speed in the direction it is currently heading each time the game clock "ticks" (see below) The robot starts out at the first base (#1). The player must move the robot so that it intersects the bases in increasing numerical order. Each time the robot reaches the next higher-numbered base, the robot is deemed to have successfully moved that far along the track and its lastBaseReached field is updated. Intersecting bases out of order (that is, reaching a base whose number is more than one greater than the most recently reached base or whose number is less than or equal to the most recently reached base) has no effect on the ame The energy level of the robot continually goes down as the game continues (energy level goes down even if the robot has zero speed since the electronics on the robot is continually working). If the robot's energy level reaches zero it can no longer move. The player must therefore occasionally move the robot off the track to go to (intersect with) an energy station, which has the effect of increasing the robot's energy level by the capacity of the energy station. After the robot intersects with the energy station, the capacity of that energy station is reduced to zero and a new energy station with randomly-specified size and location is added into the game Collisions with other robots or with drones cause damage to the robot; if the robot sustains too much damage it can no longer move. If the robot can no longer move (i.e., due to having maximum damage or no energy), the game stops, the player "loses a life", and the game world is re-initialized (but the number of clock ticks is not set back to zero). When the player loses all three lives the game ends and the program exits by printing the following text message in console: "Game over, you failed!". If the player robot reaches the last base on the track, the game also ends with the following message displayed on the console: "Game over you win! Total time: #, where # indicates the number of clock ticks it took the player robot to reach the last flag on the track since the start of the game. In later versions of the game, if a non-player robot reaches the last base before the player does, the game will also end with the following message displayed on the console: "Game over, a non-player robot wins!" The program keeps track of following "game state" values: current clock time and lives remaining. Note that these values are part of the model and therefore belong in the GameWorld class. Commands Once the game world has been created and initialized, the Game constructor is to call a method name play) to actually begin the game. play accepts single-character commands from the player via the text field located on the form (the Game class) as indicated in the "Appendix C1 Notes Any undefined or illegal input should generate an appropriate error message on the console and ignore the input. Single keystrokes invoke action the human hits "enter" after typing each command. The allowable input commands and their meanings are defined below (note that commands are case sensitive): "a' - tell the game world to accelerate (immediately increase the speed of) the player robot by a small amount. Note that the effect of acceleration is to be limited based on damage level energy level, and maximum speed as described above b-tell the game world to brake (immediately reduce the speed of) the player robot by a small amount. Note that the minimum speed for a robot is zero .(the letter "ell")- tell the game world to change the steering direction of the player robot by 5 degrees to the left (in the negative direction on the compass). Note that this changes the direction of the robot's steering wheel; it does not directly (immediately) affect the robot's heading. See the tick" command, below Y-tell the game world to change the steering direction of the player robot by 5 degrees to the right (in the positive direction on the compass). As above, this changes the direction of the robot's steering wheel, not the robot's heading . 'c-PRETEND that the player robot has collided with some other robot, tell the game world that this collision has occurred. (For this version of the program we won't actually have any other robot in the simulation, but we need to provide for testing the effect of such collisions.) Colliding with another robot increases the damage level of the player robot and fades the color of the robot (i.e., the robot color becomes lighter red-throughout the game, the robot will have different shades of red); if the damage results in the player robot not being able to move then the game stops (the player loses a life). 6 of 13 'a number between 1-9-PRETEND that the player robot has collided with the base number x (which must have a value between 1-9): tell the game world that this collision has occurred. The effect of moving over a base is to check to see whether the number x is exactly one greater than the base indicated by lastBaseReached field of the robot and if so to record in the robot the fact that the robot has now reached the next sequential base on the track (update the lastBaseReached field of the robot) 'e-PRETEND that the player robot has collided with (intersected with) an energy station; tell the game world that this collision has occurred. The effect of colliding an energy station is to increase the robot's energy level by the capacity of the energy station, reduce the capacity of the energy station to zero, fade the color of the energy station (e.g., change it to light green) and add a new energy station with randomly-specified size and location into the game .g' - PRETEND that a drone has flown over (collided with, gummed up) the player robot. The effect of colliding with a drone is to increase the damage to the robot as described above under the description of drones and fades the color of the robot (i.e., the robot color becomes lighter red) 't-tell the game world that the-game clock" has ticked. A clock tick in the game world has the following effects: (1) if the player robot moves (e.g., did not run out of energy or does not have the maximum damage or zero speed), then the robot's heading should be incremented or decremented by the robot's steeringDirection (that is, the steering wheel turns the robot) (2) Drones also update their heading as indicated above. (3) all moveable objects are told to update their positions according to their current heading and speed, and (4) the robot's energy level is reduced by the amount indicated by its energyConsumptionRate. (5) the elapsed time "game clock" is incremented by one (the game clock for this assignment is simply a variable which increments with each tick) d -generate a display by outputting lines of text on the console describing the current game/player-robot state values. The display should include (1) the number of lives left, (2) the current clock value (elapsed time), (3) the highest base number the robot has reached sequentially so far, (4) the robot's current energy level and (5) robot's current damage level All output should be appropriately labeled in easily readable format. m-tell the game world to output a "map" showing the current world (see below) X-exit, by calling the method system .exit (0) to terminate the program. Your program should confirm the user's intent (see 'y and 'n' commands below) to quit before actually exiting y-user has confirmed the exit by saying yes . n'-user has not confirmed the exit by saying no semester, your program will determine these collisions automatically1. Some of commands above indicate that you PRETEND a collision happens, Later this In later assignments we will see how to actually detect on-screen collisions such as this; for now we are simply relying on the user to tell the program via a command when collisions have occurred. Inputting a collision command is deemed to be a statement that the collision occurred; it does not matter where objects involved in the collision actually happen to be for this version of the game as long as they exist in the game. 7 of 13 methoa The code to perform each command must be encapsulated in a separate method When the Game gets a command which requires manipulating the GameWorld, the Game must invoke a method in the GameWorld to perform the manipulation (in other words, it is not appropriate for the Game class to be directly manipulating objects in the GameWorld, it must do so by calling an appropriate GameWorld method). The methods in GameWorld, might in turn call other methods that belong to other classes tab manpug tbe Game When the player enters any of the above commands, an appropriate message should be displayed in console (e.g., after 'b' is entered, print to console something like "breaks are applied")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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