pascalabcnet/InstallerSamples/Games/DeleteByMouse.pas
Mikhalkovich Stanislav d2a5dd813b fix #1757
2019-02-22 09:27:54 +03:00

56 lines
1.6 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

uses WPFObjects;
const CountSquares = 20;
var
/// Текущая цифра
CurrentDigit: integer;
/// Количество ошибок
Mistakes: integer;
/// Строка информации
StatusRect: RectangleWPF;
/// Вывод информационной строки
procedure DrawStatusText;
begin
if CurrentDigit<=CountSquares then
StatusRect.Text := $'Удалено квадратов: {CurrentDigit-1} Ошибок: {Mistakes}'
else StatusRect.Text := $'Игра окончена. Время: {Milliseconds div 1000} с. Ошибок: {Mistakes}';
end;
/// Обработчик события мыши
procedure MyMouseDown(x,y: real; mb: integer);
begin
var ob := ObjectUnderPoint(x,y);
if (ob<>nil) and (ob is RectangleWPF) and (ob<>StatusRect) then
if ob.Number=CurrentDigit then
begin
ob.Destroy;
Inc(CurrentDigit);
DrawStatusText;
end
else
begin
ob.Color := Colors.Red;
Inc(Mistakes);
DrawStatusText;
end;
end;
begin
Window.Title := 'Игра: удали все квадраты по порядку';
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;
ob.Number := i;
end;
StatusRect := RectangleWPF.Create(0,Window.Height-40,Window.Width,40,Colors.LightBlue);
CurrentDigit := 1;
Mistakes := 0;
DrawStatusText;
// Установка обработчиков
OnMouseDown := MyMouseDown;
end.