Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++, on coldblocker Tank The problem: You will have to create a Tank and guide it through a Landscape in order to move around a
C++, on coldblocker
Tank The problem: You will have to create a Tank and guide it through a "Landscape in order to move around a simple obstacle course to reach a Target* Everything you need will be provided to you in predefined dasses, you have to use the dasses and your own logic to tell the Tank how to reach the Target Classes you will use: To use each of these classes, you will get an instance of the class (either created by you or returned from a function) and then tell it to do things (its functions) The following classes are built into C+t. We have previously used some of them They are all documented on the Visual Studio's C++ website under APls" The library they are in is shown at the very top of the documentation, if the class is in a specific library, be sure and include that library string We have used this class already Can be used to get keyboard input (we have done this already) cin rand Used to create a random number generator After you create one, you can tell it to return its rand), which will return a random number between equal to 00 and less than 1 0 (we have used this already, but you can use rand0% maxstemin> to get any range of numbers you need) Represents an (x.y) coordinate > Point SDL Color Represents a color. It stores each of the RGB (Red, Green, Blue) components of the color as an integer from 0-255 So the statement SDL Color myColor = { 255, 0, 255 ); would create a Color that has as much red as possible, no green, and as much blue as possible The result would be purple. The SDL Color class also has some static' values For example, the statement Color myColor COLOR BLUE, See the "Constants h' file for the predefined would create a Color that is blue. Colors You are also given 2 classes that I wrote. The classes are Describes a drawable Tank (which is drawn as a square) You are not to change its code It has the following constructors and functions (if you look at Tank cpp, you may see a few others that you can use if you want, but the ones below are the ones defined (like the listings in the C++ standard classes) not the exact way they >Tank you will need) Note that the following show how they are would be called Ildefault constructor -sets it to Black and VERY slow Tank) I/"parameteriz Tank(SDL Color theColor, int theSpeed) ed constructor receives a color and a speed (1-30) Pgm4Tank 2 ll move - changes its position by 1 pixel void moveo /i getDimension - returns the Tank width dimension (width and height are equal since its a square) int getDimension() Pgm4 Tank-2 ll move -changes its position by 1 pxel void move0 ll getDimension- returns the Tank width dimension (width and height are equal since its a square) int getDimension) i getPositionX) - returns its x coordinate int getPositionX0 Il getPositionY()- returns its y coordinate int getPositionYO Il setPosition - sets its position to whatever x and y are passed in void setPosition(int x, int y) (you are not allowed to use this function) ll setColor -sets its color to whatever is passed in void setColor(SDL_Color newColor) /l tun-"turns by changing its orientation void tun(string whichWay) (you can pass in "left" or "right") //toString -returns its representation as a String string toString) Landscape Describes a drawable Landscape which is a simple obstacle course consisting of 2 Walls (with an opening that can fit a Tank) and a Target You are not to change its code An example of a Landscape instance, along with some relevant notes, is shown below The green and crange walls are at constant s-coordinates x increases to the right A Tank's coordinates are always at the upper left hand comer y increases The orange opening's coordinates are here. The green opening's coordinate are here The Target's coordinates are at the upper left hand corner of the bounding rectangle Landscape's constructors and functions are listed below. Note that the following show how they are defined (like the listings in the C++ standard classes), not the exact way they would be callec Default constructor-generates a random position for the green opening, the orange opening, and the target Iandscepe O Landscape's constructors and functions are listed below. Note that the following show how they are defined (like the listings in the C++ standard classes), not the exact way they would be called ll Default constructor-generates a random position for the green opening, the li orange opening, and the target Landscape () !l Parameterized constructor which receives an int that is the landscapelD e (int theID) (must be between 0000 and 9999) Il getOrangeOpening) -returns the opening in the orange wall as a Point (the /f top/left point of the lower section) Point getorangeopening () /I getGreenOpening0-returns the opening in the green wall as a Point (the II top/left point of the lower section) int getGreenopening ) // getTargetLocation returns a Point which is the location of the target (actually Point getTargetlocation () /l addTank - adds the Tank that is received to this instance of Landscape the upper/left point of its bounding rectangle) void addTank (Tank" t et can contain viruses. Unless you need to edit, it's sater to stay in Protected iEnable Editing Your program: Your program should be named Program4. It will contain the main function, inside main shoulkd be code to do the following o Prompt the user to enter their name then use the Scanner class to read it in o If their name is "Randy" (don't use for Strings, use compare) here), then o But if their name is .Pnus" (dont use = for Strings, use compare() here), then .Create a new SDi Color that consists of a random amount of Red, a random amount of Yellow, and a Random amount of Blue (different random numbers) Create some shade of Green and any speed you want be either the "static value you get from the class (see my brief description of the Color class above), or a custom SDL Color you created with no Red, some amount of Green, and no Blue The shade of Green can - Otherwise, create whatever non-Green SDL Color you want (see my brief description of the SDL Color class above) and any speed you want Create a new instance of a Tank, passing in the SDL Color you created and any speed you want o o Once your Tank is created, you should create a new instance of a Landscape. You should call its default constructor, which will create one with random openings in the walls and target location. The ID for that particular Landscape will be displayed at the top o NOTE. for testing purposes, you can create a new instance of a Landscape by passing the ID into the constructor That way, you test your logic against a particular Landscape over and over as you debug it Your final version of Program4 should call its default constructor so that it creates a random Landscape. Program4 is coded with a Landscape ID of 6147 as a good beginning Landscape to start working on your logic Tell your Landscape to add your Tank to itself o o Tell your Landscape and Tank to return whatever unchanging data (location of openings dimension of the Tank, location of the target) you will need to program the commands that tell the Tank to successfully move through the Landscape indscape ogram the Tank The problem: You will have to create a Tank and guide it through a "Landscape in order to move around a simple obstacle course to reach a Target* Everything you need will be provided to you in predefined dasses, you have to use the dasses and your own logic to tell the Tank how to reach the Target Classes you will use: To use each of these classes, you will get an instance of the class (either created by you or returned from a function) and then tell it to do things (its functions) The following classes are built into C+t. We have previously used some of them They are all documented on the Visual Studio's C++ website under APls" The library they are in is shown at the very top of the documentation, if the class is in a specific library, be sure and include that library string We have used this class already Can be used to get keyboard input (we have done this already) cin rand Used to create a random number generator After you create one, you can tell it to return its rand), which will return a random number between equal to 00 and less than 1 0 (we have used this already, but you can use rand0% maxstemin> to get any range of numbers you need) Represents an (x.y) coordinate > Point SDL Color Represents a color. It stores each of the RGB (Red, Green, Blue) components of the color as an integer from 0-255 So the statement SDL Color myColor = { 255, 0, 255 ); would create a Color that has as much red as possible, no green, and as much blue as possible The result would be purple. The SDL Color class also has some static' values For example, the statement Color myColor COLOR BLUE, See the "Constants h' file for the predefined would create a Color that is blue. Colors You are also given 2 classes that I wrote. The classes are Describes a drawable Tank (which is drawn as a square) You are not to change its code It has the following constructors and functions (if you look at Tank cpp, you may see a few others that you can use if you want, but the ones below are the ones defined (like the listings in the C++ standard classes) not the exact way they >Tank you will need) Note that the following show how they are would be called Ildefault constructor -sets it to Black and VERY slow Tank) I/"parameteriz Tank(SDL Color theColor, int theSpeed) ed constructor receives a color and a speed (1-30) Pgm4Tank 2 ll move - changes its position by 1 pixel void moveo /i getDimension - returns the Tank width dimension (width and height are equal since its a square) int getDimension() Pgm4 Tank-2 ll move -changes its position by 1 pxel void move0 ll getDimension- returns the Tank width dimension (width and height are equal since its a square) int getDimension) i getPositionX) - returns its x coordinate int getPositionX0 Il getPositionY()- returns its y coordinate int getPositionYO Il setPosition - sets its position to whatever x and y are passed in void setPosition(int x, int y) (you are not allowed to use this function) ll setColor -sets its color to whatever is passed in void setColor(SDL_Color newColor) /l tun-"turns by changing its orientation void tun(string whichWay) (you can pass in "left" or "right") //toString -returns its representation as a String string toString) Landscape Describes a drawable Landscape which is a simple obstacle course consisting of 2 Walls (with an opening that can fit a Tank) and a Target You are not to change its code An example of a Landscape instance, along with some relevant notes, is shown below The green and crange walls are at constant s-coordinates x increases to the right A Tank's coordinates are always at the upper left hand comer y increases The orange opening's coordinates are here. The green opening's coordinate are here The Target's coordinates are at the upper left hand corner of the bounding rectangle Landscape's constructors and functions are listed below. Note that the following show how they are defined (like the listings in the C++ standard classes), not the exact way they would be callec Default constructor-generates a random position for the green opening, the orange opening, and the target Iandscepe O Landscape's constructors and functions are listed below. Note that the following show how they are defined (like the listings in the C++ standard classes), not the exact way they would be called ll Default constructor-generates a random position for the green opening, the li orange opening, and the target Landscape () !l Parameterized constructor which receives an int that is the landscapelD e (int theID) (must be between 0000 and 9999) Il getOrangeOpening) -returns the opening in the orange wall as a Point (the /f top/left point of the lower section) Point getorangeopening () /I getGreenOpening0-returns the opening in the green wall as a Point (the II top/left point of the lower section) int getGreenopening ) // getTargetLocation returns a Point which is the location of the target (actually Point getTargetlocation () /l addTank - adds the Tank that is received to this instance of Landscape the upper/left point of its bounding rectangle) void addTank (Tank" t et can contain viruses. Unless you need to edit, it's sater to stay in Protected iEnable Editing Your program: Your program should be named Program4. It will contain the main function, inside main shoulkd be code to do the following o Prompt the user to enter their name then use the Scanner class to read it in o If their name is "Randy" (don't use for Strings, use compare) here), then o But if their name is .Pnus" (dont use = for Strings, use compare() here), then .Create a new SDi Color that consists of a random amount of Red, a random amount of Yellow, and a Random amount of Blue (different random numbers) Create some shade of Green and any speed you want be either the "static value you get from the class (see my brief description of the Color class above), or a custom SDL Color you created with no Red, some amount of Green, and no Blue The shade of Green can - Otherwise, create whatever non-Green SDL Color you want (see my brief description of the SDL Color class above) and any speed you want Create a new instance of a Tank, passing in the SDL Color you created and any speed you want o o Once your Tank is created, you should create a new instance of a Landscape. You should call its default constructor, which will create one with random openings in the walls and target location. The ID for that particular Landscape will be displayed at the top o NOTE. for testing purposes, you can create a new instance of a Landscape by passing the ID into the constructor That way, you test your logic against a particular Landscape over and over as you debug it Your final version of Program4 should call its default constructor so that it creates a random Landscape. Program4 is coded with a Landscape ID of 6147 as a good beginning Landscape to start working on your logic Tell your Landscape to add your Tank to itself o o Tell your Landscape and Tank to return whatever unchanging data (location of openings dimension of the Tank, location of the target) you will need to program the commands that tell the Tank to successfully move through the Landscape indscape ogram theStep 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