Assignment 5: The Snake Game


It is strongly recommended that you experiment with the assignment 5 demos posted on the



Download 291.77 Kb.
View original pdf
Page2/7
Date10.03.2024
Size291.77 Kb.
#63800
1   2   3   4   5   6   7
Assignment5-COMP1010-Fall2022
ComputerNetworks
It is strongly recommended that you experiment with the assignment 5 demos posted on the
COMP 1010 website, to see how the game is supposed to work.
It is also strongly recommended that you complete each question of the assignment before writing any code for the next question. Plan your program on paper before coding. What functions will you use, and how will they interact with each other Read through the assignment several times. Making a plan before writing code reduces the amount of time you spend coding.
This assignment uses partially-filled arrays. You should complete Unit 19 before working on this
assignment.
Question 0: Basic Functions [4 marks
The canvas is treated as a grid of squares. There will be predefined constants
ROWS
and
COLS
giving the number of rows and columns in this grid, and a constant
SQ_SIZE
giving the size of each square (in pixels. These values are predefined for you in the supplied file
TemplateA5Q0.pde
. Note The
size
command in the
setup
function must always use a canvas size of
COLS*SQ_SIZE, ROWS*SQ_SIZE
so that the game will exactly fit in the canvas. (But you have to do the calculation manually since Processing will not allow expressions in the
size
command.) The position of a circle will not be given in pixels. It will always be a position in the grid, using an
x
value from
0
to
COLS-1
, and ab ybvalue from
0
to
ROWS-1
, with
0
at the top or left, as usual. The only things that have to be drawn in this assignment are sets of circles in the grid. The same function will be used to draw the snake, and also the apples. Define a function
void drawCircles(int[] x, int y, int n, int
colour)
which will draw
n
circles in the canvas, at the positions (

Download 291.77 Kb.

Share with your friends:
1   2   3   4   5   6   7




The database is protected by copyright ©ininet.org 2024
send message

    Main page