程序实现搜索迷宫出口完整版(一)

2014-11-24 11:30:19 · 作者: · 浏览: 27
import java.awt.*;
import java.awt.List;
import java.awt.event.*;
import java.util.*;
import javax.swing.JOptionPane;
//驱动类
public class tanchishe
{
public static void main(String[] args)
{
new MainFrame("迷宫 破解").addWindowListener(new WindowAdapter() //添加窗口关闭处理函数
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}});
}
}
//路径对象
class Rect{
int wx;
int wy;
int NowValue;
int PointerTo;
public Rect(int wx,int wy){
this.wx = wx;
this.wy = wy;
}
public int GetX() {
//获得x坐标
return wx;
}
public int Gety() {
//获得y坐标
return wy;
}
public int GetNowValue() {
//获得当前路径下的数组中的值
return NowValue;
}
public void SetNowValue(int NowValue) {
//5代表已走过的路径
//4代表无法走通的路径
//3代表当表终点
this.NowValue = NowValue;
}
public int GetPointerTo() {
//获得此路径的方向
return PointerTo;
}
public void SetPointerTo(int PointerTo) {
//设置当前路径的方向值
this.PointerTo = PointerTo;
}
public String toString() {
//输出路径各个属性
return ("wx is:" + wx + "wy is:" + wy + "NowValue is:"
+ NowValue + "PointerTo is:" + PointerTo);
}
}
//此线程负责操作栈中的数据
/*
class stack_thread implements Runnable
{
@Override
public void run() {
// TODO Auto-generated method stub
}
}
***/
//游戏界面
class MainFrame extends Frame
{
private static final long serialVersionUID = 1L;
Map map = new Map(2); //默认进入游戏的第二关
//绘制游戏界面
//开始,暂停,选关标签,输入关卡的文本编辑框,游戏画面
Button a = new Button("开始");
Button b = new Button("暂停");
Button c = new Button("退出");
Button l = new Button("进入");
Label ll = new Label("关卡");
TextField t = new TextField(15);
List lst = new List(4, false);
List lll = new List(4);
Rectangle r = new Rectangle(60,10);
Init_GameArea init = new Init_GameArea(this,t,map); //初始化游戏界面
Paint st = new Paint() ; //实现了绘图的线程
Thread Painter = new Thread(st); //继承了runnable接口
boolean flag = true;
boolean gameflag; //判断游戏是否结束的标志
int Nowx; //探索迷宫出口的起始x坐标
int Nowy; //探索迷宫出口的起始y坐标
Stack stack = new Stack(); //保存路径对象的栈
MainFrame(String s){
//窗口的布局
super(s);
setLayout(new FlowLayout());
Panel p = new Panel();
p.setLayout(new FlowLayout());
a.setBounds(r);
b.setBounds(r);
c.setBounds(r);
l.setBounds(r);
ll.setBounds(r);
lst.setBounds(r);
p.add(ll);
p.add(t);
p.add(l);
p.add(lst);
p.add(a);
p.add(b);
p.add(c);
lst.add("第一关",1);
lst.add("第二关",2);
lst.add("第三关",3);
lst.add("第四关",4);
add(p);
lst.addItemListener(new ItemMonitor());
lst.addActionListener(new ItemActionMonitor());
a.addActionListener(new Monitor());
b.addActionListener(new Monitor());
c.addActionListener(new Monitor());
l.addActionListener(new Monitor());
a.setForeground(Color.PINK);
b.setForeground(Color.PINK);
c.setForeground(Color.PINK);
l.setForeground(Color.CYAN);
ll.setBackground(Color.CYAN);
setBounds(200,200,670,678);
this.setBackground(Color.BLUE);