Snake (Part 18/20)

  • 3
  • Locked
Let's fix our snake control. The direction field can only be changed to currently valid values: LEFT, RIGHT, UP, and DOWN.
You can't complete this task, because you're not signed in.
Comments (10)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Josephine
Level 26 , Normal, United States
29 October 2020, 17:48
I have no idea why UP and DOWN Direction not passing....Someone please help
Roman
Level 41
30 October 2020, 11:16
Please post your question with the attached solution in the section Help.
Josephine
Level 26 , Normal, United States
30 October 2020, 14:23
Roman,I am not able to do that..Here is the sceenshot when i an trying to do that.
Josephine
Level 26 , Normal, United States
30 October 2020, 14:34
i have already reported to olha..I am stuck at part 18/snake.
Roman
Level 41
2 November 2020, 06:42
please fill "Short question" field (on your screenshot)
Josephine
Level 26 , Normal, United States
2 November 2020, 15:50
Will try.I reset the game and started again
Josephine
Level 26 , Normal, United States
5 November 2020, 21:58
I have posted my question ,please help
Stefano Re
Level 5 , Catania, Italy
13 March 2020, 23:05
There are some mistakes in the requirements. If you follow strictly the requirements, you won't pass the test. DIrection shoulldn't change If the value of the direction field is LEFT (or RIGHT), and the snake segments with indices 0 and 1 in the snakeParts list have the same (not x) but Y coordinate; and if the direction is set to UP or DOWN and the snake segments with indices 0 and 1 in the snakeParts list have the same (not y) but X coordinate.
Dyrits
Level 22
19 July 2020, 09:16
Exactly!
DarthGizka
Level 24 , Wittenberg, Germany
9 June 2021, 16:00
Things are bit trickier than that. The 'same x' condition for the first two segments means that the snake is currently moving vertically; this means the direction field must have had the value UP or DOWN during the last game update cycle. If the snake is currently moving vertically and the direction field is currently LEFT or RIGHT then this direction change must have been keyed in since the last game tick. Hence the new condition keeps you from changing your mind after changing direction, until the next game tick. My submission passed implementing the requirements as specified, i.e. suppressing a direction change away from UP/DOWN if same Y (i.e. last move horizontal) and away from LEFT/RIGHT if same X (i.e. last move vertical).