?? ground.java
字號:
package lx.entity;
import java.awt.Graphics;
import lx.util.Global;
public class Ground {
//障礙物數組
private int[][] obstacles = new int[Global.WIDTH][Global.HIGHT];
//接受圖形方法
public void accept(Shape shape){
for(int x = 0; x < 4; x++){
for(int y = 0; y < 4; y++){
if(shape.isMember(x, y, false)){
obstacles[shape.getLeft()+x][shape.getTop()+y] = 1;
}
}
}
deleteFullLine();
}
//繪制圖形方法
public void drawMe(Graphics g){
for(int x = 0; x < Global.WIDTH; x++){
for(int y = 0; y < Global.HIGHT; y++){
if(obstacles[x][y] == 1){
g.fill3DRect(x*Global.CELL_SIZE,
y*Global.CELL_SIZE,
Global.CELL_SIZE,
Global.CELL_SIZE, true);
}
}
}
}
//判斷圖形是否可以移動
public boolean isMoveable(Shape shape,int action){
int left = shape.getLeft();
int top = shape.getTop();
switch (action) {
case Shape.LEFT :
left--;
break;
case Shape.RIGHT :
left++;
break;
case Shape.DOWN :
top++;
break;
}
for(int x = 0; x < 4; x++){
for(int y = 0; y < 4; y++){
if(shape.isMember(x, y,action == Shape.ROTATE)){
if(top + y >= Global.HIGHT ||
left + x < 0 ||
left + x >= Global.WIDTH ||
obstacles[left+x][top+y] == 1){
return false;
}
}
}
}
return true;
}
//將累積一行滿行消除
private void deleteFullLine(){
for(int y = Global.HIGHT-1; y >= 0; y--){
boolean full = true;
for(int x = 0; x < Global.WIDTH; x++){
if(obstacles[x][y] == 0){
full = false;
}
}
if(full){
deleteLine(y);
}
}
}
//刪除行
private void deleteLine(int lineNUm){
for(int y = lineNUm; y > 0; y--){
for(int x = 0; x < Global.WIDTH; x++){
obstacles[x][y] = obstacles[x][y-1];
}
}
for(int x = 0; x < Global.WIDTH; x++){
obstacles[x][0] = 0;
}
}
//結束游戲
public boolean isFull(){
for(int x = 0; x < Global.HIGHT; x++){
if(obstacles[x][0] == 1){
return true;
}
}
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -