Assignment 5: The Snake Game


Question 5: Detect Crashes [4 marks



Download 291.77 Kb.
View original pdf
Page7/7
Date10.03.2024
Size291.77 Kb.
#63800
1   2   3   4   5   6   7
Assignment5-COMP1010-Fall2022
ComputerNetworks
Question 5: Detect Crashes [4 marks
When the snake leaves the canvas, or the head of the snake hits any other part of the snake (biting itself, then the game should end, and a Game Over message should be displayed. Define a function
boolean detectCrash()
which will return true if either of these things has happened, and the game should end. It must use the
searchArrays
function from Question 4 to detect when the snakebites itself. You can reuse the
void printGameOver()
function from Assignment 2 to display the message when the game ends, or write anew one. When the game is over, the game should freeze. The snake should stop moving and nothing else should happen. The user must close the canvas and restart the program to play again.

ASSIGNMENT 5: The Snake Game DEPARTMENT AND COURSE NUMBER COMP 1010 6
Question 6: Add Levels [1 mark
Add code so that when the last apple is eaten, anew level begins. Define ab void newLevel()

function that starts anew level. The snake should go back to the top centre of the canvas, with only its head showing, moving down. Anew set of apples should appear. The snake should move faster, start longer, and grow faster when it eats apples. There should be more apples. Experiment with your own set of values for these things. The game should get more difficult, so that it becomes impossible before level 10 is reached, but the first few levels should not be too difficult.
[Programming Standards are worth 6 marks

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