?? ground.java
字號:
package com.zhanggang.teris.entities;
import java.awt.Color;
import java.awt.Graphics;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import com.zhang.teris.util.Global;
public class Ground {
private int[][] obstacle = new int[Global.HEIGHT][Global.WIDTH];
public void accept(Shape shape) {
System.out.println("Ground's accept");
int left = shape.getLeft();
int top = shape.getTop();
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
if (shape.getFlagByPoint(x, y)) {
obstacle[top + y][left + x] = 1;
}
}
}
deleteFullLine();
}
public void drawMe(Graphics g) {
System.out.println("Groud's drawMe");
for (int y = 0; y < Global.HEIGHT; y++) {
for (int x = 0; x < Global.WIDTH; x++) {
if (obstacle[y][x] == 1) {
g.fill3DRect(x * Global.CELL_SIZE, y * Global.CELL_SIZE,
Global.CELL_SIZE, Global.CELL_SIZE, true);
} else {
Color c = g.getColor();
g.setColor(new Color(0xd7d7de));
g.drawRect(x * Global.CELL_SIZE, y * Global.CELL_SIZE,
Global.CELL_SIZE, Global.CELL_SIZE);
g.setColor(c);
}
}
}
}
public boolean isMovable(Shape shape, int action) {
int left = shape.getLeft();
int top = shape.getTop();
int[] body = shape.getPresentBody();
switch (action) {
case Shape.LEFT:
left--;
break;
case Shape.RIGHT:
left++;
break;
case Shape.DOWN:
top++;
break;
case Shape.ROTATE:
body = shape.getRotateBody();
break;
default:
break;
}
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
if (body[y * 4 + x] == 1) {// top 和 left
// 是從0開始的,所以它們不能等于邊界,如果允許它們在邊界時也可以變形,這回引起存儲障礙物的數組下標越界
if ((top + y) >= Global.HEIGHT || (left + x) < 0
|| (left + x) >= Global.WIDTH
|| obstacle[top + y][left + x] == 1) {
return false;
}
}
}
}
return true;
}
private void deleteFullLine() {
for (int y = 0; y < Global.HEIGHT; y++) {
boolean isFullLine = true;
for (int x = 0; x < Global.WIDTH; x++) {
if (obstacle[y][x] == 0) {
isFullLine = false;
}
}
if (isFullLine) {
deleteLine(y);
}
}
}
private void deleteLine(int line) {
for (int y = line; y > 0; y--) {
for (int x = 0; x < Global.WIDTH; x++) {
obstacle[y][x] = obstacle[y - 1][x];
}
}
for (int x = 0; x < Global.WIDTH; x++) {
obstacle[0][x] = 0;
}
}
public boolean isFull() {
for (int x = 0; x < Global.WIDTH; x++) {
if (obstacle[0][x] == 1) {
return true;
}
}
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -