Snake (part 16)

  • 12
  • Locked
Nothing is forever... That's why the snake must die if it hits a wall or itself. There's a very simple check to determine whether a snake intersects itself: does the sections list contain a "new snake's head"? This is what the code will look like: if (sections.contains(head)).
You can't complete this task, because you're not signed in.
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Henrique
Level 41 , São Paulo, Brazil
23 July 2020, 19:13
Here it says "The head must not be added to the sections list, otherwise this condition will always be true.", but in part 8 it's written "create the first "piece of the snake" (the head) in the constructor and add it to the sections collection (ArrayList).". Is there something contradictory or I am misunderstanding something?
Mateusz
Level 29 , Poland
26 September 2020, 20:42
I think the next task explains it well. There are actually two heads. The new one which will be added to the list (but it's not there yet) and the previous one which becomes the second section of the snake once we add the new nead to the sections list.