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

📄 actionbtn.java

📁 俄罗斯方块的java源代码
💻 JAVA
字号:
import javax.swing.JButton;
import java.awt.*;

import javax.swing.*;
import javax.swing.border.Border;

/*
 * Created on 2004-11-17
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Softmedical
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

//class ActionBtn:all the boxes item would be attach to this
public class ActionBtn extends JPanel{
private boolean[][] flags=new boolean[40][20];
private JButton[][] lines=new JButton[40][20];//consumed btn stored here

public ActionBtn(){
	this.setBackground(Color.BLUE);
	this.setBounds(50,50,300,600);//20,40
	this.setFocusable(false);
    this.setLayout(null);
    this.setBorder(new Border(){

		public boolean isBorderOpaque() {
			// TODO Auto-generated method stub
			return false;
		}

		public void paintBorder(Component arg0, Graphics arg1, int arg2, int arg3, int arg4, int arg5) {
			// TODO Auto-generated method stub
			arg1.setColor(Color.RED);
			
			arg1.draw3DRect(arg2,arg3,arg4,arg5,true);
		}

		public Insets getBorderInsets(Component arg0) {
			// TODO Auto-generated method stub
			return null;
		}});
     
}



public void FlashLine(int linenum){//
	//flash line and remove ....calculate the score
	//flashing music playing....
 if(isLineEmpty(linenum))return;
 for(int i=0;i<lines[linenum].length;i++){
		 remove(lines[linenum][i]);
		 setBtn(linenum,i,null);
         setFlag(linenum,i,false);
        }
       repaint();
    for(int i=linenum-1;i>=0;i--){//a step down 
	if(!isLineEmpty(i)){
		for(int j=0;j<lines[linenum].length;j++){
		if(lines[i][j]!=null){
		 	JButton temp=lines[i][j];
		 	lines[i][j].setLocation(lines[i][j].getX(),lines[i][j].getY()+15);
		 	setFlag(i,j,false);
		 	lines[i][j]=null;
    		setFlag(i+1,j,true);
    		setBtn(i+1,j,temp);
    	  	
	  }
	 }
	
	}
     
  }

        
}

public void reset(){
this.removeAll();
for(int i=0;i<lines.length;i++){
for(int j=0;j<lines[0].length;j++){
lines[i][j]=null;
flags[i][j]=false;

}	
}	
this.score=0;
this.level=1;

}
public void gameFailApearanceShower(){
	  this.removeAll();
	  JButton btn=null;
	  JButton[][] group=new JButton[20][10];
	this.setLayout(null);
	  for(int i=1;i<19;i++)
	  	for(int j=1;j<9;j++){
	  		btn=new JButton();
	  		btn.setBackground(Color.ORANGE);
	  		btn.setSize(30,30);
	  		btn.setLocation(j*30,i*30);
	  		group[i][j]=btn;
	  	    this.add(btn);
	  	    	
	  	}
	  try{
	 ////produce 'z' 
	  group[1][2].setBackground(Color.RED);
	  for(int i=2;i<7;i++){/********/
	  	group[2][i].setBackground(Color.RED);
	  	group[8][i].setBackground(Color.RED);
	  }
	  
	  
	int col=6;
	group[3][2].setBackground(Color.RED);
	group[7][6].setBackground(Color.RED);
	for(int i=3;i<8;i++){
	    group[i][col].setBackground(Color.red);
	 	col--;
	 		 
	 }
	  	 

	//priduce 's'
	group[9][6].setBackground(Color.RED);
	group[10][4].setBackground(Color.RED);
	group[9][4].setBackground(Color.RED);
	group[9][5].setBackground(Color.RED);
	group[10][3].setBackground(Color.RED);
	group[11][2].setBackground(Color.RED);
	group[12][2].setBackground(Color.RED);
	group[13][3].setBackground(Color.RED);
	group[13][4].setBackground(Color.RED);
	group[13][5].setBackground(Color.RED);
	group[14][6].setBackground(Color.RED);
	group[15][7].setBackground(Color.RED);
	group[16][7].setBackground(Color.RED);
	
	group[17][6].setBackground(Color.RED);
	group[18][5].setBackground(Color.RED);
	group[18][4].setBackground(Color.RED);
	group[18][3].setBackground(Color.RED);
	group[18][2].setBackground(Color.RED);
	group[17][2].setBackground(Color.RED);
	
	  }catch(Exception e){}
	
	
	
	
	    repaint();
	  }

