Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please implement the C++ program exactly as described below. We will discuss some of the design choices in future lectures and we will revise the

Please implement the C++ program exactly as described below. We will discuss some of the design choices in future lectures and we will revise the ways that we connect to the functions in future assignments. Overview In the assignments for this course, you will create a text-based, side-scrolling spaceship game. In this game, the user will control a mining ship that collects asteroids. Each assignment will build on the previous one. In Assignment 1, you will design and implement code to (1) display the player ship and the region of space in front of it, (2) move the player ship, and (3) detect collisions with a single asteroid. In the game, the user will enter text commands to control the mining ship and print a picture of the player ship and the space in front of it. If the player ship collides with the asteroid, the program prints a message and terminates. The user can also terminate the program with the 'q' command at any time. As well, after each move, the displayed region of space in the game will move one column to the right. When running, the game will look as follows:

image text in transcribed

The # symbols should be printed to show the border of the area being displayed. The shape to the left is the player ship and the shape near the middle is the asteroid. The purpose of this assignment is to ensure that you understand how to use two-dimensional arrays, including defining types using two-dimensional arrays and passing two-dimensional arrays to functions. For Part A, you will develop a module that defines a display buffer. For Part B, you will begin implementing the game. For Part C, you will separate your program into multiple files. The Buffer To prepare for displaying the player ship and the region of space in front of it, a temporary area of memory, known as a buffer, should be used to represent the picture before it is displayed. The buffer is represented by a two-dimensional array of characters. Before drawing each frame, the buffer is initialized to contain all blank (' ') characters. After that, the characters representing the player ship and the asteroid are copied into the buffer. Finally, the buffer is printed on the screen. In computer science terminology, any area of memory used for temporary storage is known as a buffer, and the technique of using a buffer to hold data temporarily is known as buffering. This technique is commonly used in computer graphics, where colour values for pixels are stored instead of characters. The advantage of buffering in this case is that it is not necessary to work out, on a character-by-character basis, exactly what should be printed. Instead, each item to be shown can simply be placed in the appropriate position in the buffer, without worrying about the order in which the characters will be printed. Displaying Things The player ship and the asteroid will each be represented using a two-dimensional array of characters. The characters in each array will be loaded from a file once when the program is started, and then they are copied to the display buffer whenever the current state of the game is displayed. The images for the player ship and asteroid are stored in files named player.txt and asteroid.txt. The contents of the player.txt file are as follows: /o\ / C-/ C======\ \ The contents of the asteroid.txt file are as follows: /--\ |XX| \--/ Beginning in Assignment 2, you will replace the XX on the asteroid with a number representing its ore value. Part A: The Buffer Type [12 / 40 marks] In Part A, you will write the buffer module. 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 uppercase and the remaining letters are lowercase.

Part A: The Buffer Type [12 / 40 marks] In Part A, you will write the buffer module. 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 uppercase and the remaining letters are lowercase. By the end of Part A, you will have created functions for handling the buffer with the following prototypes: void bufferPrint (const Buffer buff); void bufferClear (Buffer buff); void bufferSetCell (Buffer buff, int row, int column, char value); Perform the following steps: 1. Define BUFFER_ROW_COUNT and BUFFER_COLUMN_COUNT as integer constants with values of 20 and 60, respectively. Define BUFFER_EMPTY and BUFFER_BORDER as character constants with values of '.' and '#' respectively. Use typedef to define a Buffer type corresponding to a 2D array of chars with dimensions BUFFER_ROW_COUNT and BUFFER_COLUMN_COUNT. Put these constants and declarations in the BigMain.cpp file outside and before the functions defined in step A2 and subsequent steps. They are global constants and a global type definition. 2. Copy in the function prototypes for bufferPrint, bufferClear, and bufferSetCell. 3. Implement a bufferClear function that takes a Buffer as a parameter. This function should set the value of each element in the Buffer to BUFFER_EMPTY. 4. Implement a bufferPrint function that takes a Buffer as a parameter. This function should print the contents of the Buffer with a border of BUFFER_BORDER characters around it. Hint: Start by printing a line of BUFFER_BORDER characters. Then, for each line, print a BUFFER_BORDER character, then all the characters in one row of the Buffer, then another BUFFER_BORDER character, and then a newline. Finally, print another line of BUFFER_BORDER characters. 5. Implement a bufferSetCell function that takes a Buffer, two ints representing a row and column, and a char representing the new value, as parameters. This function should set the element of the Buffer specified by the row and column to the character value. If the row and column lie outside the Buffer, there should be no effect. Debugging: To test the Buffer functions, create a main function. It should first declare a Buffer named my_buffer. Then it should call the bufferClear function with my_buffer as a parameter and then call bufferPrint, also with my_buffer as a parameter. Before continuing, test that this works as expected. Then add a call to bufferSetCell, that says to add the letter A to the buffer in row 10, column 5. For example, bufferSetCell(my_buffer, 'A', 10, 5);. Add another call to bufferPrint after this call to bufferSetCell. Before continuing, test that this works as expected. Then add four more calls to bufferSetCell to continue with three more As and then a row of four Bs underneath to appear in rows 10 and 11 as: AAAA BBBB Then try specifying positions outside each edge of the buffer and ensure that it works as expected.

### #3 ######: #3 #3 #3 #3 #3 #3 |--\ #3 |X | \--/ #3 #3 # C-<_l_>/ # C======\ #3 #3 #3 #3 #3 #3 ########## #3%#3####: %23%#3#### ### #3 ######: #3 #3 #3 #3 #3 #3 |--\ #3 |X | \--/ #3 #3 # C-<_l_>/ # C======\ #3 #3 #3 #3 #3 #3 ########## #3%#3####: %23%#3####

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

More Books

Students also viewed these Databases questions

Question

(4) Performing linear regression to obtain the parameter estimates.

Answered: 1 week ago