Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
Map of a Cave System Assignment

Instructions

In this assignment, you will load in and process a map of a cave system. When processing the map, you will calculate which positions are tunnels and which positions are solid rock. For the tunnel positions, you will also calculate the shape of the tunnel (e.g. straight, corner, T-junction, etc.). First, the program will load the map and print it in its raw (unprocessed) form. Second, it will process the map and print it again in its processed form. Third, the program will ask the user for a position and print a description for that position. Finally, the program will terminate.

The purpose of this assignment is to ensure that you understand how to use two-dimensional arrays, including passing two-dimensional arrays to functions. For Part A, you will write functions to handle the map in its raw form. For Part B, you will create a list of constants for tunnel shapes and some functions to process them. For Part C, you will write functions to handle the map in its processed form. For Part D, you will divide the program into several files for separate compilation.

There will be two maps, both represented as 2-dimensional arrays.The raw map is a 2-dimensional array of chars and stores values from an input file. The processed map is a 2-dimensional array of unsigned ints representing the tunnel shapes. All maps are 20 horizontal rows by 40 vertical columns in size. Both arrays use the same coordinate system: the top of the screen is north, the bottom is south, the right is east and the left is west. The northwest (top-left) corner is position (0, 0). Other positions are identified by how far south (down) and east (right) they are from that position. For example, the "A" is 2 south and 9 east, putting it at position (2, 9).

In this assignment, the symbols on the raw map are divided into '#'s, representing solid rock, and everything else, representing tunnels. The other symbols will be used in later assignments. Any position outside the map is treated as if it is solid rock.

In Part A, you will handle the raw map. You will eventually put these functions in their own module, but for now put all the code in a file named BigMain.cpp. Throughout this course, make sure that you use exactly the specified file names, which are case sensitive. Here, B and M are upper case and the remaining letters are lower case. By the end of Part A, you will have created functions for handling the raw map with the following prototypes:

The Map

• void rawMapLoad (char raw[][MAP_SIZE_EAST], const std::string& filename);

• void rawMapPrint (const char raw[][MAP_SIZE_EAST]);

• bool rawMapIsOpen (const char raw[][MAP_SIZE_EAST], int south, int east);

In Part B,you will also add a function with the following prototype:

• // Shape rawMapCalculateShape (const char raw[][MAP_SIZE_EAST], // int south, int east);

1. Use #include to include the string, iostream, and fstream libraries. Remember to put using namespace std;

2. Define MAP_SIZE_SOUTH and MAP_SIZE_EAST as constants with the values 20, and 40, respectively.

3. Copy in the function prototypes shown above.

4. Add an implementation for the rawMapLoad function. The filename string represents the name of the file to load from. You should first open this file for reading. If the file cannot be opened, print an error message. (For the rest of CS 115, you should always print an error message when a file cannot be opened.) Otherwise read the values from the file into the raw map array.

• Hint: You will need an outer for loop that is executed once for each line of input.

• Hint: One way to read in the map is using getline to read a line from the file into some string variable. Then use an inner for loop to copy the characters, one by one, from the string into the raw map array.

• Hint: Another way to read in the map is by using unformatted I/O (fin.get() ) to copy the values directly into the array. You will need to call fin.ignore(1000, 'n') at the end of each line to avoid reading the newline character into the array.

5. Add a main function. It should start by declaring a suitable variable to represent the raw map array. Then call the rawMapLoad function with the array as the first parameter and "map1.txt" as the second parameter.

• Hint: If you are using Visual Studio, the program window will usually close as soon as the program ends. To prevent this, print a message saying "Press [ENTER] to continue..." at the end of main and then read in a line of input into a temporary variable with getline.

6. Add an implementation for the rawMapPrint function. It should print out all the values in the array with a newline at the end of each line. Call this function from main after you load the map.

7. Add an implementation for the rawMapIsOpen function. The function should first check if the position is outside the map and, if so, return false. Otherwise, the function should return false if the raw map has a value of '#' at the specified position and true otherwise.

Part A: The Raw Map

• Hint: The position is outside the map if south is outside the interval [0, MAP_SIZE_SOUTH) or east is outside the interval [0, MAP_SIZE_EAST).

• Debugging: In the main function, call the rawMapIsOpen function for several positions and print out the result for each.

In Part B, you will create a list of constants to store in the processed map. Each constant will represent a possible shape that the tunnel can have at a position. You will also write a number of functions that use these shapes.

• bool shapeIsTunnel (Shape shape);

• char shapeGetMapChar (Shape shape);

• Shape shapeCalculate (bool is_open_north, bool is_open_south, bool is_open_east, bool is_open_west); Perform the following steps:

1. Above the main function, use the typedef statement to define an alias (alternate name) to the unsigned int type named Shape. Use the Shape type for values representing tunnel shapes.

• Note: We are using the Shape type to make the program easier to read. The compiler will treat it as unsigned int.

2. Define 17 constants of the Shape type with the names and values in the table below (ignore the Map Char column for now). The constants must be placed somewhere after the typedef mentioned in step B1. 

The letters in the constant names after "SHAPE_" indicate which directions the player can move (except in SHAPE_BUBBLE and SHAPE_SOLID because those have no directions in which the player can move). Similarly, the Map Char values give graphic depictions of the directions in which the player can move. For example, the pipe symbol ('|') is used to indicate that the player’s character can move north or south from its current location.

3. Copy in the function prototypes shown above.

4. Add an implementation for the shapeIsTunnel function. It should return true if the shape parameter is strictly less than SHAPE_SOLID and false otherwise.

In Part C, you will handle the processed map. By the end of Part C, you will have written functions for the processed map with the following prototypes:

• void mapInit (Shape map[][MAP_SIZE_EAST]);

• void mapPrintMap (const Shape map[][MAP_SIZE_EAST]); • bool mapIsInMap (const Shape map[][MAP_SIZE_EAST], int south, int east);

• bool mapIsTunnel (const Shape map[][MAP_SIZE_EAST], int south, int east);

• void mapPrintDescription (const Shape map[][MAP_SIZE_EAST], int south, int east);

• void mapSetAt (Shape map[][MAP_SIZE_EAST], int south, int east, Shape shape);

• void mapSetRectangle (Shape map[][MAP_SIZE_EAST], int south_min, int east_min, int south_size, int east_size, Shape shape);

Part B: Tunnel Shapes

. Copy in the function prototypes shown above.

2. Add an implementation for the mapSetAt function. It should change the specified element of the map array to the specified shape. For example, if south is 5, east is 3, and shape is SHAPE_NE_CORNER, then position [5][3] should be assigned the value of SHAPE_NE_CORNER.

3. Add an implementation for the mapSetRectangle function. It should set all elements of the map array in the specified area to the specified shape.

4. Add an implementation for the mapInit function. It should set the value of every element in the map to SHAPE_SOLID.

5. Add an implementation for the mapPrintMap function. It should print out one character for each position in the map. Use the shapeGetMapChar function to determine which character to print. Remember to print a newline character at the end of each line.

6. Add code to your main function after loading and printing the raw map. Declare an array to store the processed map and call the mapInit and mapPrintMap functions on it. When you run your program, you can expect it to print a big rectangle of spaces (blanks) since mapInit sets all locations to SHAPE_SOLID and this shape should be printed as a space.

7. Add code to your main function to add tunnels to the processed map. Use two for loops to go through every position on the raw map. If that position is not solid, use the rawMapCalculateShape function to determine the tunnel shape there. Then store the tunnel shape in the processed map. Do this before printing the processed map. You should now see tunnels when you print the processed map.

8. Add an implementation for the mapIsInMap function. It should return true if the specified position is inside the bounds of map and false otherwise.

9. Add an implementation for the mapIsTunnel function. This function should call the shapeIsTunnel function.

10. Add an implementation for the mapPrintDescription function. It should check if the map at the specified position is a tunnel and, if so, print "You are in a tunnel.". Otherwise, it should print "You are in solid rock.".

• Debugging: Call the mapPrintDescription function for several positions on the map.

1. Save a copy of your existing file named BigMain.cpp somewhere safe.

2. Place the MAP_SIZE_SOUTH and MAP_SIZE_EAST constants in their own header file named MapSize.h.

3. Place the function prototypes from Part A (including rawMapCalculateShape) in a header file named RawMap.h. The RawMap.h file should use #include to include MapSize.h and Shape.h. Also copy the #includes and using namespace std; from your original file.

4. Place the implementations of the rawMap* functions in a separate file named RawMap.cpp that #includes the header files MapSize.h, Shape.h, and RawMap.h.

5. Place the typedef for Shape and the function prototypes from Part B in a header file named Shape.h. (rawMapCalculateShape is in RawMap.h.)

6. Place the implementations of the shape* functions in a separate file named Shape.cpp that #includes the header file Shape.h.

7. Place the function prototypes from Part C in a header file named Map.h. The Map.h file should include MapSize.h and Shape.h.

8. Place the implementations of the map* functions in a separate file named Map.cpp that #includes the header files MapSize.h, Shape.h, and Map.h.

9. Change the name of your original file from BigMain.cpp to Main.cpp and #include the MapSize.h, RawMap.h, Shape.h, and Map.h header files. Remove the constants, function prototypes, and function implementations that you copied to other files. Main.cpp should now just contain the main function (and possibly helper functions of your own if you added any).

10. Upload your source and header files and all your data files to hercules.cs.uregina.ca and compile them together as explained in the lab.

support
Whatsapp
callback
sales
sales chat
Whatsapp
callback
sales chat
close