The production of a continual look

Source: Internet
Author: User

Again and again is a very familiar with the game, it is mainly for the eyesight and brain test.

As a game, its core code is not difficult, first we need to draw a picture that can be placed repeatedly:

public void Frame () {JFrame JF = new JFrame (); Jf.add (this, borderlayout.center); Jf.setsize (new Dimension (1000, 800)); This.setbackground (Color.gray); Ranvalue (); jt.jianting (ti,this); Jf.addmouselistener (JT); This.repaint (); Jf.setvisible (TRUE);}

Then we need to draw the squares and then put some random pictures in the squares.

public void Paint (Graphics g) {super.paint (g); for (lk = 0; lk <=; lk++) {G.setcolor (color.red); G.drawline (x1, y1 + L ine * LK, x1 + line * Ten, y1 + line * lk) g.drawline (x1 + line * lk, y1, x1 + line * lk, y1 + line * 10);} for (x=0;x<10;x++) {for (y=0;y<10;y++) {if (ti[x][y]==1) {//g.drawstring ("1", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2 ); G.drawimage (Im.getimage (), X1+x*line, Y1+y*line, (), and null);} if (ti[x][y]==2) {//g.drawstring ("2", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im1.getimage (), X1+x*line, y1+ Y*line, n, +, NULL);} if (ti[x][y]==3) {//g.drawstring ("3", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im2.getimage (), X1+x*line, y1+ Y*line, n, +, NULL);} if (ti[x][y]==4) {//g.drawstring ("4", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im3.getimage (), X1+x*line, y1+ Y*line, n, +, NULL);} if (ti[x][y]==5) {//g.drawstring ("5", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im4.getimage (), X1+x*line, y1+ Y*line, n, +, NULL);} if (ti[x][y]==6) {//g.drawstring ("6", x1+x*line+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im5.getimage (), X1+x*line, Y1+y*line, [+], null);} if (ti[x][y]==7) {//g.drawstring ("7", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im6.getimage (), X1+x*line, y1+ Y*line, n, +, NULL);} if (ti[x][y]==8) {//g.drawstring ("8", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im7.getimage (), X1+x*line, y1+ Y*line, n, +, NULL);} if (ti[x][y]==9) {//g.drawstring ("9", X1+X*LINE+LINE/2, Y1+Y*LINE+LINE/2); G.drawimage (Im8.getimage (), X1+x*line, y1+ Y*line, (+), null);}}}

Note that we need to do that redraw as we work on the drawing and the elimination, so that the game goes on.

The next step is to join the listener, which we need to listen to so that we can eliminate and judge the behavior.

public class Jianting extends Mouseadapter{private int[][] ti;private int[][] Newarray;private int. X1,y1,x2,y2;private in t count=1;private int x = 100,y = 100,line = 50;private JPanel JP = new JPanel ();p rivate int f=0;private int v=0;private i NT B=0;private int c=0;private int a=0;private int d=0;public void jianting (int[][] ti,jpanel jp) {this.ti = ti;this.jp = J P;newarray = new Int[ti.length+2][ti.length+2];for (int i=0;i<ti.length;i++) {for (int j=0;j<ti[i].length;j++) { NEWARRAY[I+1][J+1] = Ti[i][j];}} for (int j=0;j<=ti.length+1;j++) {newarray[0][j]=0;} for (int j=0;j<=ti.length+1;j++) {newarray[j][0]=0;} for (int j=0;j<=ti.length+1;j++) {newarray[ti.length+1][j]=0;} for (int j=0;j<=ti.length+1;j++) {newarray[j][ti.length+1]=0;}} public void mouseclicked (MouseEvent e) {x1 = (E.getx ()-X)/line;y1 = ((E.gety ()-y)/line)-1; System.out.println ("x1:" +x1+ "Y1:" +y1); if (X1 <0 | | x1>9 | | y1<0 | | y1>9) {count = 1;} else if (count==1) {x2=x1;y2=y1; System.out.println ("X2:" +x2+ "y2:" +y2); Count++;} else if (count==2&& (x1!=x2| | Y1!=y2) {if (Zero2 (x1,y1,x2,y2)) {if (Ti[x1][y1]==ti[x2][y2]) {ti[x1][y1]=0;ti[x2][y2]=0; System.out.println ("ti[x1][y1]:" +ti[x1][y1]+ "Ti[x2][y2]:" +ti[x2][y2 "); count = 1;} else x2=x1;y2=y1;} else if (Zero1 (x1,y1,x2,y2)) {if (Ti[x1][y1]==ti[x2][y2]) {ti[x1][y1]=0;ti[x2][y2]=0; System.out.println ("ti[x1][y1]:" +ti[x1][y1]+ "Ti[x2][y2]:" +ti[x2][y2 "); count = 1;} else x2=x1;y2=y1;} else if (One1 (x1,y1,x2,y2)) {if (Ti[x1][y1]==ti[x2][y2]) {ti[x1][y1]=0;ti[x2][y2]=0; System.out.println ("ti[x1][y1]:" +ti[x1][y1]+ "Ti[x2][y2]:" +ti[x2][y2 "); count = 1;} else x2=x1;y2=y1;} else if (One2 (x1,y1,x2,y2)) {if (Ti[x1][y1]==ti[x2][y2]) {ti[x1][y1]=0;ti[x2][y2]=0; System.out.println ("ti[x1][y1]:" +ti[x1][y1]+ "Ti[x2][y2]:" +ti[x2][y2 "); count = 1;} else x2=x1;y2=y1;} else if (TWO1 (x1,y1,x2,y2)) {if (Ti[x1][y1]==ti[x2][y2]) {ti[x1][y1]=0;ti[x2][y2]=0; System.out.println ("ti[x1][y1]:" +ti[x1][y1]+ "Ti[x2][y2]:" +ti[x2][y2 "); count = 1;} else x2=x1;y2=y1;} else if (TWO2 (x1,y1,x2,y2)) {if (Ti[x1][y1]==ti[x2][y2]) {ti[x1][y1]=0;ti[x2][y2]=0; System.out.println ("ti[x1][y1]:" +ti[x1][y1]+ "Ti[x2][y2]:" +ti[x2][y2 "); count = 1;} else x2=x1;y2=y1;} else count=1;} Jp.repaint ();} public boolean Zero1 (int x1,int y1,int x2,int y2) {if (y1==y2) {int maxX = Math.max (x1,x2); int minX = Math.min (x1, x2); T t=minx+1;t<maxx;t++) {if (ti[t][y1]==0) {return true;} else return false;}} if (x1==x2) {int maxy = Math.max (y1, y2); int miny = Math.min (y1, y2); for (int k=miny+1;k<maxy;k++) {if (ti[x1][k]==0) { return true;} else return false;}} return false;} public boolean Zero2 (int x1,int y1,int x2,int y2) {if (x1==x2) {int maxy = Math.max (y1, y2); int miny = Math.min (y1, y2); if (MA xy==miny+1) {return true;} else return false;} if (y1==y2) {int maxX = Math.max (x1,x2); int minX = Math.min (x1, x2); if (maxx==minx+1) {return true;} else return false;} return false;} public boolean One1 (int x1,int y1,int x2,int y2) {if (x1!=x2&&y1!=y2) {int maxX = Math.max (x1, x2); int MinX = MATH.MI N (x1, x2); int maxy = Math.max (y1, y2); int miny = Math.min (y1, y2); for (inT f=minx+1;f<=maxx;f++) {if (ti[f][miny]==0) {for (int g=miny+1;g<maxy;g++) {if (ti[maxx][g]==0) {return true;} else return false;}} else return false;} for (int q=miny+1;q<=maxy;q++) {if (ti[minx][q]==0) {for (int r=minx+1;r<maxx;r++) {if (ti[r][maxy]==0) {return true;} else return false;}} else return false;} for (int q=miny+1;q<=maxy;q++) {if (ti[maxx][q]==0) {for (int r=minx+1;r<maxx;r++) {if (ti[r][miny]==0) {return true;} else return false;}} else return false;} for (int q=miny+1;q<=maxy;q++) {if (ti[maxx][q]==0) {for (int r=minx+1;r<maxx;r++) {if (ti[r][maxy]==0) {return true;} else return false;}} else return false;} for (int q=miny+1;q<=maxy;q++) {if (ti[minx][q]==0) {for (int r=minx+1;r<maxx;r++) {if (ti[r][miny]==0) {return true;} else return false;}} else return false;} for (int q=minx+1;q<=maxx;q++) {if (ti[q][maxy]==0) {for (int r=miny+1;r<maxy;r++) {if (ti[minx][r]==0) {return true;} else return false;}} else return false;} for (int f=minx+1;f<=maxx;f++) {if (ti[f][miny]==0) {for (int g=miny+1;g<maxy;g++) {if (ti[minx][g]==0) {return true;} else return false;}} else return false;} for (int f=minx+1;f<=maxx;f++) {if (ti[f][maxy]==0) {for (int g=miny+1;g<maxy;g++) {if (ti[maxx][g]==0) {return true;} else return false;}} else return false;}} return false;} public boolean one2 (int x1,int y1,int x2,int y2) {if (x1!=x2&&y1!=y2) {int maxX = Math.max (x1, x2); int MinX = MATH.MI N (x1, x2); int maxy = Math.max (y1, y2); int miny = Math.min (y1, y2); if (ti[minx][maxy]==0) {return true;} else if (ti[maxx][miny]==0) {return true;} else if (ti[minx][miny]==0) {return true;} else if (ti[maxx][maxy]==0) {return true;} else return false;} return false;} public boolean two1 (int x1,int y1,int x2,int y2) {if (x1!=x2&&y1!=y2) {int maxX = Math.max (x1, x2) +1;int MinX = Math. Min (x1, x2) +1;int Maxy = Math.max (y1, y2) +1;int miny = math.min (y1, y2) +1;for (int g=minx+1;g<maxx;g++) {if (Ti[g][miny] ==0) {f++;for (int t=miny;t<=maxy;t++) {if (ti[minx+f][t]==0) {for (int k=minx+f;k<=maxx;k++) {if (ti[k][maxy]==0) {F=0;return true;} Else {F=0;return false;}}} else{for (int l=miny;l<=maxy;l++) {if (ti[minx+f][l]==0) {for (int k=minx+f;k<=maxx;k++) {if (ti[k][maxy]==0) {f=0 ; return true;} else {F=0;return false;}}}    Else{f=0;return false;}} }}}for (int q=miny;q<maxy;q++) {if (ti[minx][q]==0) {f++;} else{for (int t=minx;t<=maxx;t++) {if (ti[miny+f][t]==0) {for (int k=miny+1;k<maxy;k++) {if (ti[maxx][k]==0) {f=0; return true;} else F=0;return false;}} else F=0;return false;}}} for (int l=miny;l<maxy;l++) {if (ti[minx][l]==0) {f++;} else{for (int t=miny+f;t<maxy;t++) {if (ti[minx][t]==0) {for (int k=minx+1;k<=maxx;k++) {if (ti[k][maxy]==0) {f=0; return true;} else F=0;return false;}} else F=0;return false;}}} for (int o=minx;o<maxx;o++) {if (ti[o][maxy]==0) {f++;for (int. t=maxy;t>=miny;t--) {if (ti[minx+f][t]==0) {for (int k=minx+f;k<=maxx;k++) {if (ti[k][miny]==0) {F=0;return true;} else F=0;return false;}} else F=0;return false;}} else{for (int t=maxy;t>=miny;t--) {if (ti[minx+f][t]==0) {for (int k=minx+f;k<=maxx;k++) {if (ti[k][miny]==0) {f=0 ; retUrn true;} else F=0;return false;}} else F=0;return false;}}} for (int p=maxy;p>minx;p--) {if (ti[minx][p]==0) {c++;for (int. t=minx;t<=maxx;t++) {if (ti[t][maxy-f]==0) {for (int k=maxy-f;k>miny;k--) {if (ti[maxx][k]==0) {C=0;return true;} else C=0;return false;}} else C=0;return false;}} else{for (int t=minx;t<=maxx;t++) {if (ti[t][maxy-f]==0) {for (int k=maxy-f;k>miny;k--) {if (ti[maxx][k]==0) {c=0; return true;} else C=0;return false;}} else return false;}}}} return false;} public boolean two2 (int x1,int y1,int x2,int y2) {if (x1!=x2&&y1!=y2) {int maxX = Math.max (x1, x2) +1;int MinX = Math. Min (x1, x2) +1;int Maxy = Math.max (y1, y2) +1;int miny = math.min (y1, y2) +1;for (int g=minx+1;g<=newarray.length;g++) {if (newarray[g][miny+1]==0) {for (int t=miny+1;t<=maxy;t++) {if (newarray[newarray.length][t]==0) {for (int k=newarray.length;k>maxx;k--) { if (newarray[k][maxy]==0) {return true;}}}}} for (int g=miny+1;g<newarray.length;g++) {if (newarray[minx][g]==0) {for (int t=minx+1;t<maxx;t++) {if (newArray[ T][newarray.length]==0) {for (int k=newarray.length;k>maxy;k--) {if (newarray[maxx][k]==0) {return true;}}}}} for (int g=minx+1;g>0;g--) {if (newarray[g][miny]==0) {if (int. t=miny+1;t<maxy;t++) {if (newarray[0][t]==0) {for ( int k=0;k<maxx;k++) {if (newarray[k][maxy]==0) {return true;}}}}} for (int g=miny+1;g>0;g--) {if (newarray[minx][g]==0) {if (int. t=minx;t<maxx;t++) {if (newarray[t][0]==0) {for ( int k=0;k<maxy;k++) {if (newarray[maxx][k]==0) {return true;}}}}} for (int g=maxx;g>0;g--) {if (newarray[g][miny]==0) {if (int. t=miny+1;t<maxy;t++) {if (newarray[0][t]==0) {for ( int k=0;k<minx;k++) {if (newarray[k][maxy]==0) {return true;}}}}} for (int g=miny+1;g>0;g--) {if (newarray[maxx][g]==0) {if (int. t=maxx;t>minx;t--) {if (newarray[t][0]==0) {for ( int k=0;k<maxy;k++) {if (newarray[minx][k]==0) {return true;}}}}} for (int g=maxx;g<newarray.length;g++) {if (newarray[miny][g]==0) {for (int t=miny;t<maxy;t++) {if (newarray[ newarray.length][t]==0) {for (int k=newarray.length;k>minx;k--) {if (newarray[k][maxy]==0) {return true;}}}}} for (int g=miny;g<newarray.length;g++) {if (newarray[maxx][g]==0) {for (int t=maxx;t>minx;t--) {if (newarray[t][ newarray.length]==0) {for (int k=newarray.length;k>maxy;k--) {if (newarray[minx][k]==0) {return true;}}}}}} else if (x1==x2&&x1!=1&&x1!= (newarray[y1].length-1)) {int maxX = Math.max (x1, x2) +1;int MinX = Math.min ( x1, x2) +1;int Maxy = Math.max (y1, y2) +1;int miny = math.min (y1, y2) +1;for (int g=minx+1;g<newarray.length;g++) {if ( newarray[g][miny]==0) {v++;for (int t=miny;t<maxy;t++) {if (newarray[minx+v][t]==0) {for (int k=minx+v;k>minx; k--) {if (newarray[k][maxy]==0) {V=0;return true;}}} else v=0;}} else{for (int t=miny;t<maxy;t++) {if (newarray[minx+v][t]==0) {for (int k=minx+v;k>minx;k--) {if (newarray[k][ maxy]==0) {V=0;return true;}}} else v=0;}}} for (int g=minx-1;g>0;g--) {if (newarray[g][miny]==0) {a++;} else{for (int t=miny;t<maxy;t++) {if (newarray[minx-v][t]==0) {for (int k=minx-v;k<maxx;k++) {if (newarray[k][ maxy]==0) {A=0;return true;}}} ElSe a=0;}} for (int t=miny;t<maxy;t++) {if (newarray[minx-v][t]==0) {for (int k=minx-v;k<maxx;k++) {if (newarray[k][maxy]==0 {A=0;return true;}}} else a=0;}}} else if (y1==y2&&y1!=1&&y1!= (newarray[x1].length-1)) {int maxX = Math.max (x1, x2) +1;int MinX = Math.min ( x1, x2) +1;int Maxy = Math.max (y1, y2) +1;int miny = math.min (y1, y2) +1;for (int g=miny-1;g>0;g--) {if (newarray[minx][g]= =0) {C + +;} else{for (int t=minx;t<maxx;t++) {if (newarray[t][miny-c]==0) {for (int k=miny-c;k<miny;k++) {if (newarray[maxx][ k]==0) {C=0;return true;}}} else c=0;}}} for (int t=minx;t<maxx;t++) {if (newarray[t][miny-c]==0) {for (int k=miny-c;k<miny;k++) {if (newarray[maxx][k]==0 {C=0;return true;}}} else c=0;} for (int g=miny+1;g<newarray[minx].length;g++) {if (newarray[minx][g]==0) {d++;} else{for (int t=minx+1;t<maxx;t++) {if (newarray[t][miny+d]==0) {for (int k=miny+d;k>miny;k--) {if (Newarray[maxx ][k]==0) {D=0;return true;}}} else D=0;}}} for (int t=minx+1;t<maxx;t++) {if (newarray[t][miny+d]==0) {for (int k=miny+d; k>miny;k--) {if (newarray[maxx][k]==0) {D=0;return true;}}} else d=0;}} else if (x1==x2&&x1== (newarray[y1].length-1)) {return true;} else if (x1==x2&&newarray[x1-1][0]==0) {return true;} else if (y1==y2&&y1== (newarray[x1].length-1)) {return true;} else if (y1==y2&&newarray[0][y1-1]==0) {return true;} return false;}}

Here we first create two arrays, because we need to determine the location of the point and whether the point is eliminated, so we need to add a border around the one that we've seen all the time. It is necessary to construct the array two times.

Then is the inflection point of judgment, because we are in the game, we will see repeatedly see the number of points, only in its number of points less than two times, can be eliminated, so we need inflection point of judgment, calculate the number of points, then we are how to calculate the number of points, The main thing is whether there is a block on the path to the connection between it and the point to which it is connected, so that it can be calculated.

The production of a continual look

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.