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

📄 lianlian.java

📁 和同学编的连连看小游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			if(l<mi){
			  if(maparray[l][j]!=0) break;	
			  //System.out.println(maparray[l][j]);
			Point p1=new Point(j,l);
		    Point p2=new Point(k,l);
			if(horizon(p1,p2)==true)return true;
			
		}}
		for(int i=mi+1;i<12;i++){
			//System.out.println(maparray[i][j]);
			if(maparray[i][j]!=0) break;
			if(i>ma){
			  if(maparray[i][k]!=0) break;	
			  //(maparray[i][k]);
			Point p1=new Point(j,i);
		    Point p2=new Point(k,i);
			if(horizon(p1,p2)==true)return true;
			}
		}
		return false;
	}
	
	public static boolean oneCorner(Point a, Point b1){
		
		Point p2=new Point(a.x,b1.y);
		Point p1=new Point(b1.x,a.y);
		//System.out.println(p1.x+" "+p2.x);
		//System.out.println(maparray[a.y][b1.x]+"  "+maparray[b1.y][a.x]+horizon(a,p1)+" "+horizon(b1,p2));
		if(maparray[a.y][b1.x]==0&&horizon(a,p1)==true&&vertical(b1,p1)==true)             				  	 		  
		  return true;		 		  				  				
		else if(maparray[b1.y][a.x]==0&&horizon(b1,p2)==true&&vertical(a,p2)==true)     		  		    	    	
		  return true;		    
		 //	System.out.println("xiangdeng");return true;}		 		 		
		else return false;
	}
	
	public static boolean vertical(Point a, Point b1){
		if(a.x==b1.x){
		int i=0,j=0;
		if(a.y<b1.y){i=a.y;j=b1.y;} else {i=b1.y;j=a.y;}
		for(int n=i+1;n<j;n++)
		{if(maparray[n][a.x]!=0) return false;}
		  
		return true;
	}else return false;	
	}
	
	public static boolean horizon(Point a, Point b1){
		if(a.y==b1.y){
		int i=0,j=0;
		if(a.x<b1.x){i=a.x;j=b1.x;} else {i=b1.x;j=a.x;}
		for(int n=i+1;n<j;n++)
		{
			if(maparray[a.y][n]!=0) {return false;};}
		  //System.out.println("buxiangdeng"+maparray[a.y][n]);
		return true;
	
	}else return false;	
	}
	
	
	public static void begin(){
		    f.getContentPane().removeAll();	 
	        Map1 map1=new Map1(); 
	        map1.randomset(map1.array);
	        draw(map1);tpanel.setBackground(Color.darkGray);
	        Dimension da=new Dimension(450,20); 
	        progress.setStringPainted(true);
     	    progress.setMaximum(100);
     	    progress.setMinimum(0);
     	    progress.setValue(0);
     	    progress.setPreferredSize(da);
     	    progress.setBackground(new Color(255,0,0));
     	    tpanel.add(progress);
     	    tpanel.setSize(500,50);
     	    f.add(tpanel,"North");          
            f.setVisible(true);
            count=0;
	}
	
	public static void giveup(){
		f.getContentPane().removeAll();	 
    	JPanel panelset=new JPanel();
    	f.getContentPane().add( panelset);
    	panelset.add(backbutton);
    	time.stop();ji=0;
    	f.setVisible(true);
    	m11.setEnabled(true);m12.setEnabled(false);
        m21.setEnabled(false);m24.setEnabled(false);
        count=0;
	}
	
	
	
    public static void reset(){
    	int[]newarray=new int[100];
    	System.out.println("reset");
    	Map1 mapset=new Map1(); 
    	int tn=0,tn1=0;
    	for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				if(maparray[i+1][j+1]!=0){
				newarray[tn]=maparray[i+1][j+1];tn++;}
		}}
        mapset.randomset(newarray);
        for(int i=1;i<11;i++){
        	for(int j=1;j<11;j++){
        		if(maparray[i][j]!=0){
        			image[i][j]=new ImageIcon(newarray[tn1]+".jpg");
        			maparray[i][j]=newarray[tn1];
        			tn1++;
        		}
        		else image[i][j]=null;
        	}
        }
        for(int i=1 ;i<ROW+1;i++){
		for(int j=1;j<COLUMN+1;j++){
			 b[i][j].setIcon(image[i][j]);
			 b[i][j].x=i;
			 b[i][j].y=j;
			 
			 
		}
	   }
        for(int i=1;i<11;i++){
			for(int j=1;j<11;j++){
				if(maparray[i][j]==0){
					b[i][j].setVisible(false);
				}}}    	
    				
	}//end of reset
		
		
	public static void buttomaction(){
		
		for(int i1=1 ;i1<ROW+1;i1++){
		for(int j1=1;j1<COLUMN+1;j1++){
			//jj[j]=j;ii[i]=i;
			b[i1][j1].addMouseListener(new MouseAdapter(){
    			public void mouseClicked(MouseEvent e){
    					 
    			MyJButton bb;
    			bb=(MyJButton)e.getSource();
    					
    			point1.x=bb.y;point1.y=bb.x; //System.out.println("click "+point1.x+" "+point1.y);   					
		        if(click2==0){
		    	    point2=new Point(point1); 		    	
		    	    click2=1;
		    	    System.out.println("click one");
		           }
		        else if(click2==1&&point1.equals(point2)==false){
		            System.out.println("click two");   
		            if(connet(point1,point2 )){
		            maparray[point1.y][point1.x]=0;
    		    	maparray[point2.y][point2.x]=0;
    		    	b[point1.y][point1.x].setVisible(false);
    		    	b[point2.y][point2.x].setVisible(false);
    		    	click2=0;
    		    	count++;  ji-=2;progress.setValue(ji);
    			
    			if(count==50){
    				time.stop();
    			    //System.out.println("jieshu");
		            JOptionPane pane=new JOptionPane();
                    pane.showMessageDialog(f," Clever!  You Win!  You can start again!","  Win ",JOptionPane.INFORMATION_MESSAGE);
    			    giveup();
    			   }  
    			else if(autoreset()==false ){
    				 System.out.println("No connection");
                     JOptionPane pan=new JOptionPane();
                     pan.showMessageDialog(f,"No more connections! Please reset!"," Direct ",JOptionPane.INFORMATION_MESSAGE);
                   }
		          }else point2=new Point(point1);
		        }
    			}//end of mouseclick
    				
    				
    			}
    			);}
    			}
		
	}//end of buttomaction
	
    
    
    
    public static void draw(Map1 map1){
		
	JPanel p=new JPanel();
	p.setBackground(Color.darkGray); 
	
	for(int i=1;i<ROW+1;i++){
		for(int j=1;j<COLUMN+1;j++){
			 image[i][j]=new ImageIcon(map1.map[i-1][j-1]+".jpg");
			maparray[i][j]=map1.map[i-1][j-1];
		}
	}
	
	
	for(int i=0 ;i<ROW+2;i++){
		for(int j=0;j<COLUMN+2;j++){
			 b[i][j]= new MyJButton( image[i][j]);
			 b[i][j].x=i;
			 b[i][j].y=j;
		}
	}
	
	buttomaction();
	p.setLayout(new GridLayout(ROW+2,COLUMN+2));
    f.add(p,"Center");
    
    for(int i=0;i<ROW+2;i++){
		for(int j=0;j<COLUMN+2;j++){
			 p.add( b[i][j]);
		}
	}
	
	for(int n=0;n<12;n++){
		 b[0][n].setVisible(false);
		 b[11][n].setVisible(false);
		 b[n][0].setVisible(false);
		 b[n][11].setVisible(false);
		
	} 
        timeCount();
	}//end of draw
	
	
	
}//end of LianLian




//Map
class Map1{
	int[][]map=new int[LianLian.ROW][LianLian.COLUMN];
	int[] array=new int[LianLian.ROW*LianLian.COLUMN];
	int maxElement=25;
	int elements=25;
	
	 Map1(){  //Random map
		
		for(int m=0;m<maxElement;m++){
		array[m*4]=m+1;
		array[m*4+1]=m+1;
		array[m*4+2]=m+1;
		array[m*4+3]=m+1;
	    }
	}
	
  void randomset(int[]arra){
  	
	java.util.Random random = new java.util.Random();
	   for(int i=arra.length-1;i>0;i--){
	   	    if(arra[i]!=0){
	    	int j=random.nextInt(i);
	    	int temp=arra[j];
	    	arra[j]=arra[i-1];
	    	arra[i-1]=temp;}
	    }
	    
	    for(int i=0;i<LianLian.ROW;i++){
		for(int j=0;j<LianLian.COLUMN;j++){
			map[i][j]=arra[i*LianLian.COLUMN+j];
		}
	}
	}
	
}


class MyJButton extends JButton{
	int x;
	int y;
	public MyJButton(ImageIcon i){
		super(i);
	}
}

⌨️ 快捷键说明

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