unit DottiMainUnit; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ImgList, Buttons,MMSystem, StdCtrls; type TDottiMainForm = class(TForm) ImageList: TImageList; ComPanel1: TPanel; MyPanel1: TPanel; ComPanel2: TPanel; MyPanel2: TPanel; ComPanel3: TPanel; MyPanel3: TPanel; DohyouPanel: TPanel; ComSpBtn0: TSpeedButton; ComSpBtn1: TSpeedButton; ComSpBtn2: TSpeedButton; MyGooSpBtn: TSpeedButton; MyTiSpBtn: TSpeedButton; MyPaSpBtn: TSpeedButton; OptPanel: TPanel; StrongChBox: TCheckBox; procedure FormCreate(Sender: TObject); procedure SpClick(Sender: TObject); procedure DohyouPanelClick(Sender: TObject); procedure FormPaint(Sender: TObject); private { Private 宣言 } MyJan1,//こちらが出したその1 MyJan2,//こちらが出したその2 MyJan3:integer;//こちらが出したその3 ClickMe,YouWin,YouLost, IsDraw,Janken,Doch,Koch:string;//Wave ファイル名 procedure StartSpBtn;//ボタン位置や Caption 等の初期化 procedure Hantei;//勝ち負けの判定 //コンピュータの思考、というほどでもない(^^; function ComThink(My1,My2,Com1,Com2:integer):integer; public { Public 宣言 } end; var DottiMainForm: TDottiMainForm; implementation {$R *.DFM} procedure TDottiMainForm.FormCreate(Sender: TObject); var i:integer; Path:string; begin Randomize; Path:=ExtractFilePath(Application.ExeName); ClickMe:=Path+'ClickMe.wav'; YouWin:=Path+'YouWin.wav'; YouLost:=Path+'YouLost.wav'; IsDraw:=Path+'IsDraw.wav'; Janken:=Path+'Janken.wav'; Doch:=Path+'Doch.wav'; Koch:=Path+'Koch.wav'; Caption:=Application.Title; for i:=0 to ComponentCount-1 do if Components[i] is TSpeedButton then ImageList.GetBitmap( TSpeedButton(Components[i]).Tag,TSpeedButton(Components[i]).Glyph) else if Components[i] is TPanel then TPanel(Components[i]).Caption:=''; end; procedure TDottiMainForm.StartSpBtn; begin ComPanel1.Tag:=0; MyPanel1.Tag:=0;//1:片手 2:もう一つ 3:勝負 MyPanel2.Enabled:=False; MyPanel1.Enabled:=False; ComSpBtn0.Parent:=ComPanel1; ComSpBtn1.Parent:=ComPanel1; ComSpBtn2.Parent:=ComPanel1; MyGooSpBtn.Parent:=MyPanel1; MyTiSpBtn.Parent:=MyPanel1; MyPaSpBtn.Parent:=MyPanel1; DohyouPanel.Caption:='クリックしてね'; Refresh; if FileExists(ClickMe) then sndPlaySound(PChar(ClickMe),SND_SYNC); end; procedure TDottiMainForm.SpClick(Sender: TObject); var TmpI:integer; ComSpBtn:TSpeedButton; begin case MyPanel1.Tag of 0:begin (Sender as TSpeedButton).Parent:=MyPanel2;//移動 MyJan1:=(Sender as TSpeedButton).Tag;//ユーザの1手目を保存 ComSpBtn:=TSpeedButton(FindComponent('ComSpBtn'+ IntToStr(Random(3)))); ComSpBtn.Parent:=ComPanel2;//移動 ComPanel1.Tag:=ComSpBtn.Tag;//コンピュータの1手目を保存 end; 1:begin DohyouPanel.Caption:='どっちだすの ?'; (Sender as TSpeedButton).Parent:=MyPanel2; MyJan2:=(Sender as TSpeedButton).Tag;//2手目を保存 case ComPanel1.Tag of//コンピュータの2手目を決める 0:TmpI:=Random(2)+1; 1:begin TmpI:=Random(2); if TmpI=1 then TmpI:=2; end; else TmpI:=Random(2); end;//case TSpeedButton(FindComponent('ComSpBtn'+ IntToStr(TmpI))).Parent:=ComPanel2; ComPanel2.Tag:=TmpI;//コンピュータの2手目を保存 MyPanel1.Enabled:=False; MyPanel2.Enabled:=True; Refresh; Sleep(500); if FileExists(Doch) then sndPlaySound(PChar(Doch),SND_ASYNC); end; 2:begin DohyouPanel.Caption:='あ、こっち だすの'; (Sender as TSpeedButton).Parent:=MyPanel3; if StrongChBox.Checked then TmpI:=ComThink(MyJan1,MyJan2,ComPanel1.Tag,ComPanel2.Tag) else begin if Random(2)=0 then TmpI:=ComPanel1.Tag else TmpI:=ComPanel2.Tag; end; TSpeedButton(FindComponent('ComSpBtn'+ IntToStr(TmpI))).Parent:=ComPanel3; ComPanel3.Tag:=TmpI; MyJan3:=(Sender as TSpeedButton).Tag; MyPanel2.Enabled:=False; Refresh; Hantei; StartSpBtn; exit; end; end;//case MyPanel1.Tag := MyPanel1.Tag + 1; end; procedure TDottiMainForm.Hantei; var S,WaveName:string; Flg:Boolean; begin if FileExists(Koch) then sndPlaySound(PChar(Koch),SND_SYNC); if ComPanel3.Tag=MyJan3 then begin WaveName:=IsDraw; S:='ひきわけ !'; end else begin case ComPanel3.Tag of 0:Flg:=MyJan3=2; 1:Flg:=MyJan3=0; else Flg:=MyJan3=1; end;//case if Flg then begin S:='キミ の かち'; WaveName:=YouWin; end else begin S:='キミ の まけ'; WaveName:=YouLost; end; end; Sleep(2000); DohyouPanel.Caption:=S; if FileExists(WaveName) then sndPlaySound(PChar(WaveName),SND_SYNC); ShowMessage(S); end; procedure TDottiMainForm.DohyouPanelClick(Sender: TObject); begin MyPanel1.Enabled:=True;//ボタンを使えるようにする DohyouPanel.Caption:='じゃんけん ほいほい'; Refresh; if FileExists(Janken) then sndPlaySound(PChar(Janken),SND_ASYNC); end; { ○ X グウ/チョキ 01 グウ チョキ 01 グウ/チョキ 01 グウ パー 02 グウ/チョキ 01 パー チョキ 12 グウ/パー 02 チョキ グウ 01 グウ/パー 02 パー グウ 02 グウ/パー 02 パー チョキ 12 チョキ/パー 12 チョキ グウ 01 チョキ/パー 12 グウ パー 02 チョキ/パー 12 チョキ パー 12 } function TDottiMainForm.ComThink(My1,My2,Com1,Com2:integer): integer; var MyS,ComS:string; begin if My1>My2 then MyS:=IntToStr(My2)+IntToStr(My1) else MyS:=IntToStr(My1)+IntToStr(My2); if Com1>Com2 then ComS:=IntToStr(Com2)+IntToStr(Com1) else ComS:=IntToStr(Com1)+IntToStr(Com2); if MyS='01' then begin if ComS='12' then Result:=2 else Result:=0; end else if MyS='02' then begin if ComS='01' then Result:=1 else Result:=2; end else begin if ComS='02' then Result:=0 else Result:=1; end; end; procedure TDottiMainForm.FormPaint(Sender: TObject); begin OnPaint := nil;//これでこのイベントは二度と通らない StartSpBtn;//初期化 end; end.