Question
Implement a code using codename1, that all output will be in text on the console; no graphical output is required.The map (generated by the m
Implement a code using codename1, that all output will be in text on the console; no graphical output is required.The map (generated by the m command) will simply be a set of lines describing the objects currently in the world, similar to the following:
Player Ship: loc=130.0,565.5 color=[0,255,0] speed=8 dir=90 missiles=5 Missile launcher dir = 50PSs Missile: loc=180.3,100.0 color=[255,0,0] speed=10 dir=112 fuel=7 NPSs Missile: loc=50.9,540.2 color=[255,0,0] speed=5 dir=313 fuel=1 Non-Player Ship: loc=640.2,20.0 color=[128,128,128] speed=6 dir=20 size=10
Asteroid: loc=440.2,20.0 color=[128,128,128] speed=6 dir=0 size=6 Asteroid: loc=660.0,50.0 color=[128,128,128] speed=1 dir=90 size=26 Station: loc=210.2,800.0 color=[255,255,0] rate=4
Using the requirements from page 2-4
.A PS owns a MissileLauncher. It is a steerable object whose speed and location is the same as a PS. However, a direction of a MissileLauncher can be different from a PS. There is only one MissileLauncher per PS. Its initial location should be at the center of the world with speed of zero and heading of north. Graphically, in future Assignment 3 (a3)-not in this assignment, a Misslelauncher can be appeared like destroyed and removed from the game, and the user scores some points (you may decide how many). If a player ship collides with an asteroid, the ship and the asteroid are destroyed and the player loses one Tife". A complete game consists of playing until three player ships have been destroyed this when initialized: Fixed objects have unique integer identification (id) numbers; every fixed object (of any subtype) has an integer id which is different from that of every other fixed object. (Note that this is an appropriate place to use a static int in a Java class; such a value can be used to keep track of the next available id number each time an instance of the cass is constructed.) The program must enforce the rule that it is not possible to change either the ID number or the location of a fixed object once it has been created Rotation Clockwise MissileLauncher (straight line) Space stations are fixed objects that have an attribute called their bNnk rate; each space station blinks on and off at this rate (blink rate specifies the period, a blink rate of 4, for example, means the light on the space station is on for four seconds and then off for four seconds). Blink rate is initialized to a random value between zero and four, Space stations also house an unlimited supply of missiles; any ship arriving at a space station automatically gets a full resupply of missiles (up to the maximum number of missies a ship can hold) Player Ship (Triangle shape) Both classes, PlayerShip and MissileLauncher are required to have a composition elation The preceding paragraphs imply several associations between classes: an inhertance hierarchy, interfaces such as for steerable and moving objects, and aggregation associations between objects and where they are held. You must first develop a UML diagram for the relationships, and then implement it in a Java/CN1 program. Appropriate use of encapsulation, inheritance, aggregation, abstract dasses, and interfaces are important grading criteria. Non-Player Ship(s) (NPS) is NOT steerable objects. NPS(s) are movable objects that fly through space at a fixed speed and directionNPS(s) also have a fixed attribute size (small 10 or large 20), an integer giving the dimensions of the NPS(s). The size (small or large), speed, and direction of a NPS are to be randomly generated when it is created. If a player's missile collides with a NPS, the NPS (and the missile) are destroyed and removed from the game, and the user scores some points (you may decide how many). If a PS collides with a NPS, the PS and the NPS are destroyed and the player loses one life". A complete game consists of playing untl three PS have been destroyed. A NPS also has a MissileLauncher. However, it is not steerable. It has a same direction a NPS A NPS can randomly fires missile at PS (a maximum of 2). If a NPS's missile collides with a PS, the player loses one life and a missile is removed from the game * You must use a tool to draw your UML (e.g., Violet or any other UML drawing too) and output your UML as a pdf file (e.g., print your UML to a pdf file). Your UML must show all important associations between your entities and utilize correct graphical notations. For your entities, you must use three-box notation (as mentioned in lecture) 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. When your program begins, there are no objects in the world. The player can enter Missiles are moveable objects that are fired from ships's MissileLauncher, when a missile is fired, it has a direction matching its ship's MissileLauncher (that is, missiles are fired out the front of a launcher), and a speed that is some fixed amount greater than the speed of its ship (you may decide the amount) Missiles also have an attribute called fuel level, a postive integer representing the number of tme units left before the missile becomes dead and disappears. A missile's fuel level gets decremented as time passes, and when it reaches zero the missile is removed from the game. All missiles have an initial fuel level of 10. Note that while missiles are moveable, they are not steerable; that is, there is no way to change a missile's speed or heading once it is fired. The program must enforce this constraint commands (see below) to control various aspects of the game such as adding objects, moving the ship, firing missiles, etc. The game keeps track of time using a dock, which is simply an integer counter. The objectve is to achieve the highest possible score in the minimum amount of time - that is, to destroy as many asteroids and NPS(s) as possible, flying to a space station to restock missiles as necessary, without losng ships, all in minimum time Once the game world has been created and initialized, the Game constructor is to call a method name play) to actually begin the game.play0 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 Asteroids are movable objects that tumble through space at a fixed speed and direction Asteroids also have a fixed attrbute size (range 6.30-Note: We will relax this assumption in later assignment), an integer giving the dimensions of the asteroid. The size, speed, and direction of an asterold are to be randomly generated when the asteroid is created. If a PS's missile collides with an asteroid, the asteroid (and the missle) are * 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. Additionally, any input condition where a function cannot be carried out, your program must output an error text. For example, user inputs a 'd' (decrease a Page 4 of 12 speed of a player ship) command where a command (add a player ship to the world) was not initiated before. The allowable input commands and their meanings are defined below (note that commands are case sensitive may choose any missile and any NPS to be removed; later we'll worry about missiles needing to be "close to their victims. E-a NPS's missile has struck and Exploded a Ps; tell the game world to remove a missile a'- add a new asteroid to the world y - add a NPS to the world b'-add a new blinking space station to the world s'-add a PS to the world i-increase the speed of the PS by a small amount. d'- decrease the speed of the PS by a small amount, as long as doing so doesn't make the and a PS. You may choose any missile and to decrement the count of lves left; later we'll worry about missiles needing to be "close to" their victims. c'-the PS has grashed into an asteroid; tell the game world to remove the ship and an asteroid and to decrement the count of lives left if no lives are left then the game is over. You may choose any asteroid to be removed; later we'll worry about asteroids needing to be "close to, the ship h'-the PS has hit a NPS; tell the game world to remove the NPS and to decrement the count of lives left; if no lives are left then the game is over. You may choose any NPS to be removed; later we'll worry about NPS needing to be "close to" the PS speed go negative (the ship can't go backwards). (ell-tum PS left by a small amount (change the heading of the ship by a small amount in x- two asteroids have collided with and exterminated each other, tell the game world to the counter-clockwise direction). Note that determination of the actual new heading is not the responsibility of the game class; it simply instructs the game world that a change is to be made. remove two asteroids from the game. You may choose any two asteroids to be removed; later we'll worry about the asteroids needing to be "close to" each other. You may ignore collisions between NPSs r- turn PS right (change the ship heading by a small amount in the clockwise direction) I- one asteroid have collided and impacted the NPS, tell the game world to remove them from the game. You may choose one asteroid and one NPS to be removed; later we'l worry about the asteroid needing to be "dose to" NPS s' - a user controls the direction of the PS's MissileLauncher by revolving it about the center of the player ship in a clockwise direction. This command turns the MissileLauncher by small 0 angle. You decide a value t- tell the game world that the game clock has ticked. Each tick of the game dock has the following effects:ll moveable objects are told to update their positons according to their current direction and speed; (2) every missile's fuel level is reduced by one and any missies which are now out of fuel are removed from the game; (3) each space station toggles its blinking light if the tick count modulo the station's blink rate is zero; and (4) the "elapsed game time" is incremented by one -fire a missile out the front of the PS. lf the ship has no more missiles, an error message should be printed; otherwise, add to the world a new missile with a location, speed, and launchers heading determined by the ship 'L'- Launch a missile out the front of the NPS lf the ship has no more missiles, an error message should be printed; otherwise, add to the world a new missile with a location, p print a display (output lines of text) giving the current game state values, induding: (1) current score (number of points the player has earned), (2) number of missiles currenty in the ship, and (3) current elapsed time. Output should be well labeled in easy-to-read format. speed, and launcher's heading determined by the ship -jump through hyperspace. This command causes the ship to instantly jump to the initial default position in the middle of the screen, regardless of its current position. (This makes it easy to regain control of the ship after it has left visible space; later we wll see m-print a "map" showing the current world state (see below). q- guit, by calling the method System.exit (0) to terminate the program. Your program a different mechanism for viewing the ship when it is outside screen space.) should first confirm the user's intent to quit before exiting. n'-load a new supply of missiles into the PS. This increases the ship's missile supply to the maximum. It is permissible to reload missiles before all missiles have been fired, but it is not allowed for a ship to carry more than the maximum number of missiles. Note that normally the ship would actualy have to fly to a space station to reload; for this version of the game we will assume the station has transporters that can transfer .Each command must be encapsulated in a separate method in the Game class (later we will move those methods to other locations). Most of the game class command actions also invoke related actions in GameWorld. When the Game gets a command, it invokes one or more methods in the Game World, rather than itself manipulating game world objects All classes must be designed and implemented following the guidelines discussed in dass o All data fields must be private, o Accessors/mutators must be provided, but only where the design requires them, o Game world objects may only be manipulated by calling methods in the game world. It is new missiles to the ship regardless of its location. . k-a PS's missle has struck and kiled an asteroid; tell the game world to remove a missle and an asteroid and to increment the player's score by some amount of your choosing. You may choose any missile and asteroid to be removed; later we ll worry about missiles needing to be "close to their victims. e Page 6 of 12 never appropriate for the controler to directly manipulate game world data attributes - a PS's missile has struck and eiminated a NPS: tell the game world to remove a missile and a NPS and to increment the player's score by some amount of your choosing. You Moving objects need to determine their new location when their move) method is invoked, at each time tick (T command). The new location can be computed as follows: Further, you must verify that your program works properly from the command prompt before submitting it to Canvas: First make sure that the A1 Prj-jar file is up-to-date. If not, under eclipse, right cick on the dist directory and say "Refresh". Then get into the A1Prj directory and type in one ine)java pdistA 1Pr jar JavaSE.jar com.codename1.impl.javase.Simulator com.mycompany a1.Starter for Windows machines (for the command line arguments of Mac OS/Linux machines please refer to the dass notes). Alternatvely, to prove it is working, you can also run the instructor provided program RunAssignment.jar (see class notes). Substantial penalties will be applied to submissions which do not work properly from the command prompt newLocation x,y)-oldLocation(x, (deltax, deltaY), where deltax-cos() *speed eltaYsin (8) speed, and In this assignment, we are assuming time is fixed at one unit per Tick, so elapsed time is For this assignment, all output will be in text on the console; no "graphical output is required The map"(generated by the 'm' command) will simply be a set of lines describing the objects currently in the world, similar to the following: You are not required to use any particular data structure to store the game world objects, but all your game world objects must be stored in a single structure. In addition, your program must be able to handle changeable numbers of objects at runtime-soyou can't use a fixed- Consider either the Java ArrayList or Vector class for implementing this storage. Note that Java Vectors (and ArrayLists) hold elements of type "Object, but you will need to be able to treat the Objects differently depending on the type of object. You can use the "instanceof operator to determine the type of a given Object, but be sure to use it in a polymorphically safe way. For example, you can write a loop which runs through all the elements of a world Vector and processes each "movable" object with code like: Note that the appropriate mechanism for implementing this output is to override the tostring method in each concrete game object class so that it retums a String describing itself. See the coding notes Appendix (see page 11 below) for additional details, induding how to display single decimal value. Please be conformed to the format specified for (int 1-0: iStep 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