Assignment 1
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:
##############################################################
##############################################################
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-<_L_>/ 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.
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:
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 '#' 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 cpp file outside and before the functions defined in step A2 and subsequent steps. They are global constants and a global type definition.
Copy in the function prototypes for bufferPrint, bufferClear, and bufferSetCell.
Implement a bufferClear function that takes a Buffer as a This function should set the value of each element in the Buffer to BUFFER_EMPTY.
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 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.
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 If the row and column lie outside the Buffer, there should be no effect.
Debugging: To test the Buffer functions, create a main 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 A’s and then a row of four B’s 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.
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme