📄
字号:
move = false;
}
}
if (move == true)
{
man.setLocation(x, y);
}
return false;
}
public void actionPerformed(ActionEvent e)//监听事件的实现
{
if(e.getSource()==Close||e.getSource()==EXIT)
{
System.exit(0);
}
else if(e.getSource()==Introduction)
{ label.setVisible(true);
text2.setFont(new Font("Times New Roman", 0, 20));
text2.setText("在游戏进行中可以键盘和鼠标配合使用,其中在文本框显示的数值是评价玩家游戏水平的标准!");
text2.setVisible(true);
}
else if(e.getSource()==RandomSelect)
{ text1.setText("");
RandomLevelSelect();
text2.setVisible(false);
count=0;
}
else if(e.getSource()==Select_Select)
{
tflag=true;
text1.setFont(new Font("Times New Roman", 0, 20));
count=0;
text2.setVisible(false);
text1.setVisible(true);
}
else if(e.getSource()==text1)//人为控制游戏难度
{
if(tflag==true)
casecount=Integer.parseInt(text1.getText());
Select_Select(casecount);
return;
}
else if(e.getSource()==restart||e.getSource()==Start)
{
tianchong.setBounds(1000,1000,1000,1000);
count=0;
text1.setText("");
RandomLevelSelect();
}
}
public boolean check() //判断图片是否在正确位置,使用递归算法实现值的传递
{
boolean flag=true;
boolean flag1[]=new boolean[8];
for(int i=0;i<flag1.length;i++)
{
flag1[i]=false;
}
int x1,x2,y1,y2;
x1=person[5].getBounds().x;
y1=person[5].getBounds().y;
if((x1==100)&&(y1==100))
{
flag1[0]=true;
}
flag=flag&&flag1[0];
x1=person[2].getBounds().x;y1=person[2].getBounds().y;
if((x1==275)&&(y1==100))
{
flag1[1]=true;
}
flag=flag&&flag1[1];
x1=person[6].getBounds().x;y1=person[6].getBounds().y;
if((x1==450)&&(y1==100))
{
flag1[2]=true;
}
flag=flag&&flag1[2];
x1=person[4].getBounds().x;y1=person[4].getBounds().y;
if((y1==290)&&(x1==100))
{
flag1[3]=true;
}
flag=flag&&flag1[3];
x1=person[1].getBounds().x;y1=person[1].getBounds().y;
if((x1==275)&&(y1==290))
{
flag1[4]=true;
}
flag=flag&&flag1[4];
x1=person[3].getBounds().x;y1=person[3].getBounds().y;
if((x1==100)&&(y1==480))
{
flag1[5]=true;
}
flag=flag&&flag1[5];
x1=person[0].getBounds().x;y1=person[0].getBounds().y;
if((x1==275)&&(y1==480))
{
flag1[6]=true;
}
flag=flag&&flag1[6];
x1=person[7].getBounds().x;y1=person[7].getBounds().y;
if((x1==450)&&(y1==480))
{
flag1[7]=true;
}
flag=flag&&flag1[7];
Flag=flag;
return Flag;
}
public void getimage()//显示缺省的图片
{
tianchong.setBounds(450,290,170,190);
tianchong.setIcon(new ImageIcon("E:/2/9.gif"));
tianchong.setVisible(true);
}
public void RandomLevelSelect()//随机产生图片排列函数
{ casecount=(int)(Math.random()*4)+1;//产生随机器数来控制按钮的位置
RandomPicture();
}
public void Select_Select(int casenumber)//由玩家控制的游戏级别函数
{
RandomPicture();
}
public void RandomPicture() //随机生成各图片的位置,从而达到控制游戏难度(由于情形比较多,因此只随机列出几种图片位置)
{
switch(casecount)
{
case 1:
person[0].setBounds(100, 100, 170, 190);
person[1].setBounds(275, 100,170, 190);
person[2].setBounds(450, 100, 170, 190);
person[3].setBounds(100, 290, 170,190);
person[4].setBounds(275, 290, 170, 190);
person[5].setBounds(450, 290, 170, 190);
person[6].setBounds(100, 480, 170, 190);
person[7].setBounds(450, 480, 170, 190);
person[7].requestFocus();
break;
case 2:
person[0].setBounds(100, 480, 170, 190);
person[1].setBounds(100, 100, 170, 190);
person[3].setBounds(275, 100,170, 190);
person[2].setBounds(450, 100, 170, 190);
person[4].setBounds(100, 290, 170,190);
person[6].setBounds(275, 290, 170, 190);
person[5].setBounds(450, 290, 170, 190);
person[7].setBounds(275, 480, 170, 190);
person[7].requestFocus();
break;
case 3:
person[4].setBounds(100, 100, 170, 190);
person[5].setBounds(275, 100,170, 190);
person[3].setBounds(450, 100, 170, 190);
person[7].setBounds(100, 290, 170,190);
person[2].setBounds(275, 290, 170, 190);
person[1].setBounds(450, 290, 170, 190);
person[0].setBounds(100, 480, 170, 190);
person[6].setBounds(450, 480, 170, 190);
person[6].requestFocus();
break;
case 4:
person[7].setBounds(100, 100, 170, 190);
person[6].setBounds(275, 100,170, 190);
person[5].setBounds(450, 100, 170, 190);
person[4].setBounds(100, 290, 170,190);
person[3].setBounds(275, 290, 170, 190);
person[2].setBounds(450, 290, 170, 190);
person[1].setBounds(100, 480, 170, 190);
person[0].setBounds(450, 480, 170, 190);
person[7].requestFocus();
break;
case 5:
person[6].setBounds(275, 100,170, 190);
person[5].setBounds(100, 290, 170,190);
person[4].setBounds(275, 290, 170, 190);
person[3].setBounds(450, 290, 170, 190);
person[2].setBounds(100, 480, 170, 190);
person[1].setBounds(450, 480, 170, 190);
person[0].setBounds(100, 100, 170, 190);
person[7].setBounds(450,100,170,190);
break;
default:
person[0].setBounds(100, 100, 170, 190);
person[1].setBounds(275, 100,170, 190);
person[3].setBounds(100, 290, 170,190);
person[4].setBounds(275, 290, 170, 190);
person[5].setBounds(450, 290, 170, 190);
person[6].setBounds(100, 480, 170, 190);
person[2].setBounds(450, 480, 170, 190);
person[7].setBounds(450,100,170,190);
person[2].requestFocus();
}
}
public void calculate()
{
time2 = System.currentTimeMillis(); //计算时间差
shijiancha=time2-time1;
sec=shijiancha/1000;
min=sec/60;
sec=sec-60*min;
mic=shijiancha%1000;
s=min+":" + sec+ ":"+mic;
System.out.println(s);
text3.setFont(new Font("Times New Roman", 0, 20));
text3.setText(s);
}
public void run()
{
while(true)
{
if(Thread.currentThread()==shijian)
{ calculate();
}
try{
int jiange=(int)(Math.random()*500)+1;
Thread.sleep(jiange);
}
catch(InterruptedException e){}
}
}
}
class TEST
{
public static void main(String[] args)
{
pintu game=new pintu();
game.setVisible(true);
game.shijian.start();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -