package game; import util.Config; import java.awt.*; import static game.Tetrisblok.shapes; public class Block { private int w=Config.BlockSize; private int h=Config.BlockSize; private int col; private int row; int score; double speed=1; private Color color=Color.gray; int[][] map=new int[Config.COL+5][Config.ROW]; public Block(int col,int row){ this.col=col; this.row=row; } public Block(){ } // 初始化地图 public void newmap() { for (int i = 2; i < Config.COL-2; i++) { for (int j = 2; j < Config.ROW-2; j++) { map[i][j] = 0; } } } public void draw(Graphics g) { Color c = g.getColor(); g.setColor(color); g.drawRect(Config.BlockSize * col, Config.BlockSize * row, w, h); g.setColor(c); } //判断下落的方块是否碰到墙或者碰到以前掉下去的方块 //如果碰到则返回0 //判断小砖块是否合法 //相当于碰撞检测 public boolean blow(int x, int y, int blockType,int turnState){ for(int a=0;a<4;a++){ for(int b=0;b<4;b++){ if (((shapes[blockType][turnState][a * 4 + b] == 1) && (map[x + b + 1][y + a] == 1)) || ((shapes[blockType][turnState][a * 4 + b] == 1) && (map[x + b + 1][y + a] == 2))) { return true; } } } return false; } // 消行的方法 public void delline() { int c = 0; for (int b = 0; b < Config.ROW-1; b++) { for (int a = 0; a < Config.COL-1; a++) { if (map[a][b] == 1) { c = c + 1; if (c == Config.COL-4) { score += 10; speed +=0.1; for (int d = b; d > 0; d--) { for (int e = 0; e < Config.COL-2; e++) { map[e][d] = map[e][d - 1]; } } } } } c = 0; } } // 把当前添加map //添加上去的砖块会使map赋值为1 public void add(int x, int y, int blockType, int turnState) { int j = 0; for (int a = 0; a < 4; a++) { for (int b = 0; b < 4; b++) { if (map[x + b + 1][y + a] == 0) { map[x + b + 1][y + a] = shapes[blockType][turnState][j]; } j++; } } } //画围墙 public int[][] drawwall() { for (int i = 1; i < Config.COL-1; i++) { map[i][Config.ROW-2] = 2; } for (int j = 0; j < Config.ROW-1; j++) { map[Config.COL-2][j] = 2; map[1][j] = 2; } return map; } public int getCol() { return col; } public void setCol(int col) { this.col = col; } public int getRow() { return row; } public void setRow(int row) { this.row = row; } }

ClydeSon LV5
2023年12月27日
1474371745 LV1
2023年12月23日
微信网友_6699076084797440 LV7
2023年10月30日
lsglsg9 LV23
2022年9月27日
uuuuuu1 LV1
2022年6月3日
姜广坤 LV14
2022年5月21日
二十 LV1
2021年12月8日
15661649928 LV1
2020年12月12日
jrh947869206 LV4
2020年12月7日
Zcjiayouya LV1
2020年9月6日

13133117021 LV5
2024年12月24日
saikiTEST
2024年12月12日
暂无贡献等级
yimaoermao LV1
2024年9月21日
luoyanglin LV2
2024年9月14日
azzzz1 LV2
2024年6月26日
bill1234 LV1
2024年6月23日
RicardoLou
2024年5月7日
暂无贡献等级
ClydeSon LV5
2023年12月27日
1474371745 LV1
2023年12月23日
iceworld
2023年11月30日
暂无贡献等级