Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

URGENT! Can you write these methods for me in JAVA (if you're confused about specifications, just give me a rough idea of how to write

URGENT! Can you write these methods for me in JAVA (if you're confused about specifications, just give me a rough idea of how to write them, DO NOT ASK ME FOR MORE DETAIL... if anything just make up your own variables, I just need an idea)

image text in transcribed

void moveSnake(String direction): moves the snake in the specified direction; this means that array snakeBody must be updated so it contains the positions of the grid squares that the snake will occupy after it moves in the direction specified by the parameter. For example, for the snake in the above figure array snake Body is as specified above. If direction = "up" then array snakeBody must be this (0,2) 0 (1, 2) 1 (1, 1) 2 (1,0) 3 4 If direction is up" again then array snakeBody must be this (-1, 2) (0, 2) (1, 2) (1,1) 0 1 2 34 Notice that to determine the new array snake Body what you must do is this: o shift one position to the right all values in the array stored in indices 0 to snakeLength - 2. For example, if the snake is as in the figure and direction="right", then shifting produces this array: (1, 3) (1,3) 0 (1,2) 1 =(1,1)+(1,0) 2 3 (1, 3) 1 (1,2) 2 (1,1) 3 4 4 o and then store in index 0 of the array the new position of the snake's head (which you can compute using method newHeadPostion(); in the above example we would store (1,4) in the first entry of the array. void grow(String direction): increases the length of the snake by 1 and moves the snake's head in the direction specified. This method is very similar to method moveSnake, but instead of shifting the values in snakeBody from index 0 to snakeLength - 2, we need to shift all values from index 0 to index snakeLength - 1. For example, if the snake is as shown in the figure, and direction="right" then the new content of array snake Body is (1, 3) 0 (1,2) 1 (1,1) 2 (1,0) 3 (2,0) 4 Notice that since the length of the snake grows you need to make sure that array snakeBody is large enough to store the new information. If instance variable snakeLength has the same value as snakeBody.length(), the size of the array, then you must double the size of the array before storing the new positions of the snake in it. To do this you must use the below private method increaseArraySize(). void moveSnake(String direction): moves the snake in the specified direction; this means that array snakeBody must be updated so it contains the positions of the grid squares that the snake will occupy after it moves in the direction specified by the parameter. For example, for the snake in the above figure array snake Body is as specified above. If direction = "up" then array snakeBody must be this (0,2) 0 (1, 2) 1 (1, 1) 2 (1,0) 3 4 If direction is up" again then array snakeBody must be this (-1, 2) (0, 2) (1, 2) (1,1) 0 1 2 34 Notice that to determine the new array snake Body what you must do is this: o shift one position to the right all values in the array stored in indices 0 to snakeLength - 2. For example, if the snake is as in the figure and direction="right", then shifting produces this array: (1, 3) (1,3) 0 (1,2) 1 =(1,1)+(1,0) 2 3 (1, 3) 1 (1,2) 2 (1,1) 3 4 4 o and then store in index 0 of the array the new position of the snake's head (which you can compute using method newHeadPostion(); in the above example we would store (1,4) in the first entry of the array. void grow(String direction): increases the length of the snake by 1 and moves the snake's head in the direction specified. This method is very similar to method moveSnake, but instead of shifting the values in snakeBody from index 0 to snakeLength - 2, we need to shift all values from index 0 to index snakeLength - 1. For example, if the snake is as shown in the figure, and direction="right" then the new content of array snake Body is (1, 3) 0 (1,2) 1 (1,1) 2 (1,0) 3 (2,0) 4 Notice that since the length of the snake grows you need to make sure that array snakeBody is large enough to store the new information. If instance variable snakeLength has the same value as snakeBody.length(), the size of the array, then you must double the size of the array before storing the new positions of the snake in it. To do this you must use the below private method increaseArraySize()

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

d. How were you expected to contribute to family life?

Answered: 1 week ago