public void gameSuccessfulApearanceShower(){
	  this.removeAll();
	  JButton btn=null;
	  this.setLayout(new FlowLayout());
	  for(int i=1;i<39;i++)
	  	for(int j=1;j<19;j++){
	  		btn=new JButton();
	  		btn.setBackground(Color.ORANGE);
	  		btn.setSize(15,15);
	  		btn.setLocation(j*15,i*15);
	  	    this.add(btn);
	  	}
	    repaint();
	  


}
public void gameFirstApperanceShower(){
	
   }

//This set of interfaces are used to caculate the score
private int score;
public int getScore(){return this.score;}
public void setScore(int score){this.score=score;};


private int level=1;
public  int getLevel(){return this.level;}
public  void setLevel(int level){this.level=level;} 
public void speedUp(){
	this.interval=500-(47*this.level);

}
private int interval=500;
public int getInterval(){return this.interval;}
private void setInterval(int interval){this.interval=interval;}


public void setBtn(int row,int col,JButton btn){
 	if(row>lines.length||col>=lines[0].length)
 		 return ;
   	lines[row][col]=btn;
   } 

public void setFlag(int row ,int col,boolean flag){
	
	 this.flags[row][col]=flag;
	  }
public boolean getFlag(int row,int col){

	 	return this.flags[row][col];
	 } 


public boolean isLineFull(int linenum){
	
	boolean fFlag=true;
	for(int i=0;i<lines[0].length;i++){
	if(!flags[linenum][i]){fFlag=false;
	break;
	}}
	return fFlag;}

public boolean isLineEmpty(int linenum){
	boolean eFlag=true;
	for(int i=0;i<lines[0].length;i++){
	if(flags[linenum][i]){
		eFlag=false;
		break;
	 	}}
	
return eFlag;}


//Belows are some rare_used interfaces...........................................

public void colorLine(int linenum,Color color){
	for(int i=0;i<lines[0].length;i++){
	lines[linenum][i].setBackground(color);	
	}


}
public  boolean isToFlash(){
	 boolean flashFlag=false;
	for(int i=0;i<lines.length;i++){
		if(this.isLineFull(i))
		{	flashFlag=true;
		  }
	  	}
	return flashFlag;

}
public int  getFirstFlashLine(){
   for(int i=0;i<lines.length;i++){
	if(this.isLineFull(i))return i;	
	}
 return -1;//no lines to flash...
}
public boolean isFull(){
   boolean fFlag=true;
   for(int i=lines[0].length-1;i>=0;i--){
   	for(int j=lines.length-1;j>=0;j--){
        if(!flags[j][i])fFlag=false;	
        break;  
   	}
    }
   return fFlag;
   }

public boolean isEmpty(){
 boolean eFlag=true;
 for(int i=0;i<lines.length;i++)
 	 for(int j=0;j<lines[0].length;j++)
 		if(flags[i][j]){eFlag=false;
 		 break;
 		}
 return eFlag;
 	}

 public boolean isAreaEmtpy(int brow,int bcol,int colnum,int rownum ){
 boolean eFlag=true;
 	for(int i=brow;i<rownum;i++)
 		for(int j=bcol;j<colnum;j++)
 			if(this.getFlag(i,j))eFlag=false;
 		return eFlag;
    }	 



}







⌨️ 快捷键说明

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