?? unit1.pas
字號(hào):
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, jpeg, Buttons, ComCtrls, ExtDlgs,mmsystem;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
TrackBar1: TTrackBar;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Button1: TButton;
Button2: TButton;
Image1: TImage;
Button3: TButton;
OpenPictureDialog1: TOpenPictureDialog;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
ColorBox1: TColorBox;
Label9: TLabel;
Label10: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ColorBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
ch1,ch2,ch3,ch4:char;
begin
Randomize;
//隨機(jī)顯示大小寫(xiě)字母
ch1:=chr(65+Random(25)); //大寫(xiě)
ch2:=chr(97+Random(25)); //小寫(xiě)
ch3:=chr(65+Random(25));
ch4:=chr(97+Random(25));
Label1.Caption:=ch1; //關(guān)鍵句
Label2.Caption:=ch2;
Label3.Caption:=ch3;
Label4.Caption:=ch4;
Label1.Left:=100;
Label2.Left:=150;
Label3.Left:=200;
Label4.Left:=250;
If label1.Top<250 Then
Label1.Top:=Label1.Top+Random(10)
Else
Label1.Top:=10;
If label2.Top<250 Then
Label2.Top:=Label2.Top+Random(10)
Else
Label2.Top:=10;
If label3.Top<250 Then
Label3.Top:=Label3.Top+Random(10)
Else
Label3.Top:=10;
If label4.Top<250 Then
Label4.Top:=Label4.Top+Random(10)
Else
Label4.Top:=10;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key=label1.Caption Then
Begin
Caption:='你打?qū)α?#039;+label1.Caption;
If RadioButton1.Checked Then
sndplaysound('success.wav',SND_ASYNC);
end
Else if key=label2.Caption Then
Begin
Caption:='你打?qū)α?#039;+label2.Caption;
If RadioButton1.Checked Then
sndplaysound('success.wav',SND_ASYNC);
end
Else if key=label3.Caption Then
Begin
Caption:='你打?qū)α?#039;+label3.Caption;
If RadioButton1.Checked Then
sndplaysound('success.wav',SND_ASYNC);
end
Else if key=label4.Caption Then
Begin
Caption:='你打?qū)α?#039;+label4.Caption;
If RadioButton1.Checked Then
sndplaysound('success.wav',SND_ASYNC);
end
Else
Begin
Caption:='太爛了,一個(gè)都沒(méi)有對(duì)';
If RadioButton1.Checked Then
sndplaysound('fail.wav',SND_ASYNC);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//開(kāi)始游戲
Label1.Top:=25;
Label2.Top:=25;
Label3.Top:=25;
Label4.Top:=25;
//難易度設(shè)置,只要控制Timer的Interval即可
If TrackBar1.Position=0 Then
Timer1.Interval:=1000;
If TrackBar1.Position=1 Then
Timer1.Interval:=500;
If TrackBar1.Position=2 Then
Timer1.Interval:=200;
Timer1.Enabled:=True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//停止游戲
Timer1.Enabled:=False;
Label1.Caption:='';
Label2.Caption:='';
Label3.Caption:='';
Label4.Caption:='';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
If OpenPictureDialog1.Execute Then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName); //更換背景圖片
end;
procedure TForm1.ColorBox1Change(Sender: TObject);
begin
//設(shè)置字母顏色
Label1.Font.Color:=ColorBox1.Selected;
Label2.Font.Color:=ColorBox1.Selected;
Label3.Font.Color:=ColorBox1.Selected;
Label4.Font.Color:=ColorBox1.Selected;
end;
end.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -