This is needed to be in C++, please! And as soon as youpossibly can! I am confused on it all!
Objective
The objective of this lab is to enhance the effect of the shipafterburner by utilizing a series of delayed events to produce ashadowing effect. The use of the Command and Composite designpatterns help us to store and distribute these delayed events to anencapsulated hierarchy of Ship objects. This lab demonstrates theuse of the object-oriented principles of abstraction, hierarchy,encapsulation, modularity and polymorphism to extend the existingShip class and its functionality transparently. Instructions Youshould start by creating the command and composite classes. Createfiles for them in the model folder on the hard drive, add them tothe model filter in the project, and stage them in source controlto begin tracking their changes. Next, setup the delayed events forthe effect. Finally, integrate the new classes and update all codeto reflect system changes.
Diagrams
1. The provided class diagram depicts how the composite andcommand patterns will be integrated into the existing solution.
2. The provided sequence diagrams demonstrate how a commandobject is created and executed. Branch Create a branch calledCompositeShadows-Work from your master branch and switch to it.
Base Command
1. Create a class called BaseCommand. This class shouldcontain:
a. A target (Ship *) to Execute thecommand on.
b. A float for the time delay forwhen to execute the command.
2. Create accessors and mutators for the BaseCommandmembers.
3. Create a pure virtual Execute method.
Heading Command
1. Create a class called HeadingCommand that derives fromBaseCommand. This class should contain a float for the heading(direction of facing).
2. Create an accessor and mutator for the HeadingCommandmember.
3. Override the Execute method to invoke the SetHeading methodon the target (see BaseCommand 1a.) using the float member for theheading value.
Velocity Command
1. Create a class called VelocityCommand that derives fromBaseCommand. This class should contain a couple of floats for thevelocity.
2. Create accessors and mutators for the VelocityCommandmembers.
3. Override the Execute method to invoke the SetVelocity methodon the target (see BaseCommand 1a.) using the two float members forparameters.
Composite
1. Create a class named MotherShip that derives from the Shipclass with no default constructor.
a. Create a constructor thatutilizes a constant Ship reference (const Ship &) parameter toinvoke the parent Ship copy constructor via initializer list.
2. Add a vector of Ship pointers to the MotherShip class. a.Create a public method for adding a passed in “shadow” (Ship)pointer to this container.
3. In the MotherShip’s Heartbeat method update the MotherShip(invoke the parent Heartbeat method) and if the afterburner flag ison invoke the Heartbeat method on all shadows.
4. Have the destructor of the MotherShip clean up theViewManager references and memory used by its shadows.
Delayed Commands
1. We are going to produce our shadow effect via delayedcommands. Start accomplishing this by adding a vector ofBaseCommand pointers in MotherShip.
2. Within the MotherShip’s Heartbeat method, if the MotherShip’safterburner flag is on, do the following for each shadow:
a. Create a VelocityCommandobject with the MotherShip’s velocity
b. Create a HeadingCommandobject with the MotherShip’s heading.
c. The delay parameter foreach command is the amount of time in seconds to wait beforeexecuting the command (0.05 or less is a good number for the firstheading and velocity commands, 0.10 for the second set of commands,0.15 for the third, etc.).
3. Next create a private method in MotherShip that will processcommands in our list/vector. This method should take in a float asa parameter that will serve as change in time.
a. Use the passed in float toreduce the delay value for each command. If a delay value fallsbelow zero, execute it, then clean up any memory it uses, andremove the command from the list/vector.
b. Be careful how you loopthrough your command container; don’t skip the processing of anycommand by incrementing your index when removing an item fromit.
c. Invoke this method in theMotherShip’s Heartbeat method if the afterburner flag is on.
4. Generate a private clean up method that removes and cleans upthe memory for all contained commands.
a. Have this method also setthe velocities of all shadows to zero and their positions andheadings to that of the MotherShip.
b. Invoke this method in thedestructor of the MotherShip and in the MotherShip’s Heartbeatmethod if the afterburner flag is off.
Integration
1. Update the player ship creation code to create a MotherShipobject and store inside of it five Ship type objects (shadows.) Youdo not need to alter the return value of this method.
a. You will need to use thereturn value from CloneShipFromPrototype() to invoke theMotherShip’s constructor. You will also need to delete the Shipthat was returned and remove the reference in the ViewManagercreated by this function. Pseudo code example (this code will notcompile as-is): Ship*deleteme=SaiphApp::CloneShipFromPrototype(SaiphApp::GetShipID())MotherShip *player = new MotherShip(*deleteme)ViewManager::RemoveObject(deleteme) delete deletemeViewManager::AddObject(player, 2)
b. Create 5 Ship objects anduse the MotherShip’s AddShadow method to add them to theMotherShip’s container.
i. These objects should be created using theaforementioned CloneShipFromPrototype method with the same ship IDas the MotherShip.
ii. Views for all shadows must be added tolayer one so they will not be drawn on top of the MotherShip. Note:The CloneShipFromPrototype() method will accept a layer number as asecond parameter and create the views for you.
iii. Set the shadows to a color different thanwhite. Color channels range between 0 and 1 (NOT 0 and 255).
2. Compile and Test
End Result
Your finished code should have new behavior. When afterburnersare used, shadows will start to follow the player ship, thus givingthe illusion that the player is moving even faster.
This is needed to be in C++, please! And as soon as you possibly can! I am confused on it all! Objective The objective o
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am