pascalabcnet/TestSuite/CompilationSamples/DeleteByMouse.pas

56 lines
1.6 KiB
ObjectPascal
Raw Permalink Normal View History

2015-05-14 22:35:07 +03:00
uses ABCObjects,GraphABC;
const CountSquares = 20;
var
/// Текущая цифра
2015-05-14 22:35:07 +03:00
CurrentDigit: integer;
/// Количество ошибок
2015-05-14 22:35:07 +03:00
Mistakes: integer;
/// Строка информации
2015-05-14 22:35:07 +03:00
StatusRect: RectangleABC;
/// Вывод информационной строки
2015-05-14 22:35:07 +03:00
procedure DrawStatusText;
begin
if CurrentDigit<=CountSquares then
StatusRect.Text := 'Удалено квадратов: ' + IntToStr(CurrentDigit-1) + ' Ошибок: ' + IntToStr(Mistakes)
else StatusRect.Text := 'Игра окончена. Время: ' + IntToStr(Milliseconds div 1000) + ' с. Ошибок: ' + IntToStr(Mistakes);
2015-05-14 22:35:07 +03:00
end;
/// Обработчик события мыши
2015-05-14 22:35:07 +03:00
procedure MyMouseDown(x,y,mb: integer);
begin
var ob := ObjectUnderPoint(x,y);
if (ob<>nil) and (ob is RectangleABC) then
if ob.Number=CurrentDigit then
begin
ob.Destroy;
Inc(CurrentDigit);
DrawStatusText;
end
else
begin
ob.Color := clRed;
Inc(Mistakes);
DrawStatusText;
end;
end;
begin
Window.Title := 'Игра: удали все квадраты по порядку';
2015-05-14 22:35:07 +03:00
Window.IsFixedSize := True;
for var i:=1 to CountSquares do
begin
var x := Random(WindowWidth-50);
var y := Random(WindowHeight-100);
var ob := RectangleABC.Create(x,y,50,50,clMoneyGreen);
ob.Number := i;
end;
StatusRect := RectangleABC.Create(0,Window.Height-40,Window.Width,40,Color.LightSteelBlue);
CurrentDigit := 1;
Mistakes := 0;
DrawStatusText;
// Установка обработчиков
2015-05-14 22:35:07 +03:00
OnMouseDown := MyMouseDown;
end.