package com.russia.rumodel;
import java.awt.Color;
import java.awt.Graphics;
import com.russia.rufinalnum.FinalNum;
import com.russia.rulistener.ShapeListener;
public class Shape {
public static final int LEFT=1;
public static final int RIGHT=2;
public static final int DOWN=3;
public static final int ROTATE=4;
private ShapeListener shapeListener;
int [][]body;
int status;
int top,left;
Ground ground;
public void Move_Left()
{
left--;
System.out.println("Blocks Left");
}
public void Move_Right()
{
left++;
System.out.println("Blocks Right");
}
public void Move_Down()
{
top++;
System.out.println("Blocks Down");
}
public void Move_Rotate()
{
status=(status+1)%body.length;
System.out.println("Blocks Rotate");
}
public void Draw_Me(Graphics g)
{
g.setColor(Color.red);
System.out.println("Shape DrawMe");
for(int x=0;x<4;x++)
{
for(int y=0;y<4;y++)
{
if(getFlag(x,y))
{
g.fill3DRect((left+x)*FinalNum.Cell_Size, (top+y)*FinalNum.Cell_Size,FinalNum. Cell_Size, FinalNum.Cell_Size, true);
}
}
}
}
private boolean getFlag(int x,int y)
{
boolean flag=(body[status][4*y+x]==1);
return flag;
}
public boolean getInside(int x,int y,boolean rotate)
{
int tempStatus=status;
if(rotate)
{
tempStatus=(status+1)%body.length;
}
boolean flag=(body[tempStatus][4*y+x]==1);
return flag;
}
private class ShapeDriver implements Runnable
{
public void run() {
// TODO Auto-generated method stub
while(shapeListener.isMoveDownable(Shape.this))
{
Move_Down();
shapeListener.shapeMoveDown(Shape.this);
try {
Thread.sleep(1000);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
}
private boolean endOfGame()
{
boolean end=false;
for(int x=0;x<FinalNum.WIDTH;x++)
{
int sum=0;
for(int y=FinalNum.HEIGHT-1;y>0;y--)
{
if(ground.obstacle[x][y]==1)
{
sum+=1;
}
if(sum>14)
{
System.out.println("Game Over!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// end=true;
return true;
}
}
}
return end;
}
public Shape()
{
new Thread(new ShapeDriver()).start();
}
public void AddShapeListener(ShapeListener listener)
{
if(listener!=null)
{
this.shapeListener=listener;
}
}
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;
}
}