為何要跑一個多小時才有結果?這是正常況狀嗎?
下面是我的原始碼.謝謝 //--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TPanel *box1[10][10];
int bomb[10][10]; //記錄是否走過
int xx=0,yy=0; //目前位置
int tt=1; //第幾步
int dire=1;
int pop[300][3]; //記錄走過的路
int movx[9]={2,1,-1,-2, 1, 2,-1,-2}; //8個方向
int movy[9]={1,2,-2,-1,-2,-1, 2, 1}; //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void walk(int x,int y){ //走下一步
box1[x][y]->Caption=IntToStr(tt);
bomb[x][y]=1;
xx=x;yy=y;
dire=1;
} void kgoback(){ //退回一步
box1[xx][yy]->Caption="";
bomb[xx][yy]=0;
tt--;
xx=pop[tt][1];
yy=pop[tt][2];
dire=pop[tt][0] 1;
if(dire>8)dire=1;
} void __fastcall TForm1::FormCreate(TObject *Sender)
{
for(int i=0;i<5;i ){
for(int j=0;j<5;j ){
box1[i][j]=new TPanel(this);
box1[i][j]->Parent=Form1;
box1[i][j]->Width=20;
box1[i][j]->Height=20;
box1[i][j]->Left=box1[i][j]->Width*j;
box1[i][j]->Top=box1[i][j]->Height*i;
box1[i][j]->Show();
}
}
Form1->Width=box1[0][0]->Width*5 2;
Form1->Height=box1[0][0]->Height*6 2;
box1[xx][yy]->Caption=IntToStr(tt);
bomb[xx][yy]=tt;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::tt1Timer(TObject *Sender)
{
if(tt>=25){tt1->Enabled=false;return;}
for(int i=dire;i<=8;i ){
if((xx movx[i])>4)continue;
if((xx movx[i])<0)continue;
if((yy movy[i])>4)continue;
if((yy movy[i])<0)continue;
if(bomb[xx movx[i]][yy movy[i]]==1)continue;
pop[tt][0]=i;
pop[tt][1]=xx;
pop[tt][2]=yy;
tt ;
walk(xx movx[i],yy movy[i]);
return;
}
kgoback();
}
//---------------------------------------------------------------------------
------
KUSO 無處不在