import greenfoot.*; // imports Actor, World, Greenfoot, GreenfootImage
import java.util.List;
import java.util.ArrayList;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.swing.*;
public class Etch extends Mouse
{
//set values for all directions
private int direction;
private static final int NORTH = 1;
private static final int EAST = 2;
private static final int SOUTH = 3;
private static final int WEST = 4;
//set up wall number int
int wallNumber;
//set up routes and shortest path ints
int routeValue = 0;
int shortPathValue = 0;
//set up boolean for reached center
boolean reachedCenter = false;
//set up arrays
int visited[][] = new int [16][16];
int route[][] = new int [16][16];
int path[][] = new int [16][16];
int deadEnd[][] = new int [16][16];
int returnPath[][] = new int [16][16];
public Etch()
{
//Mouse information for the scorer
super("Etch","Ryan","Orcimsoft");
//Scale and set image for use on the maze
GreenfootImage i = new GreenfootImage( "images/tux.png" );
i.scale( 20, 20 );
setImage( i );
setDirection(NORTH);
}
public void act()
{
//check if any of the center squares have been visited
if (route[7][7]==0 || route[7][8]==0 ||route [8][8]==0 || route [8][7]==0)
{
reachedCenter = false; //set reachedCenter as false if not
}
if (canMove())
{
move();
getWalls();
}
}//end act
public void move()
{
int cellX = getX()/4;
int cellY = getY()/4;
//have we reached center?
reachedCenterC();
//add number to visited trail so provides number path
visited[cellX][cellY] = visited[cellX][cellY] + 1;
//set value of first cell to first number in route
route[0][15] = 1;
}//end move
//all the main move methods - left, right, return home.
public void moveLeft()
{
int x = getX();
int y = getY();
World myWorld = getWorld();
switch(direction) {
case SOUTH :
setDirection(EAST);
setLocation(getX() + 4, getY());
break;
case EAST :
setDirection(NORTH);
setLocation(getX(), getY() - 4);
break;
case NORTH :
setDirection(WEST);
setLocation(getX() - 4, getY());
break;
case WEST :
setDirection(SOUTH);
setLocation(getX(), getY() + 4);
break;
}
}//end move left
public void moveRight()
{
int x = getX();
int y = getY();
World myWorld = getWorld();
switch(direction) {
case SOUTH :
setDirection(WEST);
setLocation(getX()-4, getY() );
break;
case EAST :
setDirection(SOUTH);
setLocation(getX(), getY() + 4);
break;
case NORTH :
setDirection(EAST);
setLocation(getX()+4, getY() );
break;
case WEST :
setDirection(NORTH);
setLocation(getX(), getY() - 4);
break;
}
} //end move right
//end all the main move methods section
public boolean canMove()
{
World myWorld = getWorld();
//get x and y co-ords and change to cell values
int x = getX();
int y = getY();
int cellX = getX()/4;
int cellY = getY()/4;
//check for outsideborder
if (x >= myWorld.getWidth() || y >= myWorld.getHeight())
{
return false;
}
else if (x < 0 || y < 0)
{
return false;
}
return true;
}//end canMove
public void reachedCenterC()
{
if ((visited[7][7])>(visited[0][15]))
{
reachedCenter = true;
route[0][15] = 0;
}
else
{
reachedCenter = false;
};
}//end reachedCenterC
public void getWalls()
{
World myWorld = getWorld();
//get x and y co-ords and change to cell values
int x = getX();
int y = getY();
int cellX = getX()/4;
int cellY = getY()/4;
//get surrounding wall information
List northBrick = myWorld.getObjectsAt(x,y-2, Brick.class);
List eastBrick = myWorld.getObjectsAt(x+2,y, Brick.class);
List southBrick = myWorld.getObjectsAt(x,y+2, Brick.class);
List westBrick = myWorld.getObjectsAt(x-2,y, Brick.class);
//wall number set to 4 and then value removed later
wallNumber = 4;
//remove one from the wall number for each wall around cell
if (northBrick.isEmpty())
{
wallNumber--;
}
if (eastBrick.isEmpty())
{
wallNumber--;
}
if (southBrick.isEmpty())
{
wallNumber--;
}
if (westBrick.isEmpty())
{
wallNumber--;
}
}//end checkWalls
public void setDirection(int direction)
{
this.direction = direction;
switch(direction)
{
case SOUTH :
setRotation(90);
break;
case EAST :
setRotation(0);
break;
case NORTH :
setRotation(270);
break;
case WEST :
setRotation(180);
break;
default :
break;
}
}//end setDirection
}//end class bracket