⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 Delphi7编程80例(完全版)
💻 PAS
字号:
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;
  //随机显示大小写字母
 ch1:=chr(65+Random(25));  //大写
 ch2:=chr(97+Random(25));  //小写
 ch3:=chr(65+Random(25));
 ch4:=chr(97+Random(25));

 Label1.Caption:=ch1; //关键句
 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:='你打对了'+label1.Caption;
   If RadioButton1.Checked Then
    sndplaysound('success.wav',SND_ASYNC);
  end
 Else if key=label2.Caption Then
   Begin
   Caption:='你打对了'+label2.Caption;
   If RadioButton1.Checked Then
    sndplaysound('success.wav',SND_ASYNC);
  end
 Else if key=label3.Caption Then
   Begin
   Caption:='你打对了'+label3.Caption;
   If RadioButton1.Checked Then
    sndplaysound('success.wav',SND_ASYNC);
  end
 Else if key=label4.Caption Then
   Begin
   Caption:='你打对了'+label4.Caption;
   If RadioButton1.Checked Then
    sndplaysound('success.wav',SND_ASYNC);
  end
 Else
 Begin
 Caption:='太烂了,一个都没有对';
 If RadioButton1.Checked Then
  sndplaysound('fail.wav',SND_ASYNC);
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   //开始游戏
 Label1.Top:=25;
 Label2.Top:=25;
 Label3.Top:=25;
 Label4.Top:=25;
  //难易度设置,只要控制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
  //设置字母颜色
 Label1.Font.Color:=ColorBox1.Selected;
 Label2.Font.Color:=ColorBox1.Selected;
 Label3.Font.Color:=ColorBox1.Selected;
 Label4.Font.Color:=ColorBox1.Selected;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -