unit main; {* BINGO_Draw version 0.1.0.0 CopyRight hironori KANEMITSU 2000/03/17 ビンゴゲームの番号を抽選するためのソフトです。 *} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls; type TForm1 = class(TForm) Button1: TButton; Timer1: TTimer; ListBox1: TListBox; Button2: TButton; Image1: TImage; Button3: TButton; StatusBar1: TStatusBar; Label1: TLabel; Edit1: TEdit; Label2: TLabel; Edit2: TEdit; Button4: TButton; Label3: TLabel; Edit3: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private 宣言 } public { Public 宣言 } procedure DrawBack; procedure DrawBalls(aFig : integer); procedure DrawGrowingBall; procedure Draw_aFig(aFig : integer); procedure mCircle(aX, aY, aR : integer; aColor : TColor; aFig : integer); procedure nCircle(X0, Y0, aR : integer; aColor : TColor); function CheckNoSame(aFig : integer) : boolean; end; procedure myDelay(aSec, aMSec : word); var Form1: TForm1; gBallNum : integer; gFig : integer; gBallColor : integer; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); {* ビンゴ数字抽選 *} var aFig : integer; noSame : boolean; begin {* clickの度に乱数を初期化する *} Randomize; {* intervalを設定 *} Timer1.Interval := 200; {* Timerの状態で分岐*} if Timer1.Enabled then begin Timer1.Enabled := False; noSame := False; while noSame = False and (ListBox1.Items.Count < gFig) do begin {* 1からgFigまでの数字を作成 *} aFig := Random(gFig)+1; {* ListBox1の数字と同じかどうか調べる *} noSame := CheckNoSame(aFig); {* 同じでない場合に処理を進める *} if noSame then begin DrawBack; DrawGrowingBall; Draw_aFig(aFig); ListBox1.Items.Append(IntToStr(aFig)); StatusBar1.Panels[0].Text := IntToStr(ListBox1.Items.Count); end; end; {* ボールがgFig個になったらボタンをunableにする *} if ListBox1.Items.Count >= gFig then Button1.Enabled := False; end else Timer1.Enabled := True; end; procedure TForm1.FormCreate(Sender: TObject); {* 初期設定 *} begin gBallNum := 24; gFig := 24; gBallColor := $000000ff; Edit1.Text := IntToStr(24); Edit2.Text := IntToStr(24); Edit3.Text := IntToStr($000000ff); Timer1.Enabled := False; Form1.Width := 207; Button2.Caption := '>>'; StatusBar1.Panels[0].Text := '0'; StatusBar1.Panels[1].Text := 'CopyRight hironori'; end; procedure TForm1.Timer1Timer(Sender: TObject); {* Timer処理*} begin {* 背景を表示 *} DrawBack; {* 24個のボールを表示 *} DrawBalls(gBallNum); end; procedure TForm1.mCircle(aX, aY, aR : integer; aColor : TColor ; aFig : integer); begin with Image1.Canvas do begin {* 直径aRの円を描く *} Pen.Color := clBlack; Brush.Color := aColor; Ellipse(aX, aY, aX+aR, aY+aR); {* 円の中にaFigを表示する *} Font.Size := aR div 2; Font.Color := clWhite; {* 桁数処理 *} if aFig >= 10 then {* TextOutの始点を計算 *} TextOut(aX+(aR div 5), aY+(aR div 6), IntToStr(aFig)) else TextOut(aX+(aR div 5), aY+(aR div 6), IntToStr(0)+IntToStr(aFig)); end; end; procedure myDelay(aSec, aMSec : word); {* Delay処理 *} var TimeOut : TDateTime; begin TimeOut := Now + EncodeTime(0, aSec div 60, aSec mod 60, aMSec); while Now < TimeOut do Application.ProcessMessages; end; procedure TForm1.DrawBack; {* Image1をclGreenで塗りつぶす *} begin with Image1.Canvas do begin Brush.Color := clGreen; FillRect(Rect(0,0,Image1.Width, Image1.Height)); end; end; procedure TForm1.DrawBalls(aFig : integer); {* 中心にaFigがclWhiteで表示されるボールを描く。 *} var i : integer; aX : integer; aY : integer; aR : integer; begin {* 円をaFig個描く *} for i:=1 to aFig do begin {* 円の直径を20から29までRandomに変化させる *} aR := Random(10) + 20; {* 円の描画始点をImage1の範囲内でRandomに変化させる*} aX := Random(Image1.Width-aR); aY := Random(Image1.Height-aR); {* 1からaFigまでの数字をRandomに表示する円を描く *} mCircle(aX, aY, aR, gBallColor ,Random(aFig)+1); end; end; procedure TForm1.nCircle(X0, Y0, aR : integer; aColor : TColor); {* 中心の座標が[X0,Y0]で直径がaRの円を描く。 *} var aR2 : integer; begin aR2 := aR div 2; with Image1.Canvas do begin Pen.Color := gBallColor; Brush.Color := aColor; Ellipse(X0-aR2, Y0-aR2, X0+aR2, Y0+aR2); end; end; procedure TForm1.DrawGrowingBall; {* 半径を変化させることでだんだん大きくなる円を描きます。 *} var i : integer; begin for i:=1 to 8 do begin {* 円の中心はImage1の中心*} {* 直径が1*20から8*20まで変化する *} nCircle(Image1.Width div 2, Image1.Height div 2, i*20, gBallColor); {* delayを200msecに設定 *} myDelay(0,200); end; end; procedure TForm1.Draw_aFig(aFig : integer); {* 数字aFigを表示します。 *} begin with Image1.Canvas do begin Font.Color := clWhite; {* Fontの高さをImage1の高さの半分として *} Font.Height := Image1.Height div 2; {* 桁数を処理 *} if aFig >= 10 then {* TextOutの始点は、Image1の長さの4分の1になる *} TextOut(Image1.Width div 4, image1.Height div 4 ,IntToStr(aFig)) else TextOut(Image1.Width div 4, image1.Height div 4 ,IntToStr(0)+IntToStr(aFig)) end; end; procedure TForm1.Button2Click(Sender: TObject); {* [>>]/[<<]ボタンをクリックすると表示が変化します。 *} begin {* クリック前のForm1の状態により処理を分岐 *} if Form1.Width = 360 then begin Form1.Width := 207; Button2.Caption := '>>'; end else begin Form1.Width := 360; Button2.Caption := '<<'; end; end; function TForm1.CheckNoSame(aFig : integer) : boolean; {* aFigがListBox1の数字と同じかどうか調べます。 aFigが同じでなければ、TRUEを返します。 *} var i : integer; begin {* ListBox1の要素が0の場合の処理 *} if ListBox1.Items.Count = 0 then Result := True; {* ListBox1の要素が1以上の場合の処理 *} for i:=0 to ListBox1.Items.Count-1 do begin if IntToStr(aFig) = ListBox1.Items.Strings[i] then begin Result := False; Break; end else Result := True; end; end; procedure TForm1.Button3Click(Sender: TObject); {* Reset処理。 *} begin ListBox1.Clear; DrawBack; StatusBar1.Panels[0].Text := '0'; Button1.Enabled := True; end; procedure TForm1.Button4Click(Sender: TObject); begin gFig := StrToInt(Edit1.Text); gBallNum := StrToInt(Edit2.Text); gBallColor := StrToInt(Edit3.Text); end; end.