?? shape.java
字號(hào):
package com.zhanggang.teris.entities;
import java.awt.Graphics;
import com.zhang.teris.listener.ShapeListener;
import com.zhang.teris.util.Global;
public class Shape {
private int[][] body;
private int status;
private int left = Global.WIDTH / 2;
private int top;
public static final int ROTATE = 0;
public static final int LEFT = 1;
public static final int RIGHT = 2;
public static final int DOWN = 3;
private ShapeListener shapeListener;
public void moveLeft() {
System.out.println("Shape's moveLeft");
left --;
}
public void moveRight() {
System.out.println("Shape's moveRight");
left ++;
}
public void moveDown() {
System.out.println("Shape's moveDown");
top ++;
}
public void rotate() {
System.out.println("Shape's rotate");
status = (status + 1) % body.length;
}
public int[] getPresentBody() {
return body[status];
}
public int[] getRotateBody() {
int tempStatus = (status + 1) % body.length;
return body[tempStatus];
}
public void drawMe(Graphics g) {
System.out.println("Shape's drawMe");
for(int y=0; y<4; y++) {
for(int x=0; x<4; x++) {
if(getFlagByPoint(x, y)) {
g.fill3DRect((left + x) * Global.CELL_SIZE , (top + y) * Global.CELL_SIZE,
Global.CELL_SIZE, Global.CELL_SIZE, true);
}
}
}
}
/**
*
* @param x 列
* @param y 行
* @return
*/
public boolean getFlagByPoint(int x, int y) {
if(body[status][y * 4 + x] == 1)
return true;
else return false;
}
private class ShapeDirver implements Runnable {
public void run() {
while(shapeListener.isMoveDownable(Shape.this)) {
moveDown();
shapeListener.shpeMoveDown(Shape.this);
try {
Thread.sleep(100 * Global.GAME_SPEED);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public void addShapeListener(ShapeListener shapeListener) {
if(shapeListener != null) {
this.shapeListener = shapeListener;
}
}
public void runShapeDirver() {
new Thread(new ShapeDirver()).start();
}
public int[][] getBody() {
return body;
}
public void setBody(int[][] body) {
this.body = body;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getLeft() {
return left;
}
public void setLeft(int left) {
this.left = left;
}
public int getTop() {
}
public void setTop(int top) {
this.top = top;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -