📄 twins.java
字号:
{ //[i][j]; //[i - 1][j]; Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i-1); Ant.Tips[1][1]=(byte)j; //System.out.println("4"); return true; } } } //_ | 情况 for (i = 2; i <= 7; i++) { for (j = 0; j <= 6; j++) { if (Map[i][j].ID == Map[i - 1][j + 1].ID && Map[i][j].ID == Map[i - 2][j + 1].ID) { //[i][j]; //[i][j + 1); Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i); Ant.Tips[1][1]=(byte)(j+1); //System.out.println("5"); return true; } } } //| _ 情况 for (i = 2; i <= 7; i++) { for (j = 1; j <= 7; j++) { if (Map[i][j].ID == Map[i - 1][j - 1].ID && Map[i][j].ID == Map[i - 2][j - 1].ID) { //[i][j]; //[i][j - 1); Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i); Ant.Tips[1][1]=(byte)(j-1); //System.out.println("6"); return true; } } } //_-- 情况 for (i = 1; i <= 7; i++) { for (j = 0; j <= 5; j++) { if (Map[i][j].ID == Map[i - 1][j + 2].ID && Map[i][j].ID == Map[i - 1][j + 1].ID) { //[i][j]; //[i - 1][j]; Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i-1); Ant.Tips[1][1]=(byte)j; //System.out.println("7"); return true; } } } //-__ 情况 for (i = 0; i <= 6; i++) { for (j = 0; j <= 5; j++) { if (Map[i][j].ID == Map[i + 1][j + 2].ID && Map[i][j].ID == Map[i + 1][j + 1].ID) { //[i][j]; //[i + 1][j]; Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i+1); Ant.Tips[1][1]=(byte)j; //System.out.println("8"); return true; } } } // -_- 情况 for (i = 1; i <= 7; i++) { for (j = 1; j <= 6; j++) { if (Map[i][j].ID == Map[i - 1][j - 1].ID && Map[i][j].ID == Map[i - 1][j + 1].ID) { //[i][j]; //[i - 1][j]; Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i-1); Ant.Tips[1][1]=(byte)j; //System.out.println("9"); return true; } } } // _-_ 情况 for (i = 0; i <= 6; i++) { for (j = 1; j <= 6; j++) { if (Map[i][j].ID == Map[i + 1][j - 1].ID && Map[i][j].ID == Map[i + 1][j + 1].ID) { //[i][j]; //[i + 1][j]; Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i+1); Ant.Tips[1][1]=(byte)j; //System.out.println("10"); return true; } } } //|< 情况 for (i = 1; i <= 6; i++) { for (j = 1; j <= 7; j++) { if (Map[i][j].ID == Map[i + 1][j - 1].ID && Map[i][j].ID == Map[i - 1][j - 1].ID) { //[i][j]; //[i][j - 1); Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i); Ant.Tips[1][1]=(byte)(j-1); //System.out.println("11"); return true; } } } //>| 情况 for (i = 1; i <= 6; i++) { for (j = 0; j <= 6; j++) { if (Map[i][j].ID == Map[i + 1][j + 1].ID && Map[i][j].ID == Map[i - 1][j + 1].ID) { //[i][j]; //[i][j + 1); Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i); Ant.Tips[1][1]=(byte)(j+1); //System.out.println("12"); return true; } } }//--_ 情况 for (i = 1; i <= 7; i++) { for (j = 2; j <= 7; j++) { if (Map[i][j].ID == Map[i - 1][j - 2].ID && Map[i][j].ID == Map[i - 1][j - 1].ID) { //[i][j]; //[i - 1][j]; Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i-1); Ant.Tips[1][1]=(byte)j; //System.out.println("13"); return true; } } }//-- - 情况 for (i = 0; i <= 7; i++) { for (j = 3; j <= 7; j++) { if (Map[i][j].ID == Map[i][j - 2].ID && Map[i][j].ID == Map[i][j - 3].ID) { //[i][j]; //[i][j - 1); Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i); Ant.Tips[1][1]=(byte)(j-1); //System.out.println("14"); return true; } } } //_ _- 情况 for (i = 0; i <= 6; i++) { for (j = 2; j <= 7; j++) { if (Map[i][j].ID == Map[i + 1][j - 2].ID && Map[i][j].ID == Map[i + 1][j - 1].ID) { //[i][j]; //[i + 1][j]; Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i+1); Ant.Tips[1][1]=(byte)j; //System.out.println("14"); return true; } } } //- -- 情况 for (i = 0; i <= 7; i++) { for (j = 0; j <= 4; j++) { if (Map[i][j].ID == Map[i][j + 2].ID && Map[i][j].ID == Map[i][j + 3].ID) { //[i][j]; //[i][j + 1); Ant.Tips[0][0]=(byte)i; Ant.Tips[0][1]=(byte)j; Ant.Tips[1][0]=(byte)(i); Ant.Tips[1][1]=(byte)(j+1); //System.out.println("16"); return true; } } } return false; } //搜索是否存在连续的序列,并记录连续序列的元素 private boolean FindSeries() { int x,y; boolean IsFinded=false; for(y=0;y<8;y++) { for(x=0;x<8;x++) { Map[y][x].IsSerie=false; } } for(y=0;y<8;y++) { for(x=0;x<8;x++) { if(x<6 && Map[y][x].ID==Map[y][x+1].ID && Map[y][x+1].ID==Map[y][x+2].ID) { Map[y][x].IsSerie=true; Map[y][x+1].IsSerie=true; Map[y][x+2].IsSerie=true; IsFinded=true; } if(y<6 && Map[y][x].ID==Map[y+1][x].ID && Map[y][x].ID==Map[y+2][x].ID) { Map[y][x].IsSerie=true; Map[y+1][x].IsSerie=true; Map[y+2][x].IsSerie=true; IsFinded=true; } } } int Count=0; if (IsFinded) { for(y=0;y<8;y++) { for(x=0;x<8;x++) { if(Map[y][x].IsSerie==true) { Count++; Score+=26; } } } } //System.out.println("找到可消去个数:"+Count); //return Count; Ant.SeriesMapShowd=false; return IsFinded; } //显示提示,提示可以移动那两个元素 private void ShowTips(Graphics g) { //IsShowTips=true; if(Ant.IsShowTips==false ||IsFinish) { return; } //IsShowTips=false; if(Ant.IsShowBox<3) { g.setColor(255,0,0); g.fillRect(Ant.OX + Ant.Tips[0][1] * Ant.GW, Ant.OY + Ant.Tips[0][0] * Ant.GH, Ant.OX , Ant.OY ); g.fillRect(Ant.OX + Ant.Tips[1][1] * Ant.GW, Ant.OY + Ant.Tips[1][0] * Ant.GH, Ant.OX , Ant.OY ); } } //地图修正,即相同序列被消去后用它上面的来填补,在最顶头随机产生一个来填充 private void MoveMap() { int x,y; int yy; boolean IsMove=false; Ant.IsMoving=true; do { IsMove=false; for(y=7;y>0;y--) { for(x=0;x<8;x++) { if(Map[y][x].IsSerie==true && Map[y-1][x].IsSerie==false) { Map[y][x].ID=Map[y-1][x].ID; Map[y][x].IsSerie=false; Map[y-1][x].IsSerie=true; IsMove=true; } } } for(x=0;x<8;x++) { if(Map[0][x].IsSerie==true) { IsMove=true; Map[0][x].ID=(byte)Rnd.nextInt(6); Map[0][x].IsSerie=false; } } Waite(200); }while(IsMove); Ant.IsMoving=false; } //地图修正,即相同序列被消去后用它上面的来填补,在最顶头随机产生一个来填充 private void MoveMap2() { int x,y; int yy; //Waite(); for(y=0;y<8;y++) { for(x=0;x<8;x++) { if(Map[y][x].IsSerie==true) { //Map[x][y]=false; for(yy=y;yy>0;yy--) { ////System.out.println(yy); Map[yy][x].ID=Map[yy-1][x].ID; } Map[yy][x].ID=(byte)Rnd.nextInt(6); } } } Waite(); } //检查上一元素与当前元素交换位置后能不能产生序列,能即销毁 private boolean CheckWay() { boolean IsFinded=false; if((Ant.AX==Ant.BX && (Ant.AY==Ant.BY+1||Ant.AY==Ant.BY-1))||(Ant.AY==Ant.BY && (Ant.AX==Ant.BX+1||Ant.AX==Ant.BX-1))) { byte tmp=Map[Ant.AY][Ant.AX].ID; Map[Ant.AY][Ant.AX].ID=Map[Ant.BY][Ant.BX].ID; Map[Ant.BY][Ant.BX].ID=tmp; Waite(); while(FindSeries()) { Waite(); MoveMap(); Waite(); IsFinded=true; } if(IsFinded==false) { tmp=Map[Ant.AY][Ant.AX].ID; Map[Ant.AY][Ant.AX].ID=Map[Ant.BY][Ant.BX].ID; Map[Ant.BY][Ant.BX].ID=tmp; } } Ant.AX=Ant.BX; Ant.AY=Ant.BY; return IsFinded; } //等待函数,没什么用处,正在构思新的。 private void Waite() { IF=true; if (IsFinish==true) { return; } IsLockInput=true; try { Thread.sleep(320); } catch (InterruptedException ex) { ex.printStackTrace(); } IsLockInput=false; IF=true; } private void Waite(int SleepTime) { IF=true; if (IsFinish==true) { return; } IsLockInput=true; try { Thread.sleep(SleepTime); } catch (InterruptedException ex) { ex.printStackTrace(); } IsLockInput=false; IF=true; } //刷新计时时间,返回该字符串 private String Clock() { if(UseTime<TotalTime) { UseTime=(int)((System.currentTimeMillis() - StartTime) / 1000); }else { IsFinish=true; } return "倒计时:" +(TotalTime-UseTime)+"s"; } //载入图片的函数,加了容错处理 public Image loadImage(String location) { try { return Image.createImage(location); }catch (java.io.IOException e) { throw new RuntimeException("载入图片错误: " + e); } } //刷新线程执行函数 public void run() { do { if(RunThread) { RunThread=false; CheckWay(); if (FindWay()==false) { NewMap(); } } try { Thread.sleep(100); } catch (InterruptedException ex) { ex.printStackTrace(); } }while(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -