unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Button2: TButton;
procedure kvadrat;
procedure shestiugolnik;
procedure vosmiugolnik;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure klavKvadrat(var Key: Word);
procedure klavShest(var Key: Word);
procedure klavVosm(var key:Word);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1; var a,b:integer; n,m,c,l:byte;
implementation
{$R *.dfm}
procedure TForm1.kvadrat;
begin
canvas.brush.color:=clBlack;
a:=(form1.Width div 2)-150;
b:=(Form1.height div 2)-150;
canvas.polygon([point(a+300,b),point(a+300,b+300),point(a,b+300),
point(a,b)]);
canvas.moveto(a,b);
canvas.LineTo(a+300,b+300);
canvas.MoveTo(a+300,b);
canvas.LineTo(a,b+300);
end;
procedure TForm1.shestiugolnik;
begin
canvas.brush.color:=clBlack;
a:=(form1.Width div 2)-150;
b:=(Form1.height div 2)-150;
canvas.polygon([point(a,b),point(a+150,b-150),point(a+300,b),
point(a+300,b+300),point(a+150,b+450),point(a,b+300)]);
canvas.MoveTo(a,b);
canvas.LineTo(a+300,b+300);
canvas.moveto(a+300,b);
canvas.lineto(a,b+300);
canvas.moveto(a+150,b-150);
canvas.lineto(a+150,b+450);
end;
procedure tform1.vosmiugolnik;
begin
canvas.brush.color:=clBlack;
a:=(form1.Width div 2);
b:=(Form1.height div 2);
canvas.polygon([point(a-75,b-150),point(a+75,b-150),point(a+150,b-75),
point(a+150,b+75),point(a+75,b+150),point(a-75,b+150),
point(a-150,b+75),point(a-150,b-75)]);
canvas.moveto(a-150,b+75);
canvas.lineto(a+150,b-75); //delim na zapchasti
canvas.moveto(a-150,b-75);
canvas.lineto(a+150,b+75);
canvas.moveto(a-75,b-150);
canvas.lineto(a+75,b+150);
canvas.moveto(a+75,b-150);
canvas.lineto(a-75,b+150);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
canvas.pen.Width:=2;
canvas.Pen.color:=clwhite;
canvas.brush.color:=clBlack;
case n of
4: kvadrat;
6: shestiugolnik;
8: vosmiugolnik;
else showmessage('Некорректные данные в Input.txt');
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.lines.loadfromfile('input.txt');
n:=strtoint(memo1.lines[0]);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
m:=0;
l:=0;
canvas.pen.Width:=2;
canvas.Pen.color:=clwhite;
canvas.brush.color:=clBlack;
case n of
4: kvadrat;
6: shestiugolnik;
8: vosmiugolnik;
else showmessage('Некорректные данные в Input.txt');
end;
end;
procedure tform1.klavkvadrat(var Key: Word);
begin
kvadrat;
canvas.brush.color:=clLime;
case key of
38: canvas.polygon([point(a,b),point(a+300,b),point(a+150,b+150)]); //вверх
40: canvas.polygon([point(a,b+300),point(a+300,b+300),point(a+150,b+150)]); //вниз
37: canvas.polygon([point(a,b),point(a,b+300),point(a+150,b+150)]); //влево
39: canvas.polygon([point(a+300,b),point(a+300,b+300),point(a+150,b+150)]); //вправо
end;
end;
procedure tform1.klavShest(var Key: Word);
begin
shestiugolnik; //m - позиция треугольника по высоте
canvas.brush.color:=clLime; //l - позиция по горизонтали
case key of
38: if m>1 then m:=m-1 else m:=1; //вверх
40: if m<2 then m:=m+1 else m:=3; //вниз
37: l:=2; //влево
39: l:=1; //вправо
// else key:=#6;
end;
if l=1
then
case m of
1: canvas.polygon([point(a+150,b-150),point(a+300,b),point(a+150,b+150)]);
2: canvas.polygon([point(a+300,b),point(a+300,b+300),point(a+150,b+150)]);
3: canvas.polygon([point(a+300,b+300),point(a+150,b+450),point(a+150,b+150)]);
end
else
case m of
1: canvas.polygon([point(a,b),point(a+150,b-150),point(a+150,b+150)]);
2: canvas.polygon([point(a,b),point(a+150,b+150),point(a,b+300)]);
3: canvas.polygon([point(a,b+300),point(a+150,b+150),point(a+150,b+450)]);
end;
end;
procedure tform1.klavVosm(var key:Word);
begin
vosmiugolnik;
canvas.brush.color:=clLime;
// canvas.polygon([point(a-75,b-150),point(a+75,b-150),point(a+150,b-75),
// point(a+150,b+75),point(a+75,b+150),point(a-75,b+150),
// point(a-150,b+75),point(a-150,b-75)]);
case key of
38: if m>1 then m:=m-1 else m:=8; //вверх
40: if m<8 then m:=m+1 else m:=1; //вниз
end;
case m of
1: canvas.polygon([point(a,b),point(a-75,b-150),point(a+75,b-150)]);
2: canvas.polygon([point(a,b),point(a+75,b-150),point(a+150,b-75)]);
3: canvas.polygon([point(a,b),point(a+150,b-75),point(a+150,b+75)]);
4: canvas.polygon([point(a,b),point(a+150,b+75),point(a+75,b+150)]);
5: canvas.polygon([point(a,b),point(a+75,b+150),point(a-75,b+150)]);
6: canvas.polygon([point(a,b),point(a-75,b+150),point(a-150,b+75)]);
7: canvas.polygon([point(a,b),point(a-150,b+75),point(a-150,b-75)]);
8: canvas.polygon([point(a,b),point(a-150,b-75),point(a-75,b-150)]);
end;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case n of
4: klavkvadrat(key);
6: klavShest(key);
8: klavVosm(key);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.lines.savetofile('input.txt');
end;
end.