w][column]);
}
}
edgePosition = new Position(mazeMap.length, mazeMap[0].length);
}
public Position getPrincePosition()
{
return princePosition;
}
public Position getPrincessPosition()
{
return princessPosition;
}
/**
* 解析迷宫的位置信息
*/
private void parseMazePosition(Position currentPosition, char thing)
{
switch (thing)
{
case '.':
getAllReachablePositions().add(currentPosition);
break;
case '*':
break;
case 'S':
setPrincePosition(currentPosition);
break;
case 'P':
setPrincessPosition(currentPosition);
break;
default:
throw new UnknownElementException(null, thing);
}
}
private Position getOriginPosition()
{
return originPosition;
}
private Position getEdgePosition()
{
return edgePosition;
}
private void setPrincePosition(Position princePosition)
{
this.princePosition = princePosition;
}
private void setPrincessPosition(Position princessPosition)
{
this.princessPosition = princessPosition;
}
private List getAllReachablePositions()
{
return allReachablePositions;
}
}
[java]
import javax.lang.model.element.UnknownElementException;
/**
* 迷宫类:包含王子和迷宫地图两个对象
*
*/
public class Maze
{
/**
* 王子
*/
private Prince prince;
/**
* 迷宫地图
*/
private MazeMap map;
private boolean isInitOK = true;
public Maze(int time, char[][] map)
{
this.map = new MazeMap();
prince = new Prince(time);
initMap(map);
}
public void initMap(char[][] map)
{
try
{
getMap().initMazeMap(map);
getPrince().setMap(getMap());
}
catch (UnknownElementException e)
{
// TODO log
isInitOK = false;
}
}
/**
* 游戏开始:返回结果:-1表示营救失败;0表示营救成功
*
*/
public int start()
{
if (!isInitOK)
{
return -1;
}
return getPrince().startToSearch();
}
private MazeMap getMap()
{
return map;
}
private Prince getPrince()
{
return prince;
}
}
import javax.lang.model.element.UnknownElementException;
/**
* 迷宫类:包含王子和迷宫地图两个对象
*
*/
public class Maze
{
/**
* 王子
*/
private Prince prince;
/**
* 迷宫地图
*/
private MazeMap map;
private boolean isInitOK = true;
public Maze(int time, char[][] map)
{
this.map = new MazeMap();
prince = new Prince(time);
initMap(map);
}
public void initMap(char[][] map)
{
try
{
getMap().initMazeMap(map);
getPrince().setMap(getMap());
}
catch (UnknownElementException e)
{
// TODO log
isInitOK = false;
}
}
/**
* 游戏开始:返回结果:-1表示营救失败;0表示营救成功
*
*/
public int start()
{
if (!isInitOK)
{
return -1;
}
return getPrince().startToSearch();
}
private MazeMap getMap()
{
return map;
}
private Prince getPrince()
{
return prince;
}
}
[java]
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 王子
*
* 类名称:Prince 类描述: 创建人:dobuy
*
*/
public class Prince
{
/**
* 营救公主失败
*/
private final static int FAIL = -1;
/**
* 营救公主成功
*/
private final static int SUCCESS = 0;
/**
* 剩余的时间
*/
private int time;
/**
* 迷宫地图
*/
private MazeMap map;
/**
* 正待尝试的位置集合(开启列表)
*/
private List attemptPositions;