import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.*;
import java.net.Socket;
import javax.swing.*;
public class LabyrinthFrame extends JFrame implements ActionListener,Runnable{
protected JLabel jlabel;
protected JLabel jlabel2;
protected JButton button;
protected JButton button2;
protected JButton button3;
protected Datas labyrinth[][];
protected JButton but[][];
protected Datas start,end;
protected LinkedStack<Datas> stack;
protected Thread thread;
protected Datas data;
protected Datas last;
protected FileOutputStream fout;
protected DataOutputStream objout;
protected FileInputStream fin;
protected DataInputStream objin1;
protected FileOutputStream fout1;
protected DataOutputStream objout1;
protected FileInputStream fin1;
protected DataInputStream objin;
protected FileOutputStream fout2[];
protected DataOutputStream objout2[];
protected FileInputStream fin2[];
protected DataInputStream objin2[];
/* protected FileOutputStream fout3[];
protected DataOutputStream objout3[];
protected FileInputStream fin3[];
protected DataInputStream objin3[];*/
protected int mark;
protected JComboBox<String> combox;
protected JRadioButton radiobs[];
static boolean isSure=false;
private PrintWriter cout;
private BufferedReader br;
Socket socket;
Socket socket1;
String road[][];
int num;
public LabyrinthFrame(Datas labyrinth[][],Datas start,Datas end,Socket socket)
{
data=start;
last=start;
stack=new LinkedStack<Datas>();
this.start=new Datas(start.isWhite,start.x,start.y);
this.end=new Datas(end.isWhite,end.x,end.y);
this.but=new JButton[labyrinth.length][labyrinth[0].length];
this.labyrinth=labyrinth;
try {
fout=new FileOutputStream("E:\\labyrinth.obj");
objout=new DataOutputStream(fout);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.setTitle("迷宫");
this.setBounds(300, 50, 860, 610);
GridLayout grid=new GridLayout(8,12);
ImageIcon img2=new ImageIcon("D:\\砖块.png");
jlabel=new JLabel();
jlabel.setLayout(new FlowLayout());
this.getLayeredPane().add(jlabel,"North");
jlabel.setBounds(0,0,850,40);
((JPanel)getContentPane()).setOpaque(false);
jlabel2=new JLabel();
jlabel2.setBounds(0,40,850,533);
jlabel2.setLayout(grid);
this.getLayeredPane().add(jlabel2);
for(int i=0;i<labyrinth.length;i++)
for(int j=0;j<labyrinth[0].length;j++)
{
but[i][j]=new JButton();
if(labyrinth[i][j].isWhite==true)
{
but[i][j].setBackground(Color.LIGHT_GRAY);
jlabel2.add(but[i][j]);
but[i][j].setBorderPainted(false);
}
else
{
but[i][j].setContentAreaFilled(false);
jlabel2.add(but[i][j]);
but[i][j].setIcon(img2);
but[i][j].setBorderPainted(false);
}
}
JSplitPane split=new JSplitPane(JSplitPane.VERTICAL_SPLIT,this.jlabel,this.jlabel2);
split.setDividerLocation(40);
this.add(split);
try
{
// fout = new FileOutputStream("E:\\radiobs.char");
// objout=new DataOutputStream(fout);
fin=new FileInputStream("E:\\radiobs.char");
objin=new DataInputStream(fin);
// fout1 = new FileOutputStream("E:\\num.int");
// objout1=new DataOutputStream(fout1);
fin1=new FileInputStream("E:\\num.int");
objin1=new DataInputStream(fin1);
}
catch (FileNotFoundException e1)
{
e1.printStackTrace();
}
try {
// objout1.writeInt(4);
num=objin1.readInt();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
fout2=new FileOutputStream[num-1];
objout2=new DataOutputStream[num-1];
fin2=new FileInputStream[num-1];
objin2=new DataInputStream[num-1];
/* try{
objout3[0]=new DataOutputStream(fout3[0]=new FileOutputStream("E:\\se1.int"));
objout3[0].writeInt(1);objout3[0].writeInt(0);objout3[0].writeInt(4);objout3[0].writeInt(11);
objout3[1]=new DataOutputStream(fout3[1]=new FileOutputStream("E:\\se2.int"));
objout3[1].writeInt(1);objout3[1].writeInt(0);objout3[1].writeInt(4);objout3[1].writeInt(11);
objout3[2]=new DataOutputStream(fout3[2]=new FileOutputStream("E:\\se3.int"));
objout3[2].writeInt(3);objout3[2].writeInt(0);objout3[2].writeInt(0);objout3[2].writeInt(9);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/
// objout3[h].writeInt(arg0);
// fin3=new FileInputStream[num-1];
// objin3=new DataInputStream[num-1];
String str[]=new String[num];
// String str[]={"地图1","地图2","地图3","自定义地图"};
int h;
for(h=0;h<num-1;h++)
{
String s="";
for(int y=0;y<3;y++)
{
try
{
s+=objin.readChar()+"";
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
str[h]=s;
}
str[h]="自定义地图";
/* for(h=0;h<num-1;h++)
{
for(int y=0;y<3;y++)
{
try
{
objout.writeChar(str[h].charAt(y));
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
}*/
this.combox=new JComboBox<String>(str);
jlabel.add(new JLabel("地图选择"));
jlabel.add(this.combox);
this.combox.addActionListener(this);
jlabel.add(new JLabel(" "));
button=new JButton("开始");
button.setContentAreaFilled(false);
button.addActionListener(this);
jlabel.add(button);
button2=new JButton("停止");
button2.setContentAreaFilled(false);
button2.addActionListener(this);
button2.setEnabled(false);
jlabel.add(button2);
button3=new JButton("回放");
button3.setContentAreaFilled(false);
button3.addActionListener(this);
jlabel.add(button3);
button3.setEnabled(false);
this.setVisible(true);
jlabel.add(new JLabel(" 模式选择:"));
String str2[]={"亲自上阵","自动寻路"};
JPanel panel=new JPanel(new GridLayout(1,2));
jlabel.add(panel);
ButtonGroup bgroup=new ButtonGroup();
this.radiobs=new JRadioButton[str2.length];
for(int i=0;i<this.radiobs.length;i++)
{
panel.add(this.radiobs[i]=new JRadioButton(str2[i]));
bgroup.add(this.radiobs[i]);
this.radiobs[i].addActionListener(this);
}
this.radiobs[0].setSelected(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
if(this.radiobs[0].isSelected())
{
this.button.setEnabled(false);
this.button2.setEnabled(false);
this.button3.setEnabled(false);
}
else
{
this.button.setEnabled(true);
this.button2.setEnabled(false);
this.button3.setEnabled(false);
}
Toolkit tk=Toolkit.getDefaultToolkit();
tk.addAWTEventListener(new MyKeyListener(), AWTEvent.KEY_EVENT_MASK);
this.socket=socket;
try
{
this.cout=new PrintWriter(socket.getOutputStream(),true);
br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
}
catch (IOException e1) {
e1.printStackTrace();
}
int c,d,e,f;
try
{
c=Integer.parseInt(br.readLine());
d=Integer.parseInt(br.readLine());
e=c;
f=d;
but[c][d].setText("1");
while(true)
{
try
{
c=Integer.parseInt(br.readLine());
d=Integer.parseInt(br.readLine());
but[e][f].setText("");
but[c][d].setText("1");
if(c==this.end.x&&d==this.end.y)
JOptionPane.showMessageDialog(this,"You Lose!");
e=c;
f=d;
}
catch (IOException e1)
{
break;
}
}
}
catch (NumberFormatException e1) {}
catch (IOException e1) {}
}
public LabyrinthFrame(Datas labyrinth[][],Datas start,Datas end,String host, int port) throws IOExcept
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计 java游戏开发 小游戏 经典游戏 游戏源码 课程设计
资源推荐
资源详情
资源评论
收起资源包目录
基于Java Frame的迷宫小游戏,包含了迷宫算法和Socket网络通信实现两个客户端共同游戏。.zip (6个子文件)
project_code_0719
Maze
Labyrinth.java 1KB
Maze.java 5KB
LabyrinthFrame.java 29KB
member.java 597B
ExtensionFileFilter.java 456B
Datas.java 271B
共 6 条
- 1
资源评论
辣椒种子
- 粉丝: 3391
- 资源: 5724
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功