//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "stdio.h" #include "math.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int x1=3, y1=3; int x2, y2; int a[20][20]; int b[20][20]; int c[20][20]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { for(int i=0;i<20;i++) { for(int j=0;j<20;j++) { switch(a[i][j]) { case 0 : Form1->Canvas->Brush->Color=clGreen; break; case 1 : Form1->Canvas->Brush->Color=clRed; break; case 2 : Form1->Canvas->Brush->Color=clYellow; break; } Form1->Canvas->Rectangle(i*30,j*30,i*30+30,j*30+30); // 30 = размер клетки в пикселях } } Form1->Canvas->Ellipse(x1*30,y1*30,x1*30+30,y1*30+30); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { FILE *f; f=fopen("C:\\111.txt","r"); if(f) { for(int i=0;i<20;i++) { for(int j=0;j<21;j++) // на единицу больше из-за символа конца строки { char t=fgetc(f); switch(t) { case 48 : a[i][j]=0; break; case 49 : a[i][j]=1; break; } } } } Button4Click(Sender); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Timer1->Enabled=true; if(Button==mbRight) { x2=int(X/30); y2=int(Y/30); } Button4Click(Sender); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { for(int i=0;i<20;i++) { for(int j=0;j<20;j++) { b[i][j]=0; c[i][j]=0; if(a[i][j]==1) b[i][j]=200; } } b[x1][y1]=1; /****************** СОЗДАНИЕ КАРТЫ ПОТЕНЦИАЛОВ *****************************/ for(int k=0;k<40;k++) { for(int i=0;i<20;i++) { for(int j=0;j<20;j++) { if(b[i][j]==0 && b[i+1][j]==k+1 && i+1<20 && a[i][j]==0) { b[i][j]=k+2;} if(b[i][j]==0 && b[i-1][j]==k+1 && i-1>0 && a[i][j]==0) { b[i][j]=k+2;} if(b[i][j]==0 && b[i][j+1]==k+1 && j+1<20 && a[i][j]==0) { b[i][j]=k+2;} if(b[i][j]==0 && b[i][j-1]==k+1 && j-1>0 && a[i][j]==0) { b[i][j]=k+2;} } } } /***************************************************************************/ int x3=x2; int y3=y2; for(int i=0;iEnabled=!Timer1->Enabled; } //---------------------------------------------------------------------------