Данный код висит на FormClick.
Код:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.ExtCtrls, Vcl.StdCtrls,
FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf,
FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
FireDAC.Phys, FireDAC.Phys.MySQL, FireDAC.Phys.MySQLDef, FireDAC.Stan.Param,
FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, Vcl.Grids, Vcl.DBGrids;
type
TForm1 = class(TForm)
PopupMenu1: TPopupMenu;
Timer1: TTimer;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N21: TMenuItem;
N31: TMenuItem;
N41: TMenuItem;
N51: TMenuItem;
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure NewGame;
procedure DropBlock;
procedure DelVoid;
procedure N2Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Timer1Timer(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N21Click(Sender: TObject);
procedure N41Click(Sender: TObject);
procedure N51Click(Sender: TObject);
procedure N31Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MainArray:array[0..100,0..100] of byte;
SecArray : array[0..100,0..100] of byte;
BPic1,BPic2,BPic3,BPic4,BPic5:TBitmap;
count,colors,s,m,point:integer;
implementation
{$R *.dfm}
uses Unit2;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; //ПРОВЕРЯЕМ ЕСЛИ ЛИ КУБИКИ ОДНОГО ЦВЕТА СЛЕВА, СПРАВА, СНИЗУ И СВЕРХУ, ЕСЛИ ЕСТЬ-УНИЧТОЖАЕМ КУЧУ.
Shift: TShiftState; X, Y: Integer);
var item : byte;
i, j, k: Integer;
ending : boolean;
begin
p:=0;
item := MainArray[X div 24,Y div 24];
m := 1;
ending := False;
for i := 0 to Count do
for j := 0 to Count do
SecArray[i,j] := 0;
if MainArray[X div 24,Y div 24] <> 0 Then
begin
SecArray[X div 24,Y div 24] := 1;
While ending <> True do
begin
k := 0;
for i := Count downto 0 do
for j := Count downto 0 do
if (SecArray[i,j] = 1) Then
begin
if (MainArray[i-1,j] = item)and(SecArray[i-1,j] = 0) Then
begin SecArray[i-1,j] := 1; k := k+1; m := m+1; end;
if (MainArray[i+1,j] = item)and(SecArray[i+1,j] = 0) Then
begin SecArray[i+1,j] := 1; k := k+1; m := m+1; end;
if (MainArray[i,j-1] = item)and(SecArray[i,j-1] = 0) Then
begin SecArray[i,j-1] := 1; k := k+1; m := m+1; end;
if (MainArray[i,j+1] = item)and(SecArray[i,j+1] = 0) Then
begin SecArray[i,j+1] := 1; k := k+1; m := m+1; end;
end;
if k = 0 Then ending := True;
end;
if m > 1 Then
for i := 0 to Count do
for j := 0 to Count do
if SecArray[i,j] = 1 Then MainArray[i,j] := 0;
end;
end;
procedure TForm1.FormPaint(Sender: TObject); /// ЗАПОЛНЯЕМ ФОРМУ КУБИКАМИ
var i,j:integer;
begin
for i:=0 to count do
for j:=0 to count do
if MainArray[i,j]<>0 then
case MainArray[i,j] of
1:Canvas.Draw(i*24,j*24,BPic1);
2:Canvas.Draw(i*24,j*24,BPic2);
3:Canvas.Draw(i*24,j*24,BPic3);
4:Canvas.Draw(i*24,j*24,BPic4);
5:Canvas.Draw(i*24,j*24,BPic5);
end;
DropBlock;
DelVoid;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
label2.Caption:=form2.fdquery1.FieldByName('nickname').Asstring // ОТОБРАЖАЕМ НИК ИГРОКА В ЛЭЙБЛЕ
end;
procedure TForm1.N21Click(Sender: TObject);
begin
colors:=2;
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
NewGame;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
NewGame;
end;
procedure TForm1.N31Click(Sender: TObject);
begin
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
colors:=3;
NewGame;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
form2.Close;
close;
end;
procedure TForm1.N41Click(Sender: TObject);
begin
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
colors:=4;
NewGame;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
NewGame;
end;
procedure TForm1.N51Click(Sender: TObject);
begin
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
colors:=5;
NewGame;
end;
procedure TForm1.NewGame; /// НОВАЯ ИГРА
var i,j:integer;
begin
randomize;
for i:=0 to count do
for j:=0 to count do
MainArray[i,j]:= random(colors)+1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Refresh;
end;
procedure TForm1.DropBlock ; ///УНИЧТОЖАЕМ КУБИКИ
var i,j:integer;
begin
for i := 0 to count do
for j := count downto 1 do
if MainArray[i,j]=0 then
begin
MainArray[i,j]:= MainArray[i,j-1];
MainArray[i,j-1]:=0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.Show;
form1.hide;
NewGame;
s:=0;
Label1.Caption := 'Очки:'+inttostr(s);
end;
procedure TForm1.DelVoid; //// СДВИГАЕМ КУБИКИ
var
i,j,k:integer;
begin
for i :=0 to count-1 do
begin
k:=0;
for j := 0 to count do
k:=k+MainArray[i,j];
if k=0 then
for j := 0 to count do
begin
MainArray[i,j]:= MainArray[i+1,j] ;
MainArray[i+1,j]:=0;
end;
end;
end;
procedure TForm1.FormClick(Sender: TObject);
begin
if m=1 then point:=-2000 ////////ПОДСЧЕТ ОЧКОВ
else
if (m>1) and (m<42) then point:=m*100;
s:=s+point;
Label1.Caption := 'Очки:'+inttostr(s);
form2.fdquery3.sql.text:='update test1 set records=:s where nickname=:f and records<:s '; ///ЗАНОСИМ МАКСИМАЛЬНЫЙ РЕКОРД В СТОЛБЕЦ
form2.fdquery3.parambyname('s').asInteger:=s;
form2.fdquery3.parambyname('f').asString:=form2.fdquery1.FieldByName('nickname').Asstring;
form2.fdquery3.Execute;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Halt;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
point:=0;
s:=0;
DoubleBuffered := True;
count:=20;
Width:= 24*(count+1)+5;
Height:= 24*(count+1)+90;
color:=clblack;
colors:=3;
BPic1:=TBitmap.Create;
BPic1.LoadFromFile('red.bmp');
BPic2:=TBitmap.Create;
BPic2.LoadFromFile('blue.bmp');
BPic3:=TBitmap.Create;
BPic3.LoadFromFile('yellow.bmp');
BPic4:=TBitmap.Create;
BPic4.LoadFromFile('green.bmp');
BPic5:=TBitmap.Create;
BPic5.LoadFromFile('purple.bmp');
NewGame;
end;
end.