Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logic for death on body collision #66

Closed

Conversation

purnatadikonda5
Copy link

#4
This code will check the number of snake body parts are present in particular coordinates.
If more than 1 exists then it means snake bites itself and it will end the game.

CHANGES MADE:
Added arr[x][y]++; which will tells the number of body parts of snake present in particular coordinates
Added a condition that to check if arr[x][y]>1 it means snake bites itself .
It will work with O(1) complexity

previously added: added an array which will store 1 when the snake exists at particular coordinates else 0
video : 1) checking to go in opposite direction
2) checking to bite the snake body

Screen.Recording.2024-03-17.at.1.13.22.PM.1.1.1.1.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants