Assignment 5: The Snake Game



Download 291.77 Kb.
View original pdf
Page3/7
Date10.03.2024
Size291.77 Kb.
#63800
1   2   3   4   5   6   7
Assignment5-COMP1010-Fall2022
ComputerNetworks
x[i]
,
y[i]
) specified by the first
n
elements of the
x
and
y
arrays, and with the specified
colour
. The
x
and
y
values are in grid coordinates, not pixels. To fill arrays with data, define a function
void fillArray(int[] a, int n, int start, int
delta)
which will fill the first
n
elements of the array
a
with data. The first element should beset to
start
, and each element after that should differ from the previous one by
delta
. For example,
fillArray(a,5,6,1)
should set the first 5 elements of
a
to 6,7,8,9,10 (start at 6 and go up by 1), and
fillArray(a,4,2,-1)
should set the first 4 elements of
a
to 2,1,0,-1 (start at 2 and go down by
1). To test your two functions, put them into the supplied file
TemplateA5Q0.pde
, and run that file. You do not need to write anything else. The program should produce the image shown above. You can get a few hints for future questions by looking at the supplied code.

ASSIGNMENT 5: The Snake Game DEPARTMENT AND COURSE NUMBER COMP 1010 3
Question 1: Simple Snake [4 marks
Start anew program. Define
ROWS
,
COLS
, and
SQ_SIZE
, and use the correct values in the
size
command, as in Phase 0. Add your
drawCircles
and
fillArray
functions from Phase 0. Use global partially-full arrays to store the (x,y) coordinates of all of the circles that form the snake (as grid coordinates, not pixels. This includes a variable to control the current length of the snake. Make the arrays big enough to store a snake that fills the entire canvas which will never happen, but it will give you plenty of room. Define a variable

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