unit R35; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TRei35 = class(TForm) Button1: TButton; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } procedure MkMaze; procedure MdMov(n1,n2,m1,m2:Byte;Mdpon:array of Byte); procedure DiMaze; public { Public declarations } end; const Mwidth = 25 * 16 + 32; //规定的16*16的方块,25*19个, Mheight = 19 * 16 + 32; var Rei35: TRei35; MakeBmap : TBitmap; RectD : TRect; St,n : Byte; Mdata : array[0..24,0..18] of Byte; //25*19 的数组 , Md011 : array[0..6 * 6 - 1] of Byte = ( //分为12格,预设的数据,这个得预先设置好 6*6方块 0,0,0,0,0,0, 0,1,0,1,0,1, 0,1,0,1,0,1, //编号XX + 变化X 0,1,0,1,0,1, 0,1,0,0,0,1, 0,1,1,1,1,1); Md012 : array[0..6 * 6 - 1] of Byte = ( 0,0,0,0,0,0, 0,1,1,1,1,1, 0,1,0,0,0,0, 0,1,0,1,1,1, 0,0,0,0,0,1, 0,1,1,1,1,1); Md013 : array[0..6 * 6 - 1] of Byte = ( //3种变化,对应数据 0,0,0,0,0,1, 0,1,1,1,1,1, 0,1,0,0,0,1, 1,1,1,1,0,1, 0,0,0,0,0,1, 1,1,1,1,0,1); Md021 : array[0..6 * 6 - 1] of Byte = ( 0,0,0,0,0,0, 1,1,1,1,0,1, 0,0,0,0,0,1, 1,1,1,1,0,1, 0,0,0,0,0,0, 0,1,1,1,1,1); Md022 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,0,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,0,0,1,0,0, 1,1,0,1,0,1); Md023 : array[0..6 * 6 - 1] of Byte = ( 0,0,0,0,0,1, 0,1,1,1,1,1, 0,1,0,0,0,1, 1,1,1,1,0,1, 0,0,0,1,0,0, 1,1,1,1,0,1); Md031 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,0,0,0, 0,1,0,1,1,1, 0,0,0,0,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 1,1,0,1,0,1); Md032 : array[0..6 * 6 - 1] of Byte = ( 0,0,0,0,0,0, 0,1,1,1,0,1, 0,0,0,0,0,1, 1,1,0,1,1,1, 0,0,0,0,0,1, 1,1,1,1,0,1); Md033 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,1,0,1, 0,1,0,1,0,1, 0,0,0,0,0,1, 0,1,1,1,1,1, 0,0,0,0,0,0, 1,1,0,1,1,1); Md041 : array[0..7 * 6 - 1] of Byte = ( //7*6方块 0,1,0,0,0,0,0, 0,1,0,1,1,1,0, 0,1,0,1,0,0,0, 0,1,0,1,1,1,1, 0,0,0,0,0,0,0, 1,1,0,1,1,1,0); Md042 : array[0..7 * 6 - 1] of Byte = ( 0,0,0,0,0,0,0, 1,1,1,1,1,1,0, 0,1,0,0,0,1,0, 0,1,0,1,0,1,0, 0,0,0,1,0,0,0, 0,1,1,1,1,1,0); Md043 : array[0..7 * 6 - 1] of Byte = ( 0,1,0,0,0,0,0, 0,1,0,1,1,1,1, 0,1,0,0,0,0,0, 0,1,1,1,1,1,0, 0,0,0,0,0,0,0, 0,1,1,1,0,1,1); Md051 : array[0..7 * 6 - 1] of Byte = ( 0,1,0,0,0,1,0, 0,1,0,1,0,1,0, 0,1,0,1,0,1,0, 0,1,0,1,0,1,0, 0,0,0,1,0,0,0, 0,1,1,1,1,1,0); Md052 : array[0..7 * 6 - 1] of Byte = ( 0,1,0,0,0,0,0, 0,1,0,1,1,1,1, 0,1,0,0,0,0,0, 0,1,1,1,1,1,0, 0,0,0,0,0,0,0, 0,1,1,1,0,1,1); Md053 : array[0..7 * 6 - 1] of Byte = ( 0,1,0,0,0,1,0, 0,1,0,1,0,1,0, 0,1,0,1,0,1,0, 0,1,1,1,1,1,0, 0,0,0,0,0,0,0, 0,1,1,1,0,1,1); Md061 : array[0..7 * 7 - 1] of Byte = ( //7*7方块 0,0,0,1,0,1,0, 1,1,0,1,0,1,0, 0,0,0,1,0,0,0, 0,1,1,1,1,1,1, 0,0,0,0,0,0,0, 1,1,1,1,1,1,0, 0,0,0,0,0,0,0); Md062 : array[0..7 * 7 - 1] of Byte = ( 0,1,0,0,0,0,0, 0,1,1,1,1,1,0, 0,0,0,0,0,1,0, 1,1,1,1,0,1,0, 0,0,0,0,0,1,0, 0,1,1,1,1,1,0, 0,1,0,0,0,0,0); Md063 : array[0..7 * 7 - 1] of Byte = ( 1,1,0,1,0,1,0, 0,1,1,1,1,1,0, 0,0,0,0,0,1,0, 1,1,1,1,0,1,0, 0,0,0,0,0,1,0, 1,1,0,1,0,1,0, 0,1,0,0,0,0,0); Md071 : array[0..6 * 7 - 1] of Byte = ( 0,1,0,0,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,0,0,1,0,0); Md072 : array[0..6 * 7 - 1] of Byte = ( 0,0,0,0,0,1, 0,1,1,1,1,1, 0,0,0,0,0,1, 1,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,0,0,1,0,0); Md073 : array[0..6 * 7 - 1] of Byte = ( 0,0,0,1,0,1, 0,1,1,1,0,1, 0,0,0,0,0,1, 1,1,1,1,0,1, 0,0,0,0,0,1, 1,1,1,0,1,1, 0,0,0,0,0,0); Md081 : array[0..6 * 7 - 1] of Byte = ( 0,0,0,0,0,0, 0,1,1,1,0,1, 0,0,0,1,0,1, 1,1,0,1,1,1, 0,0,0,0,0,1, 1,1,1,1,0,1, 0,0,0,0,0,1); Md082 : array[0..6 * 7 - 1] of Byte = ( 0,0,0,0,0,0, 0,1,0,1,1,1, 0,1,0,0,0,1, 1,1,1,1,0,1, 0,0,0,1,0,1, 0,1,0,1,0,1, 0,1,0,0,0,1); Md083 : array[0..6 * 7 - 1] of Byte = ( 0,1,0,0,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,0,0,1,0,0); Md091 : array[0..6 * 7 - 1] of Byte = ( 0,0,0,0,0,1, 0,1,1,1,1,1, 0,1,0,0,0,1, 0,1,1,1,0,1, 0,0,0,0,0,1, 0,1,1,1,1,1, 0,0,0,0,0,0); Md092 : array[0..6 * 7 - 1] of Byte = ( 0,0,0,1,0,1, 0,1,1,1,0,1, 0,0,0,0,0,1, 1,1,1,1,0,1, 0,0,0,0,0,1, 1,1,1,0,1,1, 0,0,0,0,0,0); Md093 : array[0..6 * 7 - 1] of Byte = ( 0,0,0,0,0,0, 0,1,0,1,1,1, 0,1,0,0,0,1, 1,1,1,1,0,1, 0,0,0,1,0,1, 0,1,0,1,0,1, 0,1,0,0,0,1); Md101 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,0,0,0, 0,1,0,1,1,1, 0,1,0,1,0,1, 1,1,0,1,0,1, 0,0,0,1,0,1, 0,1,1,1,0,1); Md102 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,1,0,0, 0,1,0,1,0,1, 0,0,0,1,0,1, 1,1,0,1,0,1, 0,0,0,0,0,1, 0,1,1,1,0,1); Md103 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,1,1,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 1,1,0,1,0,1, 0,1,0,1,1,1, 1,1,1,1,1,1); Md111 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,1,0,1, 0,1,0,1,0,1, 0,0,0,0,0,1, 0,1,1,1,1,1, 0,0,0,0,0,0, 1,1,0,1,1,1); Md112 : array[0..6 * 6 - 1] of Byte = ( 0,0,0,0,0,1, 0,1,0,1,1,1, 0,1,0,0,0,1, 0,1,1,1,0,1, 0,1,0,0,0,0, 1,1,1,1,1,1); Md113 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,0,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1); Md121 : array[0..6 * 6 - 1] of Byte = ( 0,0,0,0,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 1,1,0,1,0,1, 0,0,0,0,0,1, 1,1,1,1,1,1); Md122 : array[0..6 * 6 - 1] of Byte = ( 0,0,0,0,0,1, 0,1,1,1,1,1, 0,1,0,0,0,1, 1,1,1,1,0,1, 0,0,0,0,0,1, 1,1,1,1,0,1); Md123 : array[0..6 * 6 - 1] of Byte = ( 0,1,0,1,0,1, 0,1,0,1,1,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 0,1,0,1,0,1, 1,1,0,1,0,1); implementation {$R *.dfm} procedure TRei35.FormCreate(Sender: TObject); begin Rei35.Canvas.CopyMode := cmSrcCopy; MakeBmap := TBitmap.Create; //少写这句程序可以编译出来,但是运行显示错误 MakeBmap.Width := Mwidth; MakeBmap.Height := Mheight; St := 1; Randomize; end; procedure TRei35.MkMaze; begin //12格随机选择图案 case Random(3) of //3种变化 0: MdMov(0,5,0,5,md011); 1: MdMov(0,5,0,5,md012); 2: MdMov(0,5,0,5,md013); end; case Random(3) of 0: MdMov(6,11,0,5,Md021); 1: MdMov(6,11,0,5,Md022); 2: MdMov(6,11,0,5,Md023); end; case Random(3) of 0: MdMov(12,17,0,5,Md031); 1: MdMov(12,17,0,5,Md032); 2: MdMov(12,17,0,5,Md033); end; case Random(3) of 0: MdMov(18,24,0,5,Md041); 1: MdMov(18,24,0,5,Md042); 2: MdMov(18,24,0,5,Md043); end; case Random(3) of 0: MdMov(18,24,6,11,Md051); 1: MdMov(18,24,6,11,Md052); 2: MdMov(18,24,6,11,Md053); end; case Random(3) of 0: MdMov(18,24,12,18,Md061); 1: MdMov(18,24,12,18,Md062); 2: MdMov(18,24,12,18,Md063); end; case Random(3) of 0: MdMov(12,17,12,18,Md071); 1: MdMov(12,17,12,18,Md072); 2: MdMov(12,17,12,18,Md073); end; case Random(3) of 0: MdMov(6,11,12,18,Md081); 1: MdMov(6,11,12,18,Md082); 2: MdMov(6,11,12,18,Md083); end; case Random(3) of 0: MdMov(0,5,12,18,Md091); 1: MdMov(0,5,12,18,Md092); 2: MdMov(0,5,12,18,Md093); end; case Random(3) of 0: MdMov(0,5,6,11,Md101); 1: MdMov(0,5,6,11,Md102); 2: MdMov(0,5,6,11,Md103); end; case Random(3) of 0: MdMov(6,11,6,11,Md111); 1: MdMov(6,11,6,11,Md112); 2: MdMov(6,11,6,11,Md113); end; case Random(3) of 0: MdMov(12,17,6,11,Md121); 1: MdMov(12,17,6,11,Md122); 2: MdMov(12,17,6,11,Md123); end; end; procedure TRei35.MdMov(n1,n2,m1,m2:Byte;Mdpon:array of Byte); var x,y : Byte; begin n := 0; for y := m1 to m2 do //m1,m2 对应12大格Y格标 for x := n1 to n2 do //n1,n1对饮12格的X坐标 begin Mdata[x,y] := Mdpon[n]; //搬运 预设数据 n := n + 1; end; end; procedure TRei35.DiMaze; var x,y : Byte; begin for x := 0 to 24 do //根据数据画出 16*16的黑格 for y := 0 to 18 do begin if Mdata[x,y] = 0 then MakeBmap.Canvas.Brush.Color := clBlack else MakeBmap.Canvas.Brush.Color := clOlive; RectD := Rect(x * 16 + 16,y * 16 + 16,x * 16 + 32,y * 16 + 32); //RectD := Rect(x * 16 + 0,y * 16 + 0,x * 16 + 16,y * 16 + 16); //0,0坐标绘制 MakeBmap.Canvas.FillRect(RectD); end; end; procedure TRei35.Timer1Timer(Sender: TObject); begin case St of 1:begin //画面初始化 MakeBmap.Canvas.Brush.Color := clOlive; //刷褐色 ,大一圈,形成边界图案 RectD := Rect(0,0,Mwidth,Mheight); MakeBmap.Canvas.FillRect(RectD); MakeBmap.Canvas.Brush.Color := clBlack; //刷黑色, RectD := Rect(16,16,Mwidth - 32,Mheight - 32); MakeBmap.Canvas.FillRect(RectD); Rei35.Canvas.Draw(0,0,MakeBmap); //将制作好的图案画到界面上 St := 2; end; 2:begin MkMaze; //将制作好的图案画到界面上 DiMaze; Rei35.Canvas.Draw(0,0,MakeBmap); St := 0; //绘制完成进入状态0, end; end; end; procedure TRei35.Button1Click(Sender: TObject); begin St := 2; end; procedure TRei35.FormClose(Sender: TObject; var Action: TCloseAction); begin MakeBmap.Free; end; end.
标签:12,end,..,Delphi,array,35,40,MdMov,Byte From: https://www.cnblogs.com/D7mir/p/16826120.html