//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Form1->DoubleBuffered=true;
Bevel1->Top=Tp-FieldWidth;
Bevel1->Left=Lft-FieldWidth;
Bevel1->Width=GlassWidth*NormalWidth+FieldWidth*2;
Bevel1->Height=GlassHeight*NormalWidth+FieldWidth*2;
Image1->Top=Tp;
Image1->Left=Lft;
Image1->Width=GlassWidth*NormalWidth;
Image1->Height=GlassHeight*NormalWidth;
SpeedButton1->Left=GlassWidth*NormalWidth+FieldWidth*4;
SpeedButton1->Left=GlassWidth*NormalWidth+FieldWidth*4;
SpeedButton1->Top=Tp;
Bevel2->Left= GlassWidth*NormalWidth+FieldWidth*4;
Bevel2->Width=SmallWidth*4;
Bevel2->Height=SmallHeight*4;
SpeedButton2->Left=GlassWidth*NormalWidth+FieldWidth*4;
SpeedButton2->Width=SpeedButton1->Width;
Image2->Left=SpeedButton1->Left;
Image2->Width=SmallWidth*4;
Image2->Height=SmallHeight*4;
Panel1->Left= SpeedButton1->Left;
Panel1->Width= SpeedButton1->Width;
SpeedButton3->Left= SpeedButton1->Left;
SpeedButton3->Width=SpeedButton1->Left;
Label1->Left=SpeedButton1->Left+FieldWidth*2;
Label2->Left=SpeedButton1->Left+FieldWidth*2;
Panel2->Left=SpeedButton1->Left;
Panel2->Width=SpeedButton1->Width;
SpeedButton3->Left=GlassWidth*NormalWidth+FieldWidth*4;
SpeedButton3->Width=SpeedButton1->Width;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
ClearSmallBlock(i,j);
ReadStyle();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N3Click(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawBlock(int X,int Y,TColor mColor)
{
int X1,Y1,X2,Y2;
X1=X*NormalWidth;
X2=X1+NormalWidth;
Y1=Y*NormalWidth;
Y2=Y1+NormalWidth;
Image1->Canvas->Brush->Color=mColor;
Image1->Canvas->FillRect(Rect(X1+1,Y1+1,X2-1,Y2-1));
Image2->Canvas->Pen->Color=clGray;
Image2->Canvas->MoveTo(X1,Y1);
Image2->Canvas->LineTo(X1,Y2-1);
Image2->Canvas->LineTo(X2-1,Y2-1);
Image2->Canvas->Pen->Color = clWhite;
Image2->Canvas->LineTo(X2-1,Y1);
Image2->Canvas->LineTo(X1,Y1);
}
void __fastcall TForm1::DrawSmallBlock(int X, int Y,TColor mColor)
{
int X1,Y1,X2,Y2;
X1=X*SmallWidth;
X2=X1+SmallWidth;
Y1=Y*SmallWidth;
Y2=Y1+SmallWidth;
Image2->Canvas->Brush->Color = mColor;
Image2->Canvas->FillRect(Rect(X1+1,Y1+1,X2-1,Y2-1));
Image2->Canvas->Pen->Color = clGray;
Image2->Canvas->MoveTo(X1,Y1);
Image2->Canvas->LineTo(X1,Y2-1);
Image2->Canvas->LineTo(X2-1,Y2-1);
Image2->Canvas->Pen->Color = clWhite;
Image2->Canvas->LineTo(X2-1,Y1);
Image2->Canvas->LineTo(X1,Y1);
}
void __fastcall TForm1::ClearSmallBlock(int X, int Y)
{
int X1,Y1,X2,Y2;
X1=X*SmallWidth;
X2=X1+SmallWidth;
Y1=Y*SmallWidth;
Y2=Y1+SmallWidth;
Image2->Canvas->Brush->Color=clBlack;
Image2->Canvas->FillRect(Rect(X1,Y1,X2,Y2));
}
void __fastcall TForm1::WriteNext()
{
NextPatn = random(6);
NextRotat=random(4);
NextColor=random(7);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
ClearSmallBlock(i,j);
for(i=0;i<4;i++)
DrawSmallBlock(Style[NextPatn][NextRotat*10+i*2]-1,
Style[NextPatn][NextRotat*10+i*2+1]-1,
Colors[NextColor]);
}
void __fastcall TForm1::ReadStyle()
{
for (int i=0; i<6; i++)
for (int j=0; j<40; j++)
if (Fangkuai[i][j]=='-')
Style[i][j]=0;
else Style[i][j]=Fangkuai[i][j]-'0';
}
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
for (int i=0;i<GlassWidth;i++)
for (int j=0;j<GlassHeight;j++){
GlassMap[i][j]=0;
ClearBlock(i,j);
}
Timer1->Enabled=true;
ObjectX=3,ObjectY=0;
WriteNext();
Patn=NextPatn;
Rotat=NextRotat;
WriteObject();
WriteNext();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
MoveDown();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ScanLine()
{
int Lines=0;
for (int i=0;i<GlassHeight;i++)
for (int j=0;j<GlassWidth;j++)
OldGlassMap[j][i]=GlassMap[j][i];
for (int i= 0;i<GlassHeight;i++){
int k= 0;
for (int j=0;j<GlassWidth;j++)
if (GlassMap[j][i]>0) k++;
if (k==GlassWidth){
Lines++;
for (int a=i;a>0;a--)
for (int b=0;b<GlassWidth;b++)
GlassMap[b][a]= GlassMap[b][a-1];
}
}
for (int i=0;i<GlassHeight;i++)
for (int j=0;j<GlassWidth;j++)
if (OldGlassMap[j][i]!=GlassMap[j][i])
if (GlassMap[j][i]==0) ClearBlock(j,i);
else DrawBlock(j,i,Colors[GlassMap[j][i]-1]);
switch(Lines){
case 1: Score +=100;
break;
case 2: Score +=250;
break;
case 3: Score +=550;
break;
case 4: Score +=1200;
break;
}
}
void __fastcall TForm1::MoveDown()
{
bool chk=false;
int xx,yy=Style[Patn][Rotat*10+1]+ObjectY;
if (yy<23){
yy=Style[Patn][Rotat*10+3]+ObjectY;
if (yy<23){
yy=Style[Patn][Rotat*10+5]+ObjectY;
if (yy<23){
yy=Style[Patn][Rotat*10+7]+ObjectY;
if (yy<23){
if (chk=HitCheck(ObjectX,ObjectY+1,Rotat)){
ObjectY++;
WriteObject();
}
}
}
}
}
if (!chk){
// ScanLine()
for (int i=0;i<4;i++){
xx=ObjectX+Style[Patn][Rotat*10+i*2]-1;
yy=ObjectY+Style[Patn][Rotat*10+i*2+1]-1;
GlassMap[xx][yy]=1;
}
ScanLine() ;
level=1;
if(Score>5000)
{level=2;}
if(Score>12000)
{level=3;}
if(Score>21000)
{level=4; }
if(Score>33000)
{level=5;}
if(Score>49000)
{level=6; }
if(Score>100000)
{level=7;}
Timer1->Interval=800-100*level;
Panel2->Caption=AnsiString(Score);
Panel1->Caption=AnsiString(level);
ObjectX=3;
ObjectY=0;
Patn=NextPatn;
Rotat=NextRotat;
ObjectColor=NextColor;
MoveFlag=false;
WriteObject();
if(!HitCheck(ObjectX,ObjectY,Rotat)){
Timer1->Enabled=false;
ShowMessage("^_^");
}
WriteNext();
}
}
void __fastcall TForm1::WriteObject()
{
if(MoveFlag)
for (int i=0;i<4;i++)
ClearBlock(OldX[i],OldY[i]);
MoveFlag=true;
for (int i=0;i<4;i++){
OldX[i]=ObjectX+Style[Patn][Rotat*10+i*2]-1;
OldY[i]=ObjectY+Style[Patn][Rotat*10+i*2+1]-1;
DrawBlock(OldX[i],OldY[i],Colors[ObjectColor]);
}
}
void __fastcall TForm1::ClearBlock(int X,int Y)
{
int X1,Y1,X2,Y2;
X1 = X*NormalWidth;
X2 = X1+NormalWidth;
Y1 = Y*NormalHeight;
Y2 = Y1+NormalHeight;
Image1->Canvas->Brush->Color=clBlack;
Image1->Canvas->FillRect(Rect(X1,Y1,X2,Y2));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MoveLeft()
{
int xx=Style[Patn][Rotat*10]+ObjectX-2;
if (xx >=0){
xx=Style[Patn][Rotat*10+2]+ObjectX-2;
if (xx >=0){
xx=Style[Patn][Rotat*10+4]+ObjectX-2