Here is snakeworld


Can someone please provide me the code for the snake project of a+ computer science? 
Here is SnakeWorld:
import java.awt.Color;
import java.util.ArrayList;
import info.gridworld.grid.Grid;
import info.gridworld.actor.Actor;
import info.gridworld.grid.Location;
import info.gridworld.actor.ActorWorld;
import info.gridworld.grid.BoundedGrid;

public class SnakeWorld extends ActorWorld
{
private int foodDelay;
private Snake snake;
private boolean gameOn=true;

public SnakeWorld(int width, int height)
{
super(new BoundedGrid(width, height));
Grid grid = getGrid();
snake = new Snake();
snake.putSelfInGrid(grid, new Location(4,7));
foodDelay = (int)(Math.random()*grid.getNumRows() * 3);
setMessage("The Snake Game - Eat as many monkees as you can!");
}

public void step()
{
if(snake.isDead())
{
setMessage("Your snake is dead! He ate "+ snake.getFoodEaten() + " monkees!");
}
else
{
//make sure the Grid is not null

setMessage("The Snake Game!!! - " + snake.getFoodEaten() + " monkees eaten so far!");

//make the Snake move


//if there is no Food
//add some Food
}
}

public boolean isFoodAllGone()
{
//check the grid to see if any Food remains
//instanceof might prove useful

return true;
}

public void addFood()
{
//write the code to randomly place 1 Food in the grid
}

public boolean keyPressed(String description, Location loc)
{
//write the code to change the direction of the Snake 
if(!gameOn)
{
return true;
}
ArrayListlocs = getGrid().getOccupiedLocations();
for(int i = locs.size()-1; i>=0; i--)
{
if(!getGrid().get(locs.get(i))instanceof Snake)
{
locs.remove(i);
}
}

Snake snake = (Snake)(getGrid().get(locs.get(0)));
if(description.equals("LEFT"))
{
snake.setDirection(Location.WEST);
}
if(description.equals("RIGHT"))
{
snake.setDirection(Location.EAST);
}
if(description.equals("UP"))
{
snake.setDirection(Location.NORTH);
}
if(description.equals("DOWN"))
{
snake.setDirection(Location.SOUTH);
}
return true;

}
}


Here is Snake:
import java.awt.Color;
import java.util.ArrayList;
import info.gridworld.grid.Grid;
import info.gridworld.actor.Actor;
import info.gridworld.actor.ActorWorld;
import info.gridworld.world.World;
import info.gridworld.grid.Location;
import info.gridworld.grid.BoundedGrid;

public class Snake
{
private Actor head;
private Actor tail;
private int foodEaten;
private boolean didEat;
private boolean isDead;

public Snake()
{
head = new Section();
head.setDirection(0);
tail = head;
foodEaten = 0;
isDead = false; 
}

public void putSelfInGrid(Grid grid, Location loc)
{
head.putSelfInGrid(grid, loc);


public void move()
{
//make sure snake is not dead and that the grid is not null
if(isDead = false && !(head.getGrid()==null))
{
Gridgr = head.getGrid();
Section snake = new Section();
int direction = head.getDirection();
Location headloc = head.getLocation();
Actor neighbor = gr.get(headloc);

if(gr.isValid(headloc) && gr.get(headloc)==null)
{
}
}


//make new Section for this Snake
//get the location of where this new Section might appear


//check for valid location

//check to see if this spot is not null


//check to see if a Snake Section found



//else check to see if Food found





//if spot is null
//move up to this spot

//remove the tail is snake is trying to move off the grid

}

public void removeTail()

Gridgr = tail.getGrid();
Location tailLoc = tail.getLocation();
int tailDir = tail.getDirection();
Location front = tailLoc.getAdjacentLocation(tailDir);
tail.removeSelfFromGrid();

//if the snake is moving normally
//the tail gets removed as a new section is added to the front

}

public void setDirection(String dir)
{
//change the direction of the head of the snake


}

public int getFoodEaten()
{
return 0;
}

public void setFoodEaten(int amount)
{

}

public boolean isDead()
{
return false;
}
}


Here is Section:
import java.awt.Color;
import info.gridworld.actor.Actor;

public class Section extends Actor
{
public Color getColor(){
return null;
}
}


Here is Food:
import java.awt.Color;
import info.gridworld.actor.Actor;

public class Food extends Actor
{
public Color getColor(){
return null;
}

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Here is snakeworld
Reference No:- TGS081850

Expected delivery within 24 Hours