package eluosi104502601;
import java.awt.Color;
import java.awt.Graphics;
public class GameShape {
private int[][] blocktype;
private int turnstate;
private int left=3;
private int top=-1;
public int action;
public int type;
public Color color0;
public Color color1;
public Color color2;
public Color color3;
public Color color4;
public Color color5;
public Color color6;
public Color color7;
public Color tempcolor;
public GameShape(){
color0 = new Color(0,0,0);
color1 = new Color(241,193,193);
color2 = new Color(241,255,160);
color3 = new Color(170,196,255);
color4 = new Color(176,255,223);
color5 = new Color(211,152,255);
color6 = new Color(255,195,152);
color7 = new Color(175,175,175);
}
public void moveLeft(){
System.out.println("Shape's moveLeft");
action = 1;
left--;
}
public void moveRight(){
System.out.println("Shape's moveRight");
action = 2;
left++;
}
public void moveDown(){
System.out.println("Shape's moveDown");
action = 3;
top++;
}
//旋转 转向状态
public void rotate(){
System.out.println("Shape's rotate");
action = 0;
turnstate = (turnstate + 1) % 4;
}
public void paint(Graphics g){
System.out.println("Shape's drawMe(paint)");
for(int a=0;a<4;a++)
{
for(int b=0;b<4;b++)
{
if(ifNeedToPaint(a,b))
{
g.setColor(tempcolor);
g.fill3DRect((left + a)*30, (top + b)*30, 30, 30, true);
System.out.println("Shape's is painting");
}
}
}
}
private boolean ifNeedToPaint(int x , int y){
tempcolor = getColor(blocktype[turnstate][4*y+x]);
return blocktype[turnstate][4*y+x] != 0;
}
public boolean isMember(int x, int y, boolean ifrotate){
int tempTurnState = turnstate;
if(ifrotate)
{
tempTurnState = (turnstate + 1) % 4;
}
return blocktype[tempTurnState][4*y+x] != 0;
}
public void setBlockType(int blocktype[][]){
this.blocktype = blocktype;
}
public void setType(int type){
this.type = type;
}
public int getType(){
return type;
}
public void setTurnState(int turnstate){
this.turnstate = turnstate;
}
public int getTop(){
return top;
}
public int getLeft(){
return left;
}
public Color getColor(int i)
{
if(i==1)
{
return color1;
}
else if(i==2)
{
return color2;
}
else if(i==3)
{
return color3;
}
else if(i==4)
{
return color4;
}
else if(i==5)
{
return color5;
}
else if(i==6)
{
return color6;
}
else if(i==7)
{
return color7;
}
else
{
return null;
}
}
}
别学了,打两把游戏吧