Processing代写 | COMP 1010 Summer 2019 Assignment 5 Java

Java代写Processing完成一个俄罗斯方块

ASSIGNMENT 5: Arrays
DEPARTMENT AND COURSE NUMBER: COMP 1010 COURSE TITLE: Introduction to Computer Science 1 TERM: Summer 2019
Assignment 5
DUE DATE: THURSDAY AUGUST 8, 2019 AT 11:59 PM.
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.
2

ASSIGNMENT 5
DEPARTMENT AND COURSE NUMBER: COMP 1010
Q2: Generate a Random Piece [3 marks]
Remove the contents of draw() that were given in the question 1 template, but leave the noLoop() line in setup() for question 2. Keep the drawCells() function that you wrote.
In Tetris, each piece consists of four squares. There are 7 possible shapes, as shown in the images at right. In the real Tetris game, users have the ability to rotate pieces as they fall. You will not implement rotation in your game and therefore there are 19 possible orientations. You must implement at least one orientation for each of five different types of pieces. You may implement more if you wish.
Set up global int array variables to store the x and y coordinates (column and row numbers) of the squares in the active (falling) game piece. For example, a possible set of coordinates for the square piece might be x coordinates of {4, 5, 4, 5} and y coordinates of {7, 7, 8, 8}, meaning that the four segments of the piece are located on the grid at (column 4, row 7), (column 5, row 7), (column 4, row 8), and
(column 5, row 8).
Implement a function void generatePiece(int[] x, int[] y, int startRow) that will create a random game piece. This function should fill the arrays with the coordinates for each square in a randomly selected piece type. startRow is the row in which the lowest squares of the piece will be located. In the game, the startRow will be row 0 (the pieces begin falling from the top), however, for this question it is suggested that you choose a lower row so that you can see the pieces in their entirety.
In this question, draw() should generate a random piece and draw it on the game board. Q3: Let the Pieces Fall [8 marks]
Remove the noLoop() line from setup. From question 3 on, your program should be animated. In this question, you will make the pieces fall, stopping when there is no empty space below
them.
Add another pair of int arrays to store the coordinates of any pieces that have landed at the bottom of the game. These should be partially full arrays, with an int variable used to store the current number of entries in the arrays. (What should the maximum length of these arrays be?)
3

ASSIGNMENT 5
DEPARTMENT AND COURSE NUMBER: COMP 1010
Implement a counter that will track the number of frames between movements. In question 7 you will add levels and increase the speed with which the pieces fall. Think carefully about how you want to count frames.
Every n frames (try starting with n=60), the piece should fall by an amount equal to the size of one grid square. Before moving a piece, you should test whether there is space for the piece to move into its destination. That is, test whether any cells that the piece wants to move into are listed in the arrays of landed pieces. If there would be an overlap of the falling piece with the landed pieces (i.e. the move is not allowed), transfer the contents of the falling piece arrays to the landed arrays and generate a new piece at the top of the canvas. If the move is allowed, make the move.
As part of this question, write
• A function boolean search(int[] xValues,
int[] yValues, int numValues, int x, int y) that searches the pair of arrays for the given x,y position, and returns true if a match is found.
• A function boolean moveAllowedY(int[] fallingX, int[] fallingY, int[] landedX, int[] landedY, int numLanded, int deltaY) that tests whether the falling piece can move vertically by the number of squares given in the parameter deltaY without colliding with the landed pieces. A deltaY value of +1 would mean the piece is moving down one row.
• A function void makeMove(int[] fallingX, int[] fallingY, int deltaX, int deltaY) that moves the falling piece by the number of squares specified in the horizontal and vertical directions. At this point, your pieces will only move in the y direction but this function will also be used in Question 5 to move pieces horizontally.
• A function int landPiece(int[] fallingX, int[] fallingY,
int[] landedX, int[] landedY, int numLanded) that transfers the contents of the falling arrays into the landed arrays. The parameter numLanded is the number of entries in the landed arrays before the transfer, and the function
should return the new number of entries in the landed arrays.
Q4: Game Over [3 marks]
When the pieces pile up to the top of the canvas, the game should end. All motion should stop, there should be no further response to user input, and a game over message should be printed on the canvas.
As part of your solution to question 4, write a function named testEndGame that tests for the end of the game and returns a boolean value of true if the game should end.
4

