Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please provide a thorough answer. separate it into the appropriate files and show the outputs thanks. Lab 06 Catch the target Star Finish This lab
please provide a thorough answer. separate it into the appropriate files and show the outputs thanks.
Lab 06 Catch the target Star Finish This lab asks you to design and implement an inheritance hierarchy to support a simple 2D game where the goal of the player is to move and catch a target The lab06_2d project has been set up with five files (main.cpp, Character.h, Point.cpp, Pointh, and Player.h) and you are to add four more files (Character.cpp, Player.cpp. Target.cpp, Targeth). The "Point.h" and "Point.cpp" files define and implement the Point class. Do not change these files. Keep in mind that the top left corner of a 2D game is (0,0) and the coordinates increase in x when moving to the right and increase in y when moving down. You are encouraged to test the point class in the main function to help you understand what they do. The "Character.h" file defines the base class of the inheritance hierarchy. Do not change this file. You need to add the "Character.cpp" file to implement the member functions of the Character class according to the following description Character(); This default constructor is to set the location of a character to the top-left corner of the 2D space, (0,0) Character(unsigned X, unsigned y); This constructor is to set the location of a character according to parameters provided, (x, y). bool close_enough(const Character& c) const; This member function is to compare the location of the invoking character and the location of the parameter character. It shall return true when the two locations are near each other, false otherwise. (Hint: take advantage of the isNear function for the point class) std::string tostring() const; This member function is to return the coordinates of the invoking character. (Hint take advantage of the toString function for the point class). You're encouraged to add code in the main function to test the member functions of the Character class before moving on to working with the player class. Here's a sample result of testing. The coordinates are displayed by outputting the result of the toString method. Note b and c are considered close enough because their coordinates are within 2 pixels in both x and y The default constructor sets character a to (0, 0). Character bis created at (3, 5). Character c is created at (2, 3). a is close enough to b? false a is close enough to c? false b is close enough to b? true The "Player.h file defines a derived class of Character. Do not change this file. You need to add the "Play.cpp" file to implement the member functions of the Player class according to the following description. Player(unsigned x = 0, unsigned y = 0); This constructor shall invoke the non-default constructor of the Character class to set the location of the player to (x, y). In addition, it shall set the points_data member to 0. void addpoints (unsigned p); This member function shall increase the points_data member of the invoking object by the value of the parameter p. std::string tostring (const This member function shall return a string showing the coordinates and points of the invoking player void move(char c) This member function shall move the location of the invoking player according to the character parameter: w for up, s for down a for left and d for right (Hint take advantage of the moveLeft, moveRight, moveUp, and move Down methods of the Point class.) You're encouraged to add code in the main function to test the member functions of the Player class before moving on to working with the Target class. Here's a sample result of testing. Note that the point class has set the 2D size to 10 x 10 Create a Player object at (4, 6): Player at (4, 6) with points. After adding 10 points: Player at (4, 6) with 10 points. x is close enought to (0, 0)? false. x is close enought to (3, 5)? true. x is close enought to (2, 3)? false. After x.move('w'): Player at (4, 5) with 10 points. After x.move('w'): Player at (4, 4) with 10 points. After x.move('w'): Player at (4, 3) with 10 points. After x.move('w'): Player at (4, 2) with 10 points. After x.move('w'): Player at (4, 1) with 10 points. After x.move('w'): Player at (4, 0) with 10 points. After x.move('w'): Player at (4, 9) with 10 points. After x.move('w'): Player at (4, 8) with 10 points. After x.move('w'): Player at (4, 7) with 10 points. After x.move('w'): Player at (4, 6) with 10 points. After x.move('s'): Player at (4, 7) with 10 points. After x.move('s'): Player at (4, 8) with 10 points. After x.move('s'): Player at (4, 9) with 10 points. After x.move('s'): Player at (4, 0) with 10 points. After x.move('s'): Player at (4, 1) with 10 points. After x.move('s'): Player at (4, 2) with 10 points. After x.move('s'): Player at (4, 3) with 10 points. After x.move('s'): Player at (4, 4) with 10 points. After x.move('s'): Player at (4, 5) with 10 points. After x.move('s'): Player at (4, 6) with 10 points. After x.move('a'): Player at (3, 6) with 10 points. After x.move('a'): Player at (2, 6) with 10 points. After x.move('a'): Player at (1, 6) with 10 points. After x.move('a'): Player at (0, 6) with 10 points. After x.move('a'): Player at (9, 6) with 10 points. After x.move('a'): Player at (8, 6) with 10 points. After x.move('a'): Player at (7, 6) with 10 points. After x.move('a'): Player at (6, 6) with 10 points. After x.move('a'): Player at (5, 6) with 10 points. After x.move('a'): Player at (4, 6) with 10 points. 1 After x.move('d'): Player at (5, 6) with 10 points. After x.move('d'): Player at (6, 6) with 10 points. After x.move('d'): Player at (7, 6) with 10 points. After x.move('d'): Player at (8, 6) with 10 points. After x.move('d'): Player at (9, 6) with 10 points. After x.move('d'): Player at (0, 6) with 10 points. After x.move('d'): Player at (1, 6) with 10 points. After x.move('d'): Player at (2, 6) with 10 points. After x.move('d'): Player at (3, 6) with 10 points. After x.move('d'): Player at (4, 6) with 10 points. You are to add "Target.h and Target.cpp" files to define and implement the following derived class of Character: clas's Target public Character / private: unsigned bonus; public: Target (unsigned b)': unsigned getBonus const; string costring const; voto move }; Target(unsigned b); This constructor shall set the bonus data member using the value of b and location to a random point. Note that the serLocation method of the Point class can handle any unsigned values unsigned getBonus() const; This member function simply returns the value of bonus string tostring() const, This member function shall return a string showing the coordinates and bonus of the invoking target void move(). You get to choose how to randomly move the invoking target in this member function Keep in mind that your algorithm would affect the level of difficulty for the player to catch the target Once you have tested the methods of all of your classes, you'll be able to enjoy a quick game of catching the target using the main function provided. 10 Con cl If main.cpp x 1 #include Step 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