Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
COMP 1010 Introduction to Computer
Assignment 5
This assignment covers the entire course, including partially-filled arrays and searching arrays.
Notes:
• Name your sketch using your name, the assignment number, and the question number, exactly as in this example: LastnameFirstnameA5Q1.
• Your programs must run upon download to receive any marks.
• Submit one PDE file for the highest question completed.
• Assignments must follow the programming standards document published on the course
website on UM Learn. Programming standards are worth 6 marks on this assignment.
• After the due date and time assignments may be submitted but will lose 2% of marks per
hour late or portion thereof.
• You may submit a question multiple times, but only the most recent version will be marked.
• These assignments are your chance to learn the material for the exams. Code your
assignments independently. We use software to compare all submitted assignments to each other, and pursue academic dishonestly vigorously.
Background: Tetris
Tetris is a puzzle game played by a single player (see https://en.wikipedia.org/wiki/Tetris). Random puzzle pieces, consisting of four square segments, fall from the top of the game. The player tries to place the pieces to form complete rows of squares. Complete rows are removed from the game board, and all rows above the removed row fall to fill in the gap. The aim is to form as many complete rows as possible before the pieces stack up to the top of the game board.
In this assignment you will create a simplified Tetris game, where the computer will randomly generate pieces, and the user will maneuver the pieces as they fall. The game will end when there is no empty space for the falling piece (i.e. the pieces have stacked up to the top of the game board). The questions below will guide you through building the game. Each question builds on the previous. Ensure one question is working before moving on to the next.
You must use the functions described below in your program, and data (including arrays) must be passed to and returned from functions as described below. Each function should have a single purpose. Your draw block should be simple, and call other functions to do the work.
It is strongly recommended that you read through the entire assignment and spend some time on program design before you begin coding. Think about which functions you need to write, and how they will interact with each other.
1
ASSIGNMENT 5
DEPARTMENT AND COURSE NUMBER: COMP 1010
Q1: Preparing the Game Board & Colouring Cells [3 marks]
Download the A5Q1template.pde file in the Assignment 5 folder in UM Learn.
The game board parameters have been set for you. A global constant CELLSIZE stores the width and height of each square in the pieces, in pixels. The global constants NUM_ROWS and NUM_COLS store the number of rows and number of columns on the game board. An integer number of squares/cells must fit horizontally and vertically in the canvas. The size of the canvas is set in setup(), so that it is the correct size for the parameters above.
In this assignment, you will store the row and column numbers for squares in parallel arrays (one array to store the row numbers, and one array to store the column numbers, where the row and column for a particular square are stored at the same position in both arrays). Valid column numbers are 0 (zero) to NUM_COLS-1. Valid row numbers are 0 to NUM_ROWS-1.
draw() contains code that will fill arrays with row and column numbers, and it calls a drawCells() function to colour cells on the game board. Do not change any of the provided code while working on question 1.
Write the drawCells() function such that it accepts two int arrays (column numbers first, row numbers second), the number of entries in the arrays, and a colour (an int). This function should fill each square listed in the arrays with the specified colour.
The conversion from column number and row number to location on the canvas MUST make use of the global constants. Do NOT use any magic numbers.
Test your drawCells() function, and make sure that your program output appears as in the image at right.