pascalabcnet/InstallerSamples/Games/DeleteByMouse.pas

56 lines
1.6 KiB
ObjectPascal
Raw Permalink Normal View History

uses WPFObjects;
2015-05-14 22:35:07 +03:00
const CountSquares = 20;
var
/// Текущая цифра
2015-05-14 22:35:07 +03:00
CurrentDigit: integer;
/// Количество ошибок
2015-05-14 22:35:07 +03:00
Mistakes: integer;
/// Строка информации
StatusRect: RectangleWPF;
2015-05-14 22:35:07 +03:00
/// Вывод информационной строки
2015-05-14 22:35:07 +03:00
procedure DrawStatusText;
begin
if CurrentDigit<=CountSquares then
StatusRect.Text := $'Удалено квадратов: {CurrentDigit-1} Ошибок: {Mistakes}'
else StatusRect.Text := $'Игра окончена. Время: {Milliseconds div 1000} с. Ошибок: {Mistakes}';
2015-05-14 22:35:07 +03:00
end;
/// Обработчик события мыши
procedure MyMouseDown(x,y: real; mb: integer);
2015-05-14 22:35:07 +03:00
begin
var ob := ObjectUnderPoint(x,y);
2019-02-22 09:27:54 +03:00
if (ob<>nil) and (ob is RectangleWPF) and (ob<>StatusRect) then
2015-05-14 22:35:07 +03:00
if ob.Number=CurrentDigit then
begin
ob.Destroy;
Inc(CurrentDigit);
DrawStatusText;
end
else
begin
ob.Color := Colors.Red;
2015-05-14 22:35:07 +03:00
Inc(Mistakes);
DrawStatusText;
end;
end;
begin
Window.Title := 'Игра: удали все квадраты по порядку';
2015-05-14 22:35:07 +03:00
for var i:=1 to CountSquares do
begin
var x := Random(Window.Width-50);
var y := Random(Window.Height-100);
var ob := RectangleWPF.Create(x,y,50,50,Colors.LightGreen).WithBorder;
ob.FontSize := 25;
2015-05-14 22:35:07 +03:00
ob.Number := i;
end;
StatusRect := RectangleWPF.Create(0,Window.Height-40,Window.Width,40,Colors.LightBlue);
2015-05-14 22:35:07 +03:00
CurrentDigit := 1;
Mistakes := 0;
DrawStatusText;
// Установка обработчиков
2015-05-14 22:35:07 +03:00
OnMouseDown := MyMouseDown;
end.