Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It's Javascript. It's one of the array practice problem on codeHS. . Write a program that makes a snake with a fixed length move around

image text in transcribedIt's Javascript. It's one of the array practice problem on codeHS.
. Write a program that makes a snake with a fixed length move around the screen. The segments should follow the snakehead's path, traveling the exact route that it took . Your snake should move SNAKE_DIM each frame your snake movement will not be as smooth as the demo, but don't worry about that Your Snake must stay on an imaginary grid with grid squares exactly SNAKE_DIM X SNAKE_DIM To do that, you must move SNAKE_DIM every frame Helpful hints Start with a program like basic snake that simply moves a green rectangle (the snake head constantly The snake should start out moving east. When the user presses an arrow key, the snake should change direction to the direction of the arrow o When the snake crosses an edge of the canvas, it should appear at the opposite edge Create an array and fill it with at least 3 more green rectangles that are the same size and color as the snake head o The initial segments should be extended behind the snake o When the snake moves, the segments follow the same path the head took If you get stuck when developing a strategy for making the segments follow the head, here are some options Follow the leader . Going from back to front, tell each segment to move to the position of the next segment Tell the segment behind the head to go to the head Move the head in the current direction Shifty-Push o For this strategy, the you must consider the last item of the array to be the head for the segment just behind the head if the head is separate from the array) o renove the first segment from the array (shift) and add it to the end of the array (push) If the head is separate from the artay, move the item you pushed to the position of the head and then move the head If the head is part of the array, then the head must be the segment you pushed, which means it should be placed at the next position to move to Pop goes to the front of the linel o Th last segment becomes the new head pop the last item off the end of the array and insert it at the front of the arty o Mc e the segment you popped to the next position where the snake should move. Alt math y, the head could be separate from the array, in which case, you would place the segment you popped at the position of the head and then move the head. This would mean the first item in the array is the segment immediately behind the head . For this strategy you might want to investigate the splice function (you can google "javascript splice"), . Write a program that makes a snake with a fixed length move around the screen. The segments should follow the snakehead's path, traveling the exact route that it took . Your snake should move SNAKE_DIM each frame your snake movement will not be as smooth as the demo, but don't worry about that Your Snake must stay on an imaginary grid with grid squares exactly SNAKE_DIM X SNAKE_DIM To do that, you must move SNAKE_DIM every frame Helpful hints Start with a program like basic snake that simply moves a green rectangle (the snake head constantly The snake should start out moving east. When the user presses an arrow key, the snake should change direction to the direction of the arrow o When the snake crosses an edge of the canvas, it should appear at the opposite edge Create an array and fill it with at least 3 more green rectangles that are the same size and color as the snake head o The initial segments should be extended behind the snake o When the snake moves, the segments follow the same path the head took If you get stuck when developing a strategy for making the segments follow the head, here are some options Follow the leader . Going from back to front, tell each segment to move to the position of the next segment Tell the segment behind the head to go to the head Move the head in the current direction Shifty-Push o For this strategy, the you must consider the last item of the array to be the head for the segment just behind the head if the head is separate from the array) o renove the first segment from the array (shift) and add it to the end of the array (push) If the head is separate from the artay, move the item you pushed to the position of the head and then move the head If the head is part of the array, then the head must be the segment you pushed, which means it should be placed at the next position to move to Pop goes to the front of the linel o Th last segment becomes the new head pop the last item off the end of the array and insert it at the front of the arty o Mc e the segment you popped to the next position where the snake should move. Alt math y, the head could be separate from the array, in which case, you would place the segment you popped at the position of the head and then move the head. This would mean the first item in the array is the segment immediately behind the head . For this strategy you might want to investigate the splice function (you can google "javascript splice")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

explain what is meant by redundancy

Answered: 1 week ago

Question

Explain the different types of Mergers.

Answered: 1 week ago

Question

What is dividend payout ratio ?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago