JAVA please: In the game of Snake, a snake moves through the squares of a grid in the up, down, left and right direction
Posted: Fri Apr 29, 2022 6:55 am
JAVA please:
In the game of Snake, a snake moves through the squares of a
grid in the up, down, left and right directions according to the
player's commands.
In your game, the snake will move through a grid of 15 lines and 17
columns, and it will only move when it receives an order from the
player. The only invalid move is when the snake hits a
wall (trying to get off the grid).
Such moves will be ignored and the snake will remain in the same
position. The initial position of the snake is in the
middle of the board (line 8, column 9).
Rows and columns of the board are numbered starting with
1.
Find out how many valid trips the snake made.
Request:
In this issue you will need to write a Snake class that contains
the following methods:
● movement (int) - the number received as a parameter means the
direction in which the snake will move: 0 - up, 1 - right, 2 -
down, 3 - left
● Valid moves () - Returns the number of valid moves made by the
snake to the current time.
EXAMPLE
In the game of Snake, a snake moves through the squares of a
grid in the up, down, left and right directions according to the
player's commands.
In your game, the snake will move through a grid of 15 lines and 17
columns, and it will only move when it receives an order from the
player. The only invalid move is when the snake hits a
wall (trying to get off the grid).
Such moves will be ignored and the snake will remain in the same
position. The initial position of the snake is in the
middle of the board (line 8, column 9).
Rows and columns of the board are numbered starting with
1.
Find out how many valid trips the snake made.
Request:
In this issue you will need to write a Snake class that contains
the following methods:
● movement (int) - the number received as a parameter means the
direction in which the snake will move: 0 - up, 1 - right, 2 -
down, 3 - left
● Valid moves () - Returns the number of valid moves made by the
snake to the current time.
EXAMPLE