嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
用Delphi 11开发的多设备游戏,可在Window和安卓手机上运行
unit NotesMain;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,System.Rtti, System.Actions, FMX.ActnList,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.TabControl,
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts, FMX.ListBox, FMX.Objects,
FMX.Edit;
type
TMainForm = class(TForm)
TabControl1: TTabControl;
TabItemWelcome: TTabItem;
TabItemPlay: TTabItem;
Label1: TLabel;
Label2: TLabel;
ButtonStart: TButton;
Label3: TLabel;
ListBox1: TListBox;
ButtonRestart: TButton;
StyleBook1: TStyleBook;
Image1: TImage;
Image2: TImage;
procedure ButtonStartClick(Sender: TObject);
procedure ButtonRestartClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure AddItem();
procedure DoSButtonOKClick(Sender: TObject);
procedure DoComboBox1OnChange(Sender: TObject);
procedure DoComboBox2OnChange(Sender: TObject);
procedure DoComboBox3OnChange(Sender: TObject);
procedure DoComboBox4OnChange(Sender: TObject);
procedure GenarateNotes();
procedure ResetCT();
procedure AjustR2();
procedure SetCQ();
public
{ Public declarations }
end;
var
MainForm: TMainForm;
n1,n2,n3,n4,c1,c2,c3,c4,r1,r2,ct1,ct2,ct3,ct4,cq1,cq2,cq3,cq4,cqa1,cqa2,cqa3,cqa4,cb1,cb2,cb3,cb4,step:integer;
implementation
uses
{$IFDEF ANDROID}
Androidapi.Helpers,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.Os,
{$ENDIF}
FMX.DialogService;
{$R *.fmx}
function FindItemParent(Obj: TFmxObject; ParentClass: TClass): TFmxObject;
begin
Result := nil;
if Assigned(Obj.Parent) then
if Obj.Parent.ClassType = ParentClass then
Result := Obj.Parent
else
Result := FindItemParent(Obj.Parent, ParentClass);
end;
procedure TMainForm.GenarateNotes();
begin
n1:=random(6) 1;
n2:=random(6) 1;
n3:=random(6) 1;
n4:=random(6) 1;
step:=0;
end;
procedure TMainForm.ResetCT();
begin
ct1:=0;
ct2:=0;
ct3:=0;
ct4:=0;
end;
procedure TMainForm.SetCQ();
begin
cq1:=1;
cq2:=1;
cq3:=1;
cq4:=1;
if c1=c2 then
cq1:=cq1 1;
if c1=c3 then
cq1:=cq1 1;
if c1=c4 then
cq1:=cq1 1;
if c2=c1 then
cq2:=cq2 1;
if c2=c3 then
cq2:=cq2 1;
if c2=c4 then
cq2:=cq2 1;
if c3=c1 then
cq3:=cq3 1;
if c3=c2 then
cq3:=cq3 1;
if c3=c4 then
cq3:=cq3 1;
if c4=c1 then
cq4:=cq4 1;
if c4=c2 then
cq4:=cq4 1;
if c4=c3 then
cq4:=cq4 1;
cqa1:=cq1;
cqa2:=cq2;
cqa3:=cq3;
cqa4:=cq4;
end;
procedure TMainForm.AjustR2();
begin
while ct1>cqa1 do
begin
ct1:=ct1-1;
r2:=r2-1;
end;
while ct2>cqa2 do
begin
ct2:=ct2-1;
r2:=r2-1;
end;
while ct3>cqa3 do
begin
ct3:=ct3-1;
r2:=r2-1;
end;
while ct4>cqa4 do
begin
ct4:=ct4-1;
r2:=r2-1;
end;
end;
procedure TMainForm.DoComboBox1OnChange(Sender: TObject);
var
Item : TListBoxItem;
begin
Item := TListBoxItem(FindItemParent(Sender as TFmxObject,TListBoxItem));
if Assigned(Item) then
begin
c1:=StrToInt(TComboBox(Sender).Selected.Text);
cb1:=1;
end;
end;
procedure TMainForm.DoComboBox2OnChange(Sender: TObject);
var
Item : TListBoxItem;
begin
Item := TListBoxItem(FindItemParent(Sender as TFmxObject,TListBoxItem));
if Assigned(Item) then
begin
c2:=StrToInt(TComboBox(Sender).Selected.Text);
cb2:=1;
end;
end;
procedure TMainForm.DoComboBox3OnChange(Sender: TObject);
var
Item : TListBoxItem;
begin
Item := TListBoxItem(FindItemParent(Sender as TFmxObject,TListBoxItem));
if Assigned(Item) then
begin
c3:=StrToInt(TComboBox(Sender).Selected.Text);
cb3:=1;
end;
end;
procedure TMainForm.DoComboBox4OnChange(Sender: TObject);
var
Item : TListBoxItem;
begin
Item := TListBoxItem(FindItemParent(Sender as TFmxObject,TListBoxItem));
if Assigned(Item) then
begin
c4:=StrToInt(TComboBox(Sender).Selected.Text);
cb4:=1;
end;
end;
procedure TMainForm.DoSButtonOKClick(Sender: TObject);
var
Item : TListBoxItem;
begin
if (cb1=1) and (cb2=1) and (cb3=1) and (cb4=1) then
begin
Item := TListBoxItem(FindItemParent(Sender as TFmxObject,TListBoxItem));
setcq;
if Assigned(Item) then
begin
if c1=n1 then //c1=n1
begin
r1:=r1 1;
if c2=n2 then //c1=n1 c2=n2
begin
r1:=r1 1;
if c3=n3 then //c1=n1 c2=n2 c3=n3
begin
r1:=r1 1;
if c4=n4 then //c1=n1 c2=n2 c3=n3 c4=n4
r1:=r1 1;
end;
if c3<>n3 then //c1=n1 c2=n2 c3<>n3
begin
if c4=n4 then //c1=n1 c2=n2 c3<>n3 c4=n4
r1:=r1 1;
if c4<>n4 then //c1=n1 c2=n2 c3<>n3 c4<>n4
begin
if c3=n4 then
r2:=r2 1;
if c4=n3 then
r2:=r2 1;
end;
end;
end;
if C2<>n2 then //c1=n1 c2<>n2
begin
if c3=n3 then //c1=n1 c2<>n2 c3=n3
begin
r1:=r1 1;
if c4=n4 then //c1=n1 c2<>n2 c3=n3 c4=n4
begin
r1:=r1 1;
end;
if c4<>n4 then //c1=n1 c2<>n2 c3=n3 c4<>n4
begin
if c2=n4 then
r2:=r2 1;
if c4=n2 then
r2:=r2 1;
end;
end;
if c3<>n3 then //c1=n1 c2<>n2 c3<>n3
begin
if c4=n4 then //c1=n1 c2<>n2 c3<>n3 c4=n4
begin
r1:=r1 1;
if (c2=n3) then
r2:=r2 1;
if c3=n2 then
r2:=r2 1;
end;
if c4<>n4 then //c1=n1 c2<>n2 c3<>n3 c4<>n4
begin
resetct;
if (c3=n2) or (c4=n2) then
begin
r2:=r2 1;
if c3=n2 then
ct3:=ct3 1;
if c4=n2 then
ct4:=ct4 1;
end;
if (c2=n3) or (c4=n3) then
begin
r2:=r2 1;
if c2=n3 then
ct2:=ct2 1;
if c4=n3 then
ct4:=ct4 1;
end;
if (c2=n4) or (c3=n4) then
begin
r2:=r2 1;
if c2=n4 then
ct2:=ct2 1;
if c3=n4 then
ct3:=ct3 1;
end;
if (c2=n1) and (cq2>1) then
cqa2:=1;
if (c3=n1) and (cq3>1) then
cqa3:=1;
if (c4=n1) and (cq4>1) then
cqa4:=1;
AjustR2;
end;
end;
end;
end;
if c1<>n1 then //c1<>n1
begin
if c2=n2 then //c1<>n1 c2=n2
begin
r1:=r1 1;
if c3=n3 then //c1<>n1 c2=n2 c3=n3
begin
r1:=r1 1;
if c4=n4 then //c1<>n1 c2=n2 c3=n3 c4=n4
begin
r1:=r1 1;
end;
if c4<>n4 then //c1<>n1 c2=n2 c3=n3 c4<>n4
if c1=n4 then
r2:=r2 1;
if (c4=n1) then
r2:=r2 1;
end;
if c3<>n3 then //c1<>n1 c2=n2 c3<>n3
begin
if c4=n4 then //c1<>n1 c2=n2 c3<>n3 c4=n4
begin
r1:=r1 1;
if (c1=n3) then
r2:=r2 1;
if c3=n1 then
r2:=r2 1;
end;
if c4<>n4 then //c1<>n1 c2=n2 c3<>n3 c4<>n4
begin
ResetCT;
if (c3=n1) or (c4=n1) then
begin
r2:=r2 1;
if c3=n1 then
ct3:=ct3 1;
if c4=n1 then
ct4:=ct4 1;
end;
if (c1=n3) or (c4=n3) then
begin
r2:=r2 1;
if c1=n3 then
ct1:=ct1 1;
if c4=n3 then
ct4:=ct4 1;
end;
if (c1=n4) or (c3=n4) then
begin
r2:=r2 1;
if c1=n4 then
ct1:=ct1 1;
if c3=n4 then
ct3:=ct3 1;
end;
if (c1=n2) and (cq1>1) then
cqa1:=1;
if (c3=n2) and (cq3>1) then
cqa3:=1;
if (c4=n2) and (cq4>1) then
cqa4:=1;
AjustR2;
end;
end;
end;
if c2<>n2 then //c1<>n1 c2<>n2
begin
if c3=n3 then //c1<>n1 c2<>n2 c3=n3
begin
r1:=r1 1;
if c4=n4 then //c1<>n1 c2<>n2 c3=n3 c4=n4
begin
r1:=r1 1;
if c1=n2 then
r2:=r2 1;
if c2=n1 then
r2:=r2 1;
end;
if c4<>n4 then //c1<>n1 c2<>n2 c3=n3 c4<>n4
begin
resetCT;
if (c2=n1) or (c4=n1) then
begin
r2:=r2 1;
if c2=n1 then
ct2:=ct2 1;
if c4=n1 then
ct4:=ct4 1;
end;
if (c1=n2) or (c4=n2) then
begin
r2:=r2 1;
if c1=n2 then
ct1:=ct1 1;
if c4=n2 then
ct4:=ct4 1;
end;
if (c1=n4) or (c2=n4) then
begin
r2:=r2 1;
if c1=n4 then
ct1:=ct1 1;
if c2=n4 then
ct2:=ct2 1;
end;
if (c1=n3) and (cq1>1) then
cqa1:=1;
if (c2=n3) and (cq2>1) then
cqa3:=1;
if (c4=n3) and (cq4>1) then
cqa4:=1;
AjustR2;
end;
end;
if c3<>n3 then //c1<>n1 c2<>n2 c3<>n3
begin
if c4=n4 then //c1<>n1 c2<>n2 c3<>n3 c4=n4
begin
resetCT;
r1:=r1 1;
if (c2=n1) or (c3=n1) then
begin
r2:=r2 1;
if c2=n1 then
ct2:=ct2 1;
if c3=n1 then
ct3:=ct3 1;
end;
if (c1=n2) or (c3=n2) then
begin
r2:=r2 1;
if c1=n2 then
ct1:=ct1 1;
if c3=n2 then
ct3:=ct3 1;
end;
if (c1=n3) or (c2=n3) then
begin
r2:=r2 1;
if c1=n3 then
ct1:=ct1 1;
if c2=n3 then
ct2:=ct2 1;
end;
if (c1=n4) and (cq1>1) then
cqa1:=1;
if (c2=n4) and (cq2>1) then
cqa3:=1;
if (c3=n4) and (cq3>1) then
cqa3:=1;
AjustR2;
end;
if c4<>n4 then //c1<>n1 c2<>n2 c3<>n3 c4<>n4
begin
resetCT;
if (c2=n1) or (c3=n1) or (c4=n1) then
begin
r2:=r2 1;
if c2=n1 then
ct2:=ct2 1;
if c3=n1 then
ct3:=ct3 1;
if c4=n1 then
ct4:=ct4 1;
end;
if (c1=n2) or (c3=n2) or (c4=n2) then
begin
r2:=r2 1;
if c1=n2 then
ct1:=ct1 1;
if c3=n2 then
ct3:=ct3 1;
if c4=n2 then
ct4:=ct4 1;
end;
if (c1=n3) or (c2=n3) or (c4=n3) then
begin
r2:=r2 1;
if c1=n3 then
ct1:=ct1 1;
if c2=n3 then
ct2:=ct2 1;
if c4=n3 then
ct4:=ct4 1;
end;
if (c1=n4) or (c2=n4) or (c3=n4) then
begin
r2:=r2 1;
if c1=n4 then
ct1:=ct1 1;
if c2=n4 then
ct2:=ct2 1;
if c3=n4 then
ct3:=ct3 1;
end;
AjustR2;
end;
end;
end;
end;
if r1=4 then
begin
Item.StylesData['ImageItem1']:=Image1.Bitmap;
Item.StylesData['ImageItem2']:=Image1.Bitmap;
Item.StylesData['ImageItem3']:=Image1.Bitmap;
Item.StylesData['ImageItem4']:=Image1.Bitmap;
Item.Enabled:=false;
end
else
begin
if r1=3 then
begin
Item.StylesData['ImageItem1']:=Image1.Bitmap;
Item.StylesData['ImageItem2']:=Image1.Bitmap;
Item.StylesData['ImageItem3']:=Image1.Bitmap;
end;
if r1=2 then
begin
Item.StylesData['ImageItem1']:=Image1.Bitmap;
Item.StylesData['ImageItem2']:=Image1.Bitmap;
if r2=2 then
begin
Item.StylesData['ImageItem3']:=Image2.Bitmap;
Item.StylesData['ImageItem4']:=Image2.Bitmap;
end;
if r2=1 then
Item.StylesData['ImageItem3']:=Image2.Bitmap;
end;
if r1=1 then
begin
Item.StylesData['ImageItem1']:=Image1.Bitmap;
if r2=3 then
begin
Item.StylesData['ImageItem2']:=Image2.Bitmap;
Item.StylesData['ImageItem3']:=Image2.Bitmap;
Item.StylesData['ImageItem4']:=Image2.Bitmap;
end;
if r2=2 then
begin
Item.StylesData['ImageItem2']:=Image2.Bitmap;
Item.StylesData['ImageItem3']:=Image2.Bitmap;
end;
if r2=1 then
begin
Item.StylesData['ImageItem2']:=Image2.Bitmap;
end;
end;
if r1=0 then
begin
if r2=1 then
Item.StylesData['ImageItem1']:=Image2.Bitmap;
if r2=2 then
begin
Item.StylesData['ImageItem1']:=Image2.Bitmap;
Item.StylesData['ImageItem2']:=Image2.Bitmap;
end;
if r2=3 then
begin
Item.StylesData['ImageItem1']:=Image2.Bitmap;
Item.StylesData['ImageItem2']:=Image2.Bitmap;
Item.StylesData['ImageItem3']:=Image2.Bitmap;
end;
if r2=4 then
begin
Item.StylesData['ImageItem1']:=Image2.Bitmap;
Item.StylesData['ImageItem2']:=Image2.Bitmap;
Item.StylesData['ImageItem3']:=Image2.Bitmap;
Item.StylesData['ImageItem4']:=Image2.Bitmap;
end;
end;
Item.Enabled:=false;
if step>9 then
TDialogService.ShowMessage('尝试次数过多,还是重新开始吧。')
else
AddItem;
end;
end;
end;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ListBox1.Free;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
TabItemPlay.Visible:=false;
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
TabControl1.ActiveTab:= TabItemWelcome;
end;
procedure TMainForm.AddItem();
var
Item : TListBoxItem;
begin
r1:=0;
r2:=0;
Item:=TListBoxItem.Create(nil);
Item.Parent:=ListBox1;
Item.StyleLookup:='CustomItem';
Item.StylesData['ImageItem1']:=nil;
Item.StylesData['ImageItem2']:=nil;
Item.StylesData['ImageItem3']:=nil;
Item.StylesData['ImageItem4']:=nil;
Item.StylesData['ComboBox1.OnChange'] := TValue.From<TNotifyEvent>(DoComboBox1OnChange);
Item.StylesData['ComboBox2.OnChange'] := TValue.From<TNotifyEvent>(DoComboBox2OnChange);
Item.StylesData['ComboBox3.OnChange'] := TValue.From<TNotifyEvent>(DoComboBox3OnChange);
Item.StylesData['ComboBox4.OnChange'] := TValue.From<TNotifyEvent>(DoComboBox4OnChange);
Item.StylesData['SButtonOK.OnClick'] := TValue.From<TNotifyEvent>(DoSButtonOKClick);
cb1:=0;
cb2:=0;
cb3:=0;
cb4:=0;
Step:=Step 1;
end;
procedure TMainForm.ButtonRestartClick(Sender: TObject);
begin
ListBox1.Clear;
GenarateNotes;
AddItem;
end;
procedure TMainForm.ButtonStartClick(Sender: TObject);
begin
ListBox1.Clear;
GenarateNotes;
AddItem;
TabItemPlay.Visible:=true;
TabControl1.ActiveTab:=TabItemPlay;
TabItemWelcome.Visible:=false;
end;
end.