
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, StdCtrls, Unit2, Menus;
type
TForm1 = class(TForm)
Panel1: TPanel;
StatusBar1: TStatusBar;
Image1: TImage;
Timer1: TTimer;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
ComboBox1: TComboBox;
RadioGroup1: TRadioGroup;
Label2: TLabel;
Label1: TLabel;
TrackBar1: TTrackBar;
Button2: TButton;
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure ClearImage;
procedure Timer1Timer(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N5Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
private
procedure AppHint(Sender: TObject);
{ Private declarations }
public
{ Public declarations }
error : integer;//Количество ошибок
error_one,error_two,error_free:boolean;//Ошибка при нажатиии клавиши
press_one, press_two,press_free:boolean;//Правильная клавиша
play : boolean;//Определяет начало игры
one,two,free : string;//Хранят случайные буквы
f:TStringList;//Файл с буквами
y1,y2:integer;
end;
var
Form1: TForm1;
Thread : TErrorCount;//Поток подсчитывает количество ошибок
Implementation
{$R *.dfm}
procedure TForm1.ClearImage;
var
rect:TRect;
begin
rect.Top:=Image1.Top;
rect.Left:=Image1.Left;
rect.Bottom:=Image1.Height;
rect.Right:=Image1.Width;
Image1.Canvas.Brush.Color:=clWhite;
Image1.Canvas.FillRect(Rect);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
StatusBar1.Panels[0].Text := 'Уровень: Новичок';
Timer1.Interval:=1000 - TrackBar1.Position*200;
Button1.SetFocus;
play:=false;
ClearImage;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
Timer1.Enabled:=false;
ClearImage;
error:=0;
if ComboBox1.ItemIndex = 0 then StatusBar1.Panels[0].Text := 'Уровень: Новичок';
if ComboBox1.ItemIndex = 1 then StatusBar1.Panels[0].Text := 'Уровень: Любитель';
if ComboBox1.ItemIndex = 2 then StatusBar1.Panels[0].Text := 'Уровень: Мастер';
play:=false;
Button1.SetFocus;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if play then
begin
if ComboBox1.ItemIndex = 0 then
begin
if Key <> one then error_one:=true;
if Key = one then press_one:=true;
if press_one then
begin
Timer1.Enabled:=false;
Button1Click(Sender);
press_one:=false;
end;
end;
if ComboBox1.ItemIndex = 1 then
begin
if (Key <> one)and(Key <> two) then error_two:=true;
if (Key = one) then press_one:=true;
if (Key = two) then press_two:=true;
if press_one and press_two then
begin
Timer1.Enabled:=false;
Button1Click(Sender);
press_one:=false;
press_two:=false;
end;
end;
if ComboBox1.ItemIndex = 2 then
begin
if (Key <> one)and(Key <> two)and(Key <> free) then error_free:=true;
if (Key = one) then press_one:=true;
if (Key = two) then press_two:=true;
if (Key = free) then press_free:=true;
if press_one and press_two and press_free then
begin
Timer1.Enabled:=false;
Button1Click(Sender);
press_one:=false;
press_two:=false;
press_free:=false;
end;
end;
Thread:=TErrorCount.Create(true);
Thread.Resume;
Thread.Priority:=tpLower;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Randomize;
f:=TStringList.Create();//Создание объекта типа TStringList
if RadioGroup1.ItemIndex=0 then
begin
f.LoadFromFile('Russian.txt');//Загружаем файл
StatusBar1.Panels[2].Text:='Алфавит: Русский'
end
else
begin
f.LoadFromFile('Latin.txt');//Загружаем файл
StatusBar1.Panels[2].Text:='Алфавит: Латинский'
end;
one:=f.Strings[random(f.Count)];//Выбираем букву из файла
two:=f.Strings[random(f.Count)];//Выбираем букву из файла
free:=f.Strings[random(f.Count)];//Выбираем букву из файла
f.Free;//Выгружаем объект из памяти
StatusBar1.Panels[1].Text := 'Количество ошибок: '+IntToStr(error);
error_one:=false;
error_two:=false;
error_free:=false;
play:=true;
Timer1.Enabled:=true;
y1:=10;
y2:=110;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ClearImage;
Brush.Style:=bsClear;
Image1.Canvas.Font.Height:=90;
Image1.Canvas.Font.Name:='Times New Roman';
if ComboBox1.ItemIndex = 0 then
begin
Image1.Canvas.TextOut(315,y1+3,one);
end;
if ComboBox1.ItemIndex = 1 then
begin
Image1.Canvas.TextOut(220,y1+3,one);
Image1.Canvas.TextOut(420,y1+3,two);
end;
if ComboBox1.ItemIndex = 2 then
begin
Image1.Canvas.TextOut(130,y1+3,one);
Image1.Canvas.TextOut(330,y1+3,two);
Image1.Canvas.TextOut(530,y1+3,free);
end;
Inc(y1,10);
Inc(y2,10);
if y2>=Image1.Height then
begin
Inc(error);
Timer1.Enabled:=false;
Button1Click(Sender)
end;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Timer1.Interval:=500 - TrackBar1.Position*100;
Button1.SetFocus;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
Timer1.Enabled:=false;
ClearImage;
error:=0;
if ComboBox1.ItemIndex = 0 then StatusBar1.Panels[0].Text := 'Уровень: Новичок';
if ComboBox1.ItemIndex = 1 then StatusBar1.Panels[0].Text := 'Уровень: Любитель';
if ComboBox1.ItemIndex = 2 then StatusBar1.Panels[0].Text := 'Уровень: Мастер';
play:=false;
Button1.SetFocus;
end;
procedure TForm1.N2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
Application.HelpCommand(HELP_FINDER,0);
end;
procedure TForm1.N5Click(Sender: TObject);
begin
ShowMessage('Программа: Клавиатурный тренажер'+#13+
'Выполнили: ст. гр. 840 Сорокина М. М., Иванова Е. А.');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnHint:= AppHint;
end;
procedure TForm1.AppHint(Sender: TObject);
begin
StatusBar1.Panels[3].Text := Application.Hint;end;end.
Результаты выполнения программы:
Задание 2.4. Текст модулей:
unit Unit1;