/**
* Defined direction for east (right).
*/
public static final int EAST = 0;
/**
* Defined direction for north (up).
*/
public static final int NORTH = 1;
/**
* Defined direction for west (left).
*/
public static final int WEST = 2;
/**
* Defined direction for south (down).
*/
public static final int SOUTH = 3;
private static final int[] directions = { NORTH,
EAST,
SOUTH,
WEST
};
/**
* Location of the image of karel facing north.
*/
private static final String nkarelLocation = "/icons/kareln.gif";
/**
* Location of the image of karel facing east.
*/
private static final String ekarelLocation = "/icons/karele.gif";
/**
* Location of the image of karel facing south.
*/
private static final String skarelLocation = "/icons/karels.gif";
/**
* Location of the image of karel facing west.
*/
private static final String wkarelLocation = "/icons/karelw.gif";
/**
* Image icon where the north-facing karel is loaed.
*/
private static ImageIcon nkarel = null;
/**
* Image icon where the east-facing karel is loaded.
*/
private static ImageIcon ekarel = null;
/**
* Image icon where the south-facing karel is loaded.
*/
private static ImageIcon skarel = null;
/**
* Image icon where the west-facing karel is loaded.
*/
private static ImageIcon wkarel = null;
/**
* Location of the image of karel facing north.
*/
private static final String nbmLocation = "/icons/bmn.gif";
/**
* Location of the image of karel facing east.
*/
private static final String ebmLocation = "/icons/bme.gif";
/**
* Location of the image of karel facing south.
*/
private static final String sbmLocation = "/icons/bms.gif";
/**
* Location of the image of karel facing west.
*/
private static final String wbmLocation = "/icons/bmw.gif";
/**
* Image icon where the north-facing karel is loaed.
*/
private static ImageIcon nbm = null;
/**
* Image icon where the east-facing karel is loaded.
*/
private static ImageIcon ebm = null;
/**
* Image icon where the south-facing karel is loaded.
*/
private static ImageIcon sbm = null;
/**
* Image icon where the west-facing karel is loaded.
*/
private static ImageIcon wbm = null;
public static int validateDirection(int dir) {
for (int i = 0; i < directions.length; i++)
if (dir == directions[i])
return dir;
return ((dir % 4) + 4) % 4; //This is in case it's negative
}
static ImageIcon getCharacterIcon(int direction, int app){
switch (direction) {
case NORTH:
{
if (app == 1) {
if (nbm == null)
nbm = new ImageIcon(Display.class.getResource(nbmLocation));
return nbm;}
else {
if (nkarel == null)
nkarel = new ImageIcon(Display.class.getResource(nkarelLocation));
return nkarel;}
}
case EAST:
{
if (app == 1) {
if (ebm == null)
ebm = new ImageIcon(Display.class.getResource(ebmLocation));
return ebm;}
else {
if (ekarel == null)
ekarel = new ImageIcon(Display.class.getResource(ekarelLocation));
return ekarel;}
}
case SOUTH:
{
if (app == 1) {
if (sbm == null)
sbm = new ImageIcon(Display.class.getResource(sbmLocation));
return sbm;}
else {
if (skarel == null)
skarel = new ImageIcon(Display.class.getResource(skarelLocation));
return skarel;}
}
case WEST:
{
if (app == 1) {
if (wbm == null)
wbm = new ImageIcon(Display.class.getResource(wbmLocation));
return wbm;}
else {
if (wkarel == null)
wkarel = new ImageIcon(Display.class.getResource(wkarelLocation));
return wkarel;}
}
default:
Debug.printError("Karel image or character for direction " + direction + " or " + appearance[app] + " not found! Aborting...");
System.exit(7);
return null;
}
}