package cn.itcast.tetris.entities;
import java.awt.Color;
import java.awt.Graphics;
import cn.itcast.tetris.listener.ShapeListener;
import cn.itcast.tetris.utill.Global;
public class Shape {
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 int[][] body;
private int status;
private int left;
private int top;
private ShapeListener listener;
public void moveLeft(){
System.out.println("Shape's moveLeft");
left--;
}
public void moveRight(){
System.out.println("Shape' moveRight");
left++;
}
public void moveDown(){
System.out.println("Shape,s moveDown");
top++;
}
public void rotate(){
System.out.println("Shape's moveDown");
status=(status+1)%body.length;
}
public void drawMe(Graphics g){
System.out.println("Shape's drawMe");
g.setColor(Color.BLUE);
for(int x=0;x<4;x++){
for(int y=0;y<4;y++){
if(getFlagByPoint(x,y)){
g.fill3DRect((left+x)*Global.CELL_SIZE,
(top+y)*Global.CELL_SIZE,
Global.CELL_SIZE,Global.CELL_SIZE,
true);
}
}
}
}
private boolean getFlagByPoint(int x, int y){
return body[status][y*4+x]==1;
}
public boolean isMember(int x,int y,boolean rotate){
int tempStatus=status;
if(rotate){
tempStatus=(status+1)%body.length;
}
return body[tempStatus][y*4+x]==1;
}
private class ShapeDriver implements Runnable{
public void run(){
while(listener.isShapeMoveDownable(Shape.this)){
moveDown();
listener.shapeMoveDown(Shape.this);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public Shape(){
new Thread(new ShapeDriver()).start();
}
public void addShapeListener(ShapeListener l){
if(l!=null)
this.listener=l;
}
public void setBody(int body[][]){
this.body=body;
}
public void setStatus(int status){
this.status=status;
}
public int getTop(){
return top;
}
public int getLeft(){
return left;
}
}
俄罗斯方块游戏代码 本代码主要是俄罗斯方块的游戏的概要设计
需积分: 12 54 浏览量
2010-12-20
09:37:44
上传
评论
收藏 15KB RAR 举报
lzyxy5182
- 粉丝: 1
- 资源: 1