Answered step by step
Verified Expert Solution
Link Copied!

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.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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 2 using namespace std; 3 4 int main() { 5 srand(time(NULL)); 6 //First add statements to test the methods of the character Player, and Target class. After you are happy with the methods, uncomment the following code to play the game. 7 8 9 Playet me (55); 10 Target flegi(20) chan key 12 bool win false 13 un signed moves 3:03 14 Cout the beginning in same costring end 15 Coutosta kendi, 16 Hooves 17 Loverengi 18 Get and NOT 19 main.cpp E me.move(key); flag.move() win = me close enough flag) it (win) cout 2 #include #include "Point.h" 4 //Working with static data members unsigned Point::max_x 10; 7 unsigned Point::max_y = 10; void Point::setLimits(unsigned x, unsigned y) { Point::max_x = x; 10 Point::max_y = y; 11 } 12 13 Point::Point() : x(0), y_(0) { 14 } 15 16 Point::Point(unsigned x, unsigned y) { 17 this->setLocation(x, y); 118 } 19 20 21 22 23 24 string Point::toString() const { stringstream s; s "(" __y_ ')'; return s.str(); } 25 26 27 void Point::setLocation (unsigned x, unsigned y) { this->X = X % Point::max X: E CE - Point.cpp x 28 this->y_ = y % Point::max_y; 29 } 30 31 void Point::moveLeft( { 32 this->x_ (Point::max_x + this->x_ 1) % Point::max_x; 33 } 34 35 void Point::moveRight() { 36 this->x_ = (this->x_ + 1) % Point::max_x; 37 } 38 39 void Point::moveUp() { 40 this->y_ = (Point::max_y + this->y. - 1) % Point::max_y: 41 } 42 43 void Point::moveDown() { 44 this->y_ = (this->y_ + 1) % Point::max_y; 45 ] 46 47 return true if ps with 2 pixels from this 48 bool Point::isNear (const Point& p) const { int x_diff this-> pix_ 50 int y_diff =' this->y_ p.yu 51 return (abs(x_diff) using namespace std; 4 5 6 6000 This point class does not keep unique ID for a Point object. class Point { private: unsigned x_ y_; static unsigned max_x; static unsigned max_y: public: static void setLimits(unsigned x, unsigned y); 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 mutator void setLocation(unsigned x, unsigned y); void moveLeft(); Imove one step to the left! void moveRight(); move one step to the gho void moveUp(); Renault void moveDown (; move one scendon desbe string toString() const; Nature bool isNear (const Point& p) const; 26 Point(); Point.hx LI 27 Point(const Point& p); Point(unsigned x, unsigned y); }; 28 29 30 31 #endif

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

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions