资源描述:
《连连看java程序-论文》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、连连看java程序-论文连连看java程序packagekyodai.map;importjava.awtimportjavax.swing.*;importkyodai/***消除连连看方块的类*/publicclassAnimateDeleteimplementsRunnable{staticJButton[]dots;staticlongdelay二201;int[]array二newint[44];//最大距离只可能为2行1列privateintcount=0;privatevolatileThreadthread;p
2、ublicAnimateDelete(JButton[]dots){this.dots=dots;array二newint[0];/***初始化*/publicAnimateDelete(intdired,Pointa,Pointb){initArray();calcTwoPoint(direct,a,b);start();}/***direct方向*1表示a,b在同一直线上,b,c在同一竖线上;*0表示a,b在同一竖线上,b,c在同一直线上*/publicAnimateDelete(intdirect,Pointa,Poin
3、tb,Pointc)initArray();if(direct=1){//先横后竖calcTwoPoint(1,a,b);calcTwoPoint(0,b,c);}else{calcTwoPoint(0,a,b);count--;calcTwoPoint(1,b,c);}start();}/***direct方向*1表示a,b为横线,b,c为竖线,c,d为横线*0表示d,b为竖线,b,c为横线,c,d为竖线*/publicAnimateDelete(intdirect,Pointa,Pointb,Pointc,Pointd){
4、initArray();if(direct=1){//横、竖、横方式处理calcTwoPoint(1,a,b);count・・;calcTwoPoint(0,b,c);count--;calcTwoPoint(1,c,d);}else{//竖、横、竖方式处理calcTwoPoint(0,a,b);count--;calcTwoPoint(1,b,c);count--;calcTwoPoint(0,c,d);}start();}/***计算消除的两点*/privatevoidcalcTwoPoint(intdirect,Poin
5、ta,Pointb){intoffset=0;if(direct=1){//横向连接if(a.y>b.y){//a点向b点是从右向左在水平线上消除for(inty=a.y;y>=b.y;y--){offset二a.x*Setting.COLUMN+y;array[count]二offset;count++;}}else{//a点向b点是从左向右在水平线上消除for(inty二a.y;y<二b.y;y++){offset二a.x*Setting.COLlft'IN+y;array[count]二offset;count-H-;}
6、}}else{//竖向连接if(a.x>b.x){//a点向b点是从下向上垂直消除for(intx=a.x;x>=b.x;x--){offset二x*Setting.COLUMN+a.y;array[count]二offset;count;}}else{//a点向b点是从上向下垂直消除for(intx二a.x;x<二b.x;x++){offset=x*Setting.COLUMN+a.y;array[count]=offset;count;}}}}/***设置动画速度*/publicvoidsetSpeed(intspeed)
7、{delay二speed*10;}privatevoidinitArray(){if(array=nul1IIarray.length=0){return;}publicvoidtest(){if(array=nul1IIarray.length=0){return;for(inti二0;i8、d(this);thread・start();}publicvoidrun(){if(count<2){return;}ThreadcurrentThread二Thread.currentThread();booleananimate二true;while(thread=cu