A little bit of game lighting game is better than C to achieve a little

Source: Internet
Author: User

 /**************************  added last night's idea that the data function must be implemented to generate enough points  rand value is different from the value of check judgment,rand> The rand   in check is the same as the logical   the next version is to add a 2-linked list to increase the diagonal line and increase the spacing to load the picture http://www.592xyx.com/gameplay/14193/ Index.shtml Turn off the lights Game 3 did not expect to be in this game again will be the thing, should not just talk about it ... The concrete realization theory after the paper on paper for the mind    technology for the first stage to generate maps of thinking    similar   or a difference of this program practice image   Map is to load the picture   more convenient operation specifically can be used ;;; The link list itself is a problem following the import can be simplified    This branch can be implemented according to the basic function of logic to run **************************/  import  java.awt.frame;  import java.awt.point;import java.awt.image.bufferedimage;import  Java.io.file;import java.lang.reflect.field;import java.util.list;import java.awt.button;import  java.awt.Color;import java.awt.Dimension;import java.awt.Frame;import java.awt.Graphics; import java.awt.menu;import java.awt.menubar;import java.awt.menuitem; import  Java.awt.event.actionevent;import java.awt.event.actionlistener;import java.awt.event.mouseadapter;import java.awt.event.mouseevent;import java.awt.event.mouselistener;import  java.awt.event.windowadapter;import java.awt.event.windowevent;import java.awt.event.windowlistener; import java.util.arraylist;import java.util.date;import java.util.stack;import  java.util.timer;import java.util.timertask; import javax.imageio.imageio;import  javax.swing.jframe;import javax.swing.jmenu;import javax.swing.jpanel;import  javax.swing.jtextarea; import java.awt.graphics;import java.awt.point;import  java.awt.event.mouseadapter;import java.awt.event.mouseevent;import java.util.date;import  java.util.timer;import java.util.timertask; import javax.swing.jframe;import  javax.swing.jpanel; public class main extends jpanel {static stack< Integer> stack = new stack (); //  Create a Stack object      static int a = 1;    static int rand = 1;     static point p = null;    static point p2  = null;    static int    count=0;     public static frame frame = new frame ();     static  int s[][] = new  int [10][10];    static int  ss[][] = new  int [10][10];    public static void  data ()  {    java.util.random random=new java.util.random ();//  Define Random Class             int sr=random.nextint (120);     int o=2;int p=2;    //randomly generates rand contiguous dots on the map      while (sr-->0)  &Nbsp;  {    int r=random.nextint (%4;    if) (0<o &AMP;&AMP;O&LT;9&AMP;&AMP;0&LT;P&AMP;&AMP;P&LT;9)         {s[o][p]=1;ss [O] [P]=1;  ///stack.push (O);  stack.push (p); rand++;       rand++ ;        }    if (r==0)  o--;     if (r==1)  p++;    if (r==2)  o++;    if (r==3)  p--;     }    if (RAND&LT;20)     clear ();     }    public static void clear ()  {      for (int i=0;i<10;i++) {for (int j=0;j<10;j++)   s[i][j]=ss[i][j]=0;}      rand=0;     data ();    }     public static&nbsP;int  check ()  {    for (int i=0;i<10;i++) {for (int j=0;j<10; J + +) if (ss[i][j]==1&&ss[i][j]==0) count++;}      if (Count==rand) return 1;     return 0;         }    public static void main ( String[] args)  {    data ();     //int x=stack.peek ();     //int y=stack.pop ();     //while (rand-->0)     // system.out.println ("element" +rand+ "out of Stack")   //  system.out.println ("element" +stack.pop () + "Out of Stack");  //      for (int i=0;i<10;i++)//    {for (int j=0;j<10;j++)  system.out.print (" " +s[i][j]);//     System.out.println (" ");//    }//      for (int i=0;i<10;i++)//    {for (int j=0;j<10;j++)  System.out.print (" " + SS[I][J]);//    system.out.println (" ");    //     }    system.out.println (" " +rand);         main f = new main ();         frame.settitle (" "Illumination Game" ");         frame.add (f);                 frame.setsize (500, 500);         frame.addwindowlistener (New windowadapter ()  {             public void windowclosing (WindowEvent e)  {                 system.exit (0) ;             }         });         //frame.                         f.action ();         frame.addmouselistener (New mouseadapter ()  {                          public void mouseclicked (mouseevent e)  {                 int x = e.getx ();                 int y =  e.gety ();                 count++;                             p = new point (x, y);                int i= (x-35)/20;                int j= (y-55)/20;                   // The information in the SS array is judged first     is 1 for                 if (ss[j][i]==1)                 {               s [j] [I]=1-s[j][i];               if (ss[ J-1][i]==1) s[j-1][i]=1-s[j-1][i];                               if (ss[j+1][i]==1) s[j+1][i]=1-s[j+1][i];                if (ss[j][i-1]==1) s[j ][i-1]=1-s[j][i-1];                if (ss[j][i+1]==1) s[j][i+1]=1-s[j][i+1];                }                               //change the state in S                if (check () ==1)    p2 = new point (330, 220);               &nbsP;else            p2 = new point ( 330,&NBSP;2200);                 frame.repaint ();            }         });         frame.setvisible (true);     }     private Timer timer;      private void action ()  {        //  Listenerclick ();         timer = new timer ();         timer.schedule (New timertask ()  {             public void run ()  {                  frame.repaint ();             }        }, new date (),  1000);     }      @Override     public void paint ( GRAPHICS&NBSP;G)  {        g.drawline (30,30,30,300);   //   Left         g.drawline (30,30,300,30);  //  top              g.drawline (300,30,300,300);//  right          g.drawline (30,300,300,300);//  Bottom            g.drawstring ("Illumination Game 3" ", 333,33);         g.DrawString ("Point square area, connected area change", 333,50);        int i=0,j=0;      &nBsp;   for (  i=0;i<10;i++)   {          for (  j=0;j<10;j++)   if (s[i][j]==1) g.drawstring ("+", 40+j*20,40+i*20);   }//        for (  i=1;i<9;i++)// {//           for (  j=1;j<9;j++)  //  if (ss I [J]==1&&ss[i][j+1]==1]  g.drawline (40+j*20,40+i*20,40+ (j+1) *20,40+i*20);   //Right//            //  if (ss[i][j]==1&&ss[i][j-1]== 1)  g.drawline (40+j*20,40+i*20,40+ (j-1) *20,40+i*20)   //left//              if (ss[i][j]==1&&ss[i-1][j]==1)  g.drawLine (40+j*20,40+i* 20,40+j*20,40+ (i-1) *20)    ////         //if (ss[i ][j]==1&&ss[i+1][j]==1)  g.drawline (40+j*20,40+i*20,40+j*20,40+ (i+1) *20)     //                    //  }        for (  i=1;i<9;i++)  {          for (  j=1;j<9;j++)    if (ss[i][j]==1&& ss[i][j+1]==1)  g.drawline (40+j*20,40+i*20,40+ (j+1) *20,40+i*20);   //Right              if (ss[i][j]==1&&ss[i][j-1]==1)  g.drawLine (40+j* 20,40+i*20,40+ (j-1) *20,40+i*20)   //left                             }         for (  i=1;i<9;i++)  {          for (  j=1;j<9;j++)                if (ss[i][j]==1&&ss[i-1][j]==1)  g.drawline (40+j*20,40+i*20,40+j*20,40+ (i-1) *20);    //         if (ss[i][j]==1&&ss[i+1][j]==1)   G.drawline (40+j*20,40+i*20,40+j*20,40+ (i+1) *20)     //                     }         file file = new file ("1.jpg");                                   if  (p != null)           {   if (30<p.getx () &&p.getx () <300&&30 <p.gety () &&p.gety ()&LT;300)         {          g.drawstring ("You  had  win", (int) p2.getx (),  (int) p2.gety ());         int ii= (int) (P.GETX () -35)/20;int jj= (int) (P.gety () -35)/20;//          try{//              bufferedimage src = javax.imageio.imageio.read (file);//              g.drawimage (SRC, (int) P.getX (), (int) P.getY (), 10,10,null);//             } //              catch (Exception e) {//                  e.printstacktrace () ;//             }finally{ //              ;//                  }             g.drawstring ("x = " +ii,333,70);             g.drawstring ("y = " +jj,333,90);             g.drawstring ("y = " +ss[jj][ii],333,110);         }                      else        {             g.drawstring ("" Error "", 44,344);            &nBsp;            g.drawstring ("X = " + P.getx (), 44,360);             g.drawstring ("ss[][")  =  "+p.gety (), 44,390);        }                                      }                            g.drawstring ("I will always print time  " +a+ "s",  100, 400);         a++;             }  }


A little bit of game lighting game is better than C to achieve a little

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.