ASSIGNMENT 5
DEPARTMENT AND COURSE NUMBER: COMP 1010
Q5: Add User Control [5 marks]
Give your user the ability to move the pieces. Pressing the left or right arrow should move the piece one square in the desired direction, provided that a move in that direction would not move the piece out off of the game board. Pressing the down arrow should cause the piece to move down an extra square, in addition to the speed it is naturally falling. Pressing the up arrow or any other key should have no effect.
Make use of the makeMove function that you wrote in question 3.
As part of your solution to this question write
• A function boolean moveAllowedX(int[] fallingX, int[] fallingY,
int[] landedX, int[] landedY, int numLanded, int deltaX) that tests whether the falling piece can move horizontally by the number of squares given in the parameter deltaX, without colliding with the landed pieces or moving out of the game area. Use -1 to indicate moving to the left one column, and +1 to indicate moving to the right one column.
• The void keyPressed() function should be used to test which key the user presses. keyPressed should call moveAllowedX or moveAllowedY as appropriate, and then call makeMove to move the falling piece. Because landing the pieces was implemented in question 3, the keyPressed function should only test if the user’s desired motion (given by pressing arrow keys) is allowed and make that move. The falling motion should remain as implemented in question 3.
Q6: Remove Full Rows & Keep Score [10 marks]
Each time a piece lands, you should check for full horizontal rows. If one or more full rows exist, they should be removed. Consider one row at a time. If a row is full, all squares in that row should be removed from the landed arrays, and any squares in the landed arrays that are above the full row should move down one row. Then continue your test by checking the squares that have moved into that row.
Each time a full row is found and removed, increase the game score by one. Add the score to your game over message from question 4, displaying the number of rows that the user filled.
As part of your solution to Question 6, implement:
• A function int clearFullRows(int[] x,
int[] y, int n) that will accept the landed arrays and the number of entries in those arrays as parameters, and will return the new number of entries in the arrays. The arrays themselves should be modified by this function (or a function called by this function).
5

ASSIGNMENT 5
DEPARTMENT AND COURSE NUMBER: COMP 1010
• A function boolean rowFull(int[] y, int n, int row) that will search the given array of row numbers (containing n entries) for entries with the given row number. Count the number of entries in the given row, compare to NUM_COLS, and return true if the row is full.
• A function int removeRow(int[] x, int[] y, int n, int row), where x and y are the arrays of landed pieces, n is the number of entries in those arrays, and row is the row number for the row you want to remove. This function should remove the row and shift all higher pieces down one row. Return the new number of entries in the arrays.
• A function int deleteItem(int[] items, int numItems, int index) that removes the entry at position index from the array. All later entries in the array should be shifted over by one position to fill the hole, and the new number of entries in the array should be returned.
Question 7 [2 marks]
Implement the following two features to finish your game.
• Add Levels: After every 5 complete rows, the game should move up a level. The rate at
which the pieces are falling should become faster, making the game harder.
• Play Again: Add the ability for the user to press a key to start a new game. When the
game is over, your game over message should tell the user which key needs to be pressed to start a new game. When that key is pressed, the board should be cleared (i.e. the falling and landed arrays reset), the game should start again from level 1 (the slowest level) and the score should start again from zero.
Hand In:
Hand in one pde file only, containing the answer to the highest question you completed. It must run without errors, or you will lose all of the marks for the test run.
Make sure your file is named exactly as specified in the instructions at the beginning of the assignment.
The marker will run your program, and may change the value of any constants. It should still work if any constants are changed in a reasonable way. You may assume that if the cell size, or number of cells, is changed, the canvas size will be set accordingly.
6


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:dmxyzl003


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

发表评论