📄 mainpanel.java
字号:
{
progress.setValue(PROGRESS);
Score_label.setText("WIN");
}
else
{
progress.setValue(temp.progress_num);
Score_label.setText(""+temp.progress_num);
//progress.setString("ok");
}
continue;
}
if(temp.sound!=temp.NoSound)
{
//System.out.println("come into here");
new SoundThread(temp.sound).start();
continue;
}
if(temp.sleep_num_before!=0)
{
try{
sleep(temp.sleep_num_before);
}catch(InterruptedException ef){
System.out.println("Thread Sleep Error!!!");
};
}
if(temp.specialDelay)
continue;
temp.label.setIcon(ImageFactory.getInstance().getImageicon(temp.pic));
//System.out.println("temp pic is "+temp.pic);
if(temp.sleep_num_after!=0)
{
try{
sleep(temp.sleep_num_after);
}catch(InterruptedException ef){
System.out.println("Thread Sleep Error!!!");
};
}
}
if(!win_flag)
addAllListener();
else
{
//System.out.println("come here");
win();
}
InGridProcess = false;
}
}
public boolean CanStart(){
return canStart;
}
public boolean IsStarting(){
return gameStarting;
}
private void getStartMap(){
int y;
int x;
boolean goon;
while(true){
goon = false;
for(y=0;y<8;y++)
for(x=0;x<8;x++)
map[x][y]=(int)(Math.random()*7);
for(y=0;y<8;y++)
for(x=0;x<6;x++)
if(map[x][y]==map[x+1][y] && map[x][y]==map[x+2][y])
goon = true;;
for(x=0;x<8;x++)
for(y=0;y<6;y++)
if(map[x][y]==map[x][y+1] && map[x][y]==map[x][y+2])
goon = true;
if(goon)
continue;
break;
}
}
private void getRandomMap(){
int y;
int x;
for(y=0;y<8;y++)
for(x=0;x<8;x++)
map[x][y]=(int)(Math.random()*7);
}
private boolean IsRelated(JLabel prev,JLabel now){
if(map[getXpos(prev)][getYpos(prev)] == map[getXpos(now)][getYpos(now)])
return false;
if( getXpos(prev)==getXpos(now) && (getYpos(prev)+1 == getYpos(now)||getYpos(prev)-1 == getYpos(now)))
return true;
if( getYpos(prev)==getYpos(now) && (getXpos(prev)+1 == getXpos(now)||getXpos(prev)-1 == getXpos(now)))
return true;
return false;
}
private boolean IsSame(JLabel prev,JLabel now){
if(getXpos(prev) == getXpos(now) && getYpos(prev)==getYpos(now))
return true;
return false;
}
private void copyArray(int[][] src,int[][]dst){
int i;
int j;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
dst[i][j]=src[i][j];
}
private class Map{
int y;
int x;
public Map(int posx,int posy){
x=posx;
y=posy;
}
}
private boolean calculateDelete(){
//System.out.println("calculated.........");
int x;
int y;
boolean hasdelete = false;
Vector tempv=new Vector();
for(y=0;y<8;y++)
for(x=0;x<6;x++)
if(tempmap[x][y]==tempmap[x+1][y] && tempmap[x][y]==tempmap[x+2][y])
{
int count =3;
int value = tempmap[x][y];
int temp = x+3;
hasdelete= true;
v.add(new JItem(value));
tempv.add(new Map(x,y));
tempv.add(new Map(x+1,y));
tempv.add(new Map(x+2,y));
while(temp<8)
{
if(value == tempmap[temp][y])
{
count ++;
tempv.add(new Map(temp,y));
temp ++;
}
else
break;
}
x+=count;
}
for(x=0;x<8;x++)
for(y=0;y<6;y++)
if(tempmap[x][y]==tempmap[x][y+1] && tempmap[x][y]==tempmap[x][y+2])
{
int count =3;
int value = tempmap[x][y];
int temp = y+3;
hasdelete= true;
v.add(new JItem(value));
tempv.add(new Map(x,y));
tempv.add(new Map(x,y+1));
tempv.add(new Map(x,y+2));
while(temp<8)
{
if(value == tempmap[x][temp])
{
count ++;
//Xmap[x][temp]=KONG;
tempv.add(new Map(x,temp));
temp ++;
}
else
break;
}
y+=count;
}
if(!hasdelete)
return hasdelete;
kongnum = 0;
Map tempMap;
while(!tempv.isEmpty()){
tempMap=(Map)tempv.remove(0);
tempmap[tempMap.x][tempMap.y]=KONG;
}
for(y=0;y<8;y++)
for(x=0;x<8;x++)
{
if(tempmap[x][y]==KONG)
{
konghang[x] = true;
v.add(new JItem(grid[x][y],KONG,0,0));
//System.out.println(progress_num);
kongnum ++;
}
}
progress_num+=kongnum;
//System.out.println("kongnum"+kongnum);
v.add(new JItem(progress_flag,progress_num));
v.add(new JItem(true,10*sleep_num));
return true;
}
private int countKongNum(int[][] input){
int output=0;
int y;
int x;
for(y=0;y<8;y++)
for(x=0;x<8;x++)
{
if(input[x][y]==KONG)
output++;
}
return output;
}
private int getXpos(JLabel label){
return (label.getX()-2)/50;
}
private int getYpos(JLabel label){
return (label.getY()-2)/50;
}
private boolean IsLiving(int[][] map){
int y;
int x;
int [][] tempmap =new int[8][8];
copyArray(map, tempmap);
for(y=0;y<8;y++)
for(x=0;x<7;x++)
{
tempmap[x][y]=map[x+1][y];
tempmap[x+1][y]=map[x][y];
if(HasKong(tempmap))
return true;
else
{
tempmap[x][y]=map[x][y];
tempmap[x+1][y]=map[x+1][y];
}
}
for(x=0;x<8;x++)
for(y=0;y<7;y++)
{
tempmap[x][y]=map[x][y+1];
tempmap[x][y+1]=map[x][y];
if(HasKong(tempmap))
return true;
else
{
tempmap[x][y]=map[x][y];
tempmap[x][y+1]=map[x][y+1];
}
}
return false;
}
private boolean HasKong(int[][] map){
int y;
int x;
for(y=0;y<8;y++)
for(x=0;x<6;x++)
if(map[x][y]==map[x+1][y] && map[x][y]==map[x+2][y])
return true;
for(x=0;x<8;x++)
for(y=0;y<6;y++)
if(map[x][y]==map[x][y+1]&&map[x][y]==map[x][y+2])
return true;
return false;
}
private void setKong(int[][] map){
int y;
int x;
for(y=0;y<8;y++)
for(x=0;x<8;x++)
map[x][y]=KONG;
}
private void addAllListener(){
int y;
int x;
for(y=0;y<8;y++)
for(x=0;x<8;x++)
grid[x][y].addMouseListener(gma);
}
private void removeAllListener(){
int y;
int x;
for(y=0;y<8;y++)
for(x=0;x<8;x++)
grid[x][y].removeMouseListener(gma);
}
private class DaoJuThread extends Thread{
private int type;
private boolean processed;
public DaoJuThread(int t){
type = t;
processed = false;
}
public synchronized void run(){
while(!processed){
if(!InGridProcess){
removeAllListener();
kongnum = 0;
for(;;){
do{
int loopout;
int loopin;
int loopX;
int loopY;
int loop;
while(kongnum>0)
{
for(loopX=0;loopX<8;loopX++)
{
if(!konghang[loopX])
continue;
for(loopY=7;loopY>=0;loopY--)
{
if(tempmap[loopX][loopY] ==KONG)
{
for(loop=loopY;loop>0;loop--)
{
tempmap[loopX][loop]=tempmap[loopX][loop-1];
v.add(new JItem(grid[loopX][loop],tempmap[loopX][loop],0,0));
tempmap[loopX][loop-1]=KONG;
v.add(new JItem(grid[loopX][loop-1],KONG,0,0));
}
tempmap[loopX][0]=(int)(Math.random()*7);
v.add(new JItem(grid[loopX][0],tempmap[loopX][0],0,0));
kongnum--;
//progress_num ++;
break;
}
}
}
v.add(new JItem(true,5*sleep_num));
}
//v.add(new JItem(true,5*sleep_num));
}
while(calculateDelete());
if(!IsLiving(tempmap))
{
setKong(tempmap);
kongnum = 8*8;
}
else
{
break;
}
}
copyArray(tempmap,map);
if(progress_num >= PROGRESS)
win_flag = true;
if(!v.isEmpty()){
show = new DisplayThread(v);
show.start();
}
else if(!win_flag)
addAllListener();
break;
}
try{
sleep(500);
}catch(Exception e){System.out.println("TimeThread err");}
}
}
}
private class TimeThread extends Thread{
private long now;
private long base;
private long diff;
public TimeThread(){
base = new Date().getTime();
}
public void run(){
int seconds;
int minute;
int second;
String m;
String s;
while(!win_flag && gameStarting){
diff = new Date().getTime() - base;
seconds = (int)(diff/1000);
//System.out.println("diff"+diff);
minute = (int)(seconds/60);
second = seconds%60;
if(minute<10)
m=new String("0"+minute);
else
m=new String(""+minute);
if(second<10)
s=new String("0"+second);
else
s=new String(""+second);
Time_label.setText(m+" : "+s);
try{
sleep(500);
}catch(Exception e){System.out.println("TimeThread err");}
}
}
}
// private class ProgressThread extends Thread {
// private MainPanel m;
// public ProgressThread(MainPanel mp) {m=mp;}
// public void run() {
// while(true){
// if(progress_num >=PROGRESS)
// {
// progress.setValue(PROGRESS);
// m.win();
// break;
// }
//
// else
// progress.setValue(progress_num);
//
// try {
// sleep(100);
// } catch(InterruptedException ire) {
// System.err.println("sleep interrupted");
// }
// }
//
// }
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -