Question: Assignment for Snake game app - need help on how to proceed with the assignment. Java doc given is posted below: Package snake Class Level
Assignment for Snake game app - need help on how to proceed with the assignment. Java doc given is posted below:
Package snake Class Level java.lang.Object snake.Level
public class Level extends java.lang.Object This class defines the Level for use in the Snake game. It will control major portions of the game like updating the Snake and Item positions and determining when the game has been lost.
Constructor Summary
Level(int widthIn, int heightIn, java.util.Random randIn) Creates a default level with a given dimension.
void generateMap() Generates the 2-dimensional map of the game area.
GameState getGameState() Returns the current GameState.
Item getItem() Returns the current Item.
int[][] getMap() Returns the current 2d array map.
Snake getSnake() Returns the current Snake.
void updateOneStep() Updates a single step.
Constructor Detail Level public Level(int widthIn, int heightIn, java.util.Random randIn) Creates a default level with a given dimension. The map should use the given height and width values as its dimensions. The Snake and Item should be be the default version of themselves. The Random object passed in should be used in creation of new positions for the Item. The GameState should initially be PLAYING. Parameters: widthIn - - The logical width of the new level. heightIn - - The logical height of the new level. randIn - - The Random object that will be used to generate new Item locations.
updateOneStep public void updateOneStep() Updates a single step. The algorithm you use should go as follows: 1) Move the Snake in its current direction 2) Determine if a losing condition has been met (the Snake hitting itself or a wall) 3) Determine if the Item has been grabbed by the Snake. If it has, generate the new position for the Item. Generate the X value for the new Item position, then the Y value for the new Item position. If the position generated is currently being occupied by the Snake, regenerate another position and check again. Do this until a valid position has been found. If the Item was grabbed, be sure to increase the length of the Snake as well.
generateMap public void generateMap() Generates the 2-dimensional map of the game area. Please read the supplemental document on the differences between how the game map should look vs the Snake. The following pattern should be used for the map: If the space is open, place a 0 in that place in the map If the space is occupied by the Snake, place a 1 in that place in the map If the space is occupied by the Item, place a -1 in that place in the map
public Item getItem() Returns the current Item. Returns: - The current Item.
public Snake getSnake() Returns the current Snake. Returns: - The current Snake.
public int[][] getMap() Returns the current 2d array map. Returns: - The current 2d array map.
public GameState getGameState() Returns the current GameState. Returns: - The current GameState.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
