⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lianlian.java

📁 和同学编的连连看小游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;


public class LianLian  {
	public static final int ROW = 10;
    public static final int COLUMN =10;
    public static JFrame f=new JFrame("Lian Lian Kan");
    public static ImageIcon backround=new ImageIcon("b.jpg");
    public static JButton backbutton=new JButton(backround);
    public static MyJButton b[][]=new MyJButton[ROW+2][COLUMN+2];
	public static ImageIcon image[][]=new ImageIcon[ROW+2][COLUMN+2];
	public static int count=0;
    public static Point point2=new Point();
	public static Point point1=new Point();
	public static int click2=0,ji=0;  
    public static int maparray[][]=new int[12][12];
    public static JMenuItem m12=new JMenuItem("Give up"); 
    public static JMenuItem m11=new JMenuItem("Start");
    public static JMenuItem m21=new JMenuItem("Reset");
    public static JMenuItem m22=new JMenuItem("Music play");
    public static JMenuItem m23=new JMenuItem("Music stop");
    public static JMenuItem m24=new JMenuItem("Direct");
    public static AudioClip a;
    public static Point pa=new Point();
	public static Point pb=new Point();
	public static JPanel tpanel=new JPanel();
	public static JProgressBar progress=new JProgressBar();
	public static Timer time;
	 
    
    
	public static void main(String[]args){
		
	vvv();a.loop();
	f.add(backbutton);
	
	JMenuBar mb=new JMenuBar();
	f.setJMenuBar(mb);
	JMenu m1=new JMenu("Game");
	JMenu m2=new JMenu("Option");
	JMenu m3=new JMenu("Help");
    mb.add(m1);
    mb.add(m2);
    mb.add(m3);
    JMenuItem m31=new JMenuItem("About");
    m3.add(m31);
    m31.addActionListener(new ActionListener(){      
         public  void actionPerformed(ActionEvent e){
                  JOptionPane pane=new JOptionPane();
                  //ImageIcon ic=new ImageIcon("3.jpg");
                  pane.showMessageDialog(f,"Version 515 Made by Xu  ","  About ",JOptionPane.INFORMATION_MESSAGE);
                                }
                            });
    
    m21.setEnabled(false);
    m2.add(m21);
    m21.addActionListener(new ActionListener(){      
         public  void actionPerformed(ActionEvent e){
                     reset();
                                }
                            });
    m2.add(m22);m22.setEnabled(false);
    m22.addActionListener(new ActionListener(){      
         public  void actionPerformed(ActionEvent e){
                    a.loop();m23.setEnabled(true);m22.setEnabled(false);
                                }
                            });
    m2.add(m23);m23.setEnabled(true);
    m23.addActionListener(new ActionListener(){      
    	
         public  void actionPerformed(ActionEvent e){
                     a.stop();m22.setEnabled(true);m23.setEnabled(false);
                      
                                }
                            });
                                
     m2.add(m24);m24.setEnabled(false);
     m24.addActionListener(new ActionListener(){      
         public  void actionPerformed(ActionEvent e){
                     if(autoreset()==false){System.out.println("No connection");
                     JOptionPane pan=new JOptionPane();
                     pan.showMessageDialog(f,"No more connection! Please reset!"," Direct ",JOptionPane.INFORMATION_MESSAGE);
                      }
                      else {
                      	b[pa.y][pa.x].setIcon(new ImageIcon(maparray[pa.y][pa.x]+"l.jpg"));
					    b[pb.y][pb.x].setIcon(new ImageIcon(maparray[pb.y][pb.x]+"l.jpg"));
                      	}
                                }
                            });
     
    m12.setEnabled(false);
    m21.setEnabled(false);
    JMenuItem m13=new JMenuItem("Quit");
    m1.add(m11);
    m1.add(m12);
    m1.addSeparator();
    m1.add(m13);
    
    m12.addActionListener(new ActionListener(){      
    	
         public  void actionPerformed(ActionEvent e){
                      giveup(); 
                                }
                            });
                            
    m13.addActionListener(new ActionListener(){      
    	
         public  void actionPerformed(ActionEvent e){
                     System.exit(0);
                                }
                            });
                            
    
    m11.addActionListener(new ActionListener(){
    	public void actionPerformed(ActionEvent e){    	
    		       begin();//timeCount();
    		       m12.setEnabled(true);
    		       m11.setEnabled(false);
    		       m21.setEnabled(true);
    		       m24.setEnabled(true);
    	}
    }
    
    );
    
    for(int n=0;n<12;n++){
		maparray[0][n]=0;
		maparray[11][n]=0;
		maparray[n][0]=0;
		maparray[n][11]=0;
		 image[0][n]=null;
		 image[11][n]=null;
		 image[n][0]=null;
		 image[n][11]=null;
		 
		
	}
	
	
        
    
    f.setSize(600,600);
	f.setVisible(true);
	 f.setLocation(300,60);
	
	    
	
	}  //end of main
	
	
	
     
     public static void timeCount(){
     	time=new Timer(300,null);
     	time.start();
     	time.addActionListener(
     	new ActionListener(){
    	public void actionPerformed(ActionEvent e){ 
    	         ji++;   	
    		     progress.setValue(ji);  
    		     System.out.println(progress.getPercentComplete());
    		     if(ji==100){
     	time.stop();
     	JOptionPane pan=new JOptionPane();
        pan.showMessageDialog(f,"  No   Time  Left  !   Start  again ! "," Message ",JOptionPane.INFORMATION_MESSAGE);
        giveup();
     	
        }
    	}
       });
     }//end of timeCount
     
     
     public static void vvv(){
     	try{a=Applet.newAudioClip(new URL("file:\\F:\\zuoye\\s.mid"));}
		catch(MalformedURLException e){}
     }//music play
     
     
	
	public static boolean autoreset(){
		
		for(int n=1;n<11;n++){
			for(int m=1;m<11;m++){
				if(maparray[n][m]!=0){
				 
					for(int i=1;i<11;i++){
						for(int j=1;j<11;j++){
							if(maparray[i][j]==maparray[n][m]&&(i!=n||j!=m)){ 
								pa.x=m;pa.y=n;
								pb.x=j;pb.y=i;
								if(connet(pa,pb)){System.out.println(n+"  "+m+"  "+i+"  "+j);
								                   return true;}
							}
						}
					}
				}
			}
		}return false;
	}//end of autoreset
	
	
	 public static boolean connet(Point point1,Point point2){
		if(maparray[point1.y][point1.x]==maparray[point2.y][point2.x]){
			
	    if(vertical(point1,point2)==true)return true;
	    else if(horizon(point1,point2)==true)return true;
	    else if(oneCorner(point1,point2)==true)return true;
	    else if(twoCorner1(point1,point2)==true)return true;
	    else if(twoCorner2(point1,point2)==true)return true;
	    else if(twoCorner3(point1,point2)==true)return true;
	    else if   ( twoCorner4(point1,point2)==true)return true;
	    else return false;	    		
    	    		
	}     return false;
	}//connet two buttom
	
	public static boolean twoCorner4(Point a, Point b1){
		int ma=a.x,mi=a.x,j=0,k=0;
		if(a.x>b1.x){mi=b1.x;ma=a.x;j=b1.y;k=a.y;}else{mi=a.x;ma=b1.x;k=b1.y;j=a.y;}
		for(int i=1;i<ma-mi;i++){
			if(maparray[j][mi+i]==0){//System.out.println("kaishi");
			Point a1=new Point(mi+i,j);
			Point b2=new Point(ma,k);
			if(oneCorner(a1,b2)==true)return true;
			}else return false;
		}return false;
	}
	
	
	public static boolean twoCorner3(Point a, Point b1){
		int ma=a.y,mi=a.y,j=0,k=0;
		if(a.y>b1.y){mi=b1.y;ma=a.y;j=b1.x;k=a.x;}else {mi=a.y;ma=b1.y;k=b1.x;j=a.x;}
		for(int i=1;i<ma-mi;i++){
			if(maparray[mi+i][j]==0){//System.out.println("kaishi");
			Point a1=new Point(j,mi+i);
			Point b2=new Point(k,ma);
			if(oneCorner(a1,b2)==true)//(twoCorner2(a1,b1)==true||twoCorner1(a1,b1)==true)
			return true;}else return false;
		}return false;
	}
	
	
	public static boolean twoCorner2(Point a, Point b1){
		int ma=a.x,mi=a.x,j=0,k=0;
		if(a.x>b1.x){mi=b1.x;ma=a.x;j=b1.y;k=a.y;}else{mi=a.x;ma=b1.x;k=b1.y;j=a.y;}
		for(int l=ma-1;l>=0;l--){
			//System.out.println(maparray[k][l]);
			if(maparray[k][l]!=0) break;
			if(l<mi){
				if(maparray[j][l]!=0) break;
				//System.out.println(maparray[j][l]);
				Point p1=new Point(l,j);
		        Point p2=new Point(l,k);
				if(vertical(p1,p2)==true)return true;
			}			
		}
		for(int i=mi+1;i<12;i++){
			//System.out.println(maparray[j][i]);
			if(maparray[j][i]!=0) break;
			if(i>ma){
			  if(maparray[k][i]!=0) break;	
			  //System.out.println(maparray[k][i]);
			Point p1=new Point(i,j);
		    Point p2=new Point(i,k);
			if(vertical(p1,p2)==true)return true;
			}
		}return false;
	}
	
	
	public static boolean twoCorner1(Point a, Point b1){
		int ma=a.y,mi=a.y,j=0,k=0;
		if(a.y>b1.y){mi=b1.y;ma=a.y;j=b1.x;k=a.x;}else {mi=a.y;ma=b1.y;k=b1.x;j=a.x;}
		for(int l=ma-1;l>=0;l--){
			//System.out.println(maparray[l][k]);
			if(maparray[l][k]!=0) break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -