isWin=false;
nbInit();//NetBeans定义的初始化函数
}catch (Exception e) {
e.printStackTrace();
}
}
private void Init_game(){
//初始化游戏,读取地图,设置选择区域,清空要移动到的区域
this.currentCursor = MyMap.read_map(this.level);//读取地图文件,并返回光标的初始位置
//0为水平位置,1为竖直位置, 2为宽,3为高.
nextCursor[0]=currentCursor[0]; //初始化要移动到的区域
nextCursor[1]=currentCursor[1];
nextCursor[2]=currentCursor[2];
nextCursor[3]=currentCursor[3];
}
private void nbInit() throws Exception {//NetBeans定义的初始化函数
//初始化实例变量
Images.init();//初始化图片常量
Init_game();//初始化游戏,读取地图,设置选择区域,清空要移动到的区域
//setCommandListener(this);//添加命令监听,这是Displayable的实例方法
//addCommand(CMD_PAUSE);//添加“暂停”按钮
}
public void commandAction(Command command, Displayable displayable) {
//命令处理函数
}
protected void paint(Graphics g) {
//画图函数,用于绘制用户画面,即显示图片,勾画选中区域
try {
g.drawImage(Images.image_Frame, 0, 0,Graphics.TOP | Graphics.LEFT);//画背景
MyMap.draw_map(g);//按照地图内容画图
g.setColor(0, 255, 0);//绿色画笔
g.drawRect(this.currentCursor[0] * Images.UNIT + Images.LEFT,
this.currentCursor[1] * Images.UNIT + Images.TOP,
this.currentCursor[2] * Images.UNIT,
this.currentCursor[3] * Images.UNIT);//画出选择区域,
g.setColor(255,255,255);//恢复画笔颜色
}catch (Exception ex) {
}
//显示步数
Draw.paint(g,String.valueOf(moves), 60, 15, Graphics.BASELINE | Graphics.HCENTER);
if ( win()) {
isWin=true;
Draw.paint(g,"你赢了!", 60, 70, Graphics.TOP | Graphics.HCENTER);
}
}
private void setRange() {
//设置移动后能够选中的区域
//调整当前光标位置到地图的主位置,即记录人物信息的位置
if (this.MyMap.Grid[this.currentCursor[1]][this.currentCursor[0]] == Images.DLEFT) {
this.currentCursor[0] -= 1;//向左调
}else if (this.MyMap.Grid[this.currentCursor[1]][this.currentCursor[0]] == Images.DUP) {
this.currentCursor[1] -= 1;//向上调
}else if (this.MyMap.Grid[this.currentCursor[1]][this.currentCursor[0]] == Images.DLEFTUP) {