Home / Expert Answers / Computer Science / this-is-needed-to-be-in-c-please-and-as-soon-as-you-possibly-can-i-am-confused-on-it-all-nbsp-pa911

(Solved): This is needed to be in C++, please! And as soon as you possibly can! I am confused on it all!   ...



This is needed to be in C++, please! And as soon as you possibly can! I am confused on it all!

 

Objective

The objective of this lab is to enhance the effect of the ship afterburner by utilizing a series of delayed events to produce a shadowing effect. The use of the Command and Composite design patterns help us to store and distribute these delayed events to an encapsulated hierarchy of Ship objects. This lab demonstrates the use of the object-oriented principles of abstraction, hierarchy, encapsulation, modularity and polymorphism to extend the existing Ship class and its functionality transparently. Instructions You should start by creating the command and composite classes. Create files for them in the model folder on the hard drive, add them to the model filter in the project, and stage them in source control to begin tracking their changes. Next, setup the delayed events for the effect. Finally, integrate the new classes and update all code to reflect system changes.

Diagrams

1. The provided class diagram depicts how the composite and command patterns will be integrated into the existing solution.

2. The provided sequence diagrams demonstrate how a command object is created and executed. Branch Create a branch called CompositeShadows-Work from your master branch and switch to it.

Base Command

1. Create a class called BaseCommand. This class should contain:

        a. A target (Ship *) to Execute the command on.

        b. A float for the time delay for when to execute the command. 

2. Create accessors and mutators for the BaseCommand members.

3. Create a pure virtual Execute method.

Heading Command

1. Create a class called HeadingCommand that derives from BaseCommand. This class should contain a float for the heading (direction of facing).

2. Create an accessor and mutator for the HeadingCommand member.

3. Override the Execute method to invoke the SetHeading method on the target (see BaseCommand 1a.) using the float member for the heading value.

Velocity Command

1. Create a class called VelocityCommand that derives from BaseCommand. This class should contain a couple of floats for the velocity.

2. Create accessors and mutators for the VelocityCommand members.

3. Override the Execute method to invoke the SetVelocity method on the target (see BaseCommand 1a.) using the two float members for parameters.

Composite

1. Create a class named MotherShip that derives from the Ship class with no default constructor.

        a. Create a constructor that utilizes a constant Ship reference (const Ship &) parameter to invoke 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 is on invoke the Heartbeat method on all shadows.

4. Have the destructor of the MotherShip clean up the ViewManager references and memory used by its shadows.

Delayed Commands

1. We are going to produce our shadow effect via delayed commands. Start accomplishing this by adding a vector of BaseCommand pointers in MotherShip.

2. Within the MotherShip’s Heartbeat method, if the MotherShip’s afterburner flag is on, do the following for each shadow:

         a. Create a VelocityCommand object with the MotherShip’s velocity

         b. Create a HeadingCommand object with the MotherShip’s heading.

         c. The delay parameter for each command is the amount of time in seconds to wait before executing the command (0.05 or less is a good number for the first heading 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 process commands in our list/vector. This method should take in a float as a parameter that will serve as change in time.

         a. Use the passed in float to reduce the delay value for each command. If a delay value falls below zero, execute it, then clean up any memory it uses, and remove the command from the list/vector.

         b. Be careful how you loop through your command container; don’t skip the processing of any command by incrementing your index when removing an item from it.

         c. Invoke this method in the MotherShip’s Heartbeat method if the afterburner flag is on.

4. Generate a private clean up method that removes and cleans up the memory for all contained commands.

         a. Have this method also set the velocities of all shadows to zero and their positions and headings to that of the MotherShip.

         b. Invoke this method in the destructor of the MotherShip and in the MotherShip’s Heartbeat method if the afterburner flag is off.

Integration

1. Update the player ship creation code to create a MotherShip object and store inside of it five Ship type objects (shadows.) You do not need to alter the return value of this method.

          a. You will need to use the return value from CloneShipFromPrototype() to invoke the MotherShip’s constructor. You will also need to delete the Ship that was returned and remove the reference in the ViewManager created by this function. Pseudo code example (this code will not compile as-is): Ship *deleteme=SaiphApp::CloneShipFromPrototype(SaiphApp::GetShipID()) MotherShip *player = new MotherShip(*deleteme) ViewManager::RemoveObject(deleteme) delete deleteme ViewManager::AddObject(player, 2)

          b. Create 5 Ship objects and use the MotherShip’s AddShadow method to add them to the MotherShip’s container.

                       i. These objects should be created using the aforementioned CloneShipFromPrototype method with the same ship ID as the MotherShip.

                       ii. Views for all shadows must be added to layer one so they will not be drawn on top of the MotherShip. Note: The CloneShipFromPrototype() method will accept a layer number as a second parameter and create the views for you.

                       iii. Set the shadows to a color different than white. 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 afterburners are used, shadows will start to follow the player ship, thus giving the illusion that the player is moving even faster.



We have an Answer from Expert

View Expert Answer

Expert Answer


Answer: // Include header file #include #include #include class GFG { // To represent a data point // corresponding to x and y = f(x) public: class Data { private : GFG *parentClass; public: Data(GFG *parentClass) { this-
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe