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

📄 paint.java

📁 一个俄罗斯方块游戏
💻 JAVA
字号:

import java.awt.*;
import java.awt.event.*;
import java.util.*;

 public class Paint{

OneSquareDown st;

public Paint(OneSquareDown st){
	this.st=st;//指定绘图区
}	
  
//画出砖块组动作区地图外框	
public void DrawMapFrame(int x,int y,int wid,int hig,int side){
	
	//定义多边形坐标
	int xx[][]={{x,x+wid,x+wid-side,x+side},//上
		     {x+wid-side,x+wid,x+wid,x+wid-side},//右
			 {x+side,x+wid-side,x+wid,x},//下
			 {x,x+side,x+side,x}};//左
	int yy[][]={{y,y,y+side,y+side},//上
		     {y+side,y,y+hig,y+hig-side},//右
			 {y+hig-side,y+hig-side,y+hig,y+hig},//下
			 {y,y+side,y+hig-side,y+hig}};//左		

			
	//画出多边形
	for(int i=0;i<=3;i++){
		
		//不同边设定不同颜色
		switch(i){
			case 0:
				st.g.setColor(new Color(150,150,150));
				break;
			case 1:
				st.g.setColor(new Color(150,150,150));
				break;
			case 2:
				st.g.setColor(new Color(180,180,180));
				break;
			case 3:
				st.g.setColor(new Color(180,180,180));
				break;
		}
		
		st.g.fillPolygon(xx[i],yy[i],4);				
		st.g.setColor(Color.black);
		st.g.fillRect(x+side-1,y+side-1,wid-side*2+2,hig-side*2+2);
	}
}

//画出砖块组
public void DrawBrickGroup(int x,int y,int type,int direct,Color c){
	Square sb=(Square)st.BrickArray.get(type);
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if(sb.BRICK_ARRAY[direct][i][j]==1){
				DrawBrick((i+x),(j+y),c);
			}
		}	
	}
}
//清除前一个砖块组
public void DrawBrickGroup(int fx,int fy,int fdirect){
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if((i+st.NOW_BRICK_X)>=0 && (i+st.NOW_BRICK_X)<st.GRIDX && 
			   (j+st.NOW_BRICK_Y)>=0 && (j+st.NOW_BRICK_Y)<st.GRIDY){
				if(st.NowBrick.BRICK_ARRAY[fdirect][i][j]==1){
					DrawBrick(i+fx,j+fy,Color.black);
					
				}
			}
		}	
	}

	//画出现在砖块组
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if((i+st.NOW_BRICK_X)>=0 && (i+st.NOW_BRICK_X)<st.GRIDX && 
			   (j+st.NOW_BRICK_Y)>=0 && (j+st.NOW_BRICK_Y)<st.GRIDY){
			if(st.NowBrick.BRICK_ARRAY[st.NOW_BRICK_DIRECT][i][j]==1){
					DrawBrick(i+st.NOW_BRICK_X,
						      j+st.NOW_BRICK_Y,
						     Color.blue);
				}
			}
		}	
	}
}	

//画出单一砖块
public void DrawBrick(int x,int y,Color c){
	st.g.setColor(Color.black);
	st.g.drawRect(x*st.BRICK_WIDTH+st.MAPX,y*st.BRICK_WIDTH+st.MAPY,
			      st.BRICK_WIDTH-1,st.BRICK_WIDTH-1);
	st.g.setColor(c);
	st.g.fill3DRect(x*st.BRICK_WIDTH+st.MAPX+st.BRICK_SIDE,
					y*st.BRICK_WIDTH+st.MAPY+st.BRICK_SIDE,
			        st.BRICK_WIDTH-st.BRICK_SIDE*2,
			        st.BRICK_WIDTH-st.BRICK_SIDE*2,true);				      
}

//画出字型
public void DrawFont(String str,int x,int y,int size,Color c,String fs){
	Font f=new Font(fs,Font.BOLD,size);
	st.g.setColor(c);
	st.g.setFont(f);
	st.g.drawString(str,x,y);	
}
}






⌨️ 快捷键说明

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