Отправляет email-рассылки с помощью сервиса Sendsay
  Все выпуски  

Новости сайта "Системное Программирование" Выпуск от 07/02/2003 - Программа


Информационный Канал Subscribe.Ru

Новости №15
Добавить в избранное | Стартовая страница
Новости сайта Системное программирование

Новости сайта "Системное Программирование"

Приглашаем к сотрудничеству руководителей других интернет проектов

Уважаемые читатели присылайте свои отзывы по адресу:
mailto:odin_2000_sata@mail.ru?subject=Otzvnew


ООП

Пример программы:

uses Graph, Crt;
const
{Задание количества объектов}
Colich=5; ColichT=5; ColichC=5; ColichCK=5; type
{Описание базового типа}
TPoint = object X,Y: Integer;
{Текущие координаты объекта}
Col:Word;
{Цвет объекта}
xx,yy:integer;
{Направление движения -1..+1 }
gx,gy,gxm,gym:integer;
{Границы движения объекта}
scet:integer;
{Вспомогательное поле. Служит для замедленной смене цветов}
Radius:integer;
{Радиус объекта.}
Razm:integer; constructor Init(InitX, InitY:integer; Igx, Igy,Igxm, Igym: Integer); procedure Show;virtual;
{Метод отображает объект на экране (Не наследуется!!!)}
procedure Hide;virtual;
{Метод скрывает объект на экране (не наследуется)}
procedure Move(NewX, NewY: Integer);
{Перемещает объект на экране
        Использует методы Show и Hide описанные для конкретного объекта }
end; TTreug = object (TPoint) constructor Init(InitX, InitY: Integer; InitRadius: Integer; Igx, Igy,Igxm, Igym: Integer); procedure Show;virtual; procedure Hide;virtual; end; TCircle = object (Ttreug) procedure Show;virtual; procedure Hide;virtual; end; TCircleK = object (TCircle) procedure Show;virtual; procedure Hide;virtual; end; Sp=^list; List=record LPoint:TPoint; Next:sp; end; SpT=^Tlist; TList=record LTreug:Ttreug; Next:spT; end; SpC=^Clist; CList=record LCircle:TCircle; Next:spC; end; SpCK=^CKlist; CKList=record LCircleK:TCircleK; Next:spCK; end; var MPoint: TPoint; MTreug: TTreug; MCircle: TCircle; MCircleK:TCircleK; i, Gd, Gm: Integer; c : char; scet1,scet2,scet3:integer; gh,gt,te:Sp; ghT,gtT,teT:SpT; ghC,gtC,teC:SpC; ghCK,gtCK,teCK:SpCK; constructor TPoint.Init(InitX, InitY:integer; Igx, Igy,Igxm, Igym: Integer); begin scet:=0; X := InitX; Y := InitY; xx:=1; yy:=1; gx:=Igx; gy:=Igy; gxm:=Igxm; gym:=Igym; Razm:=20; end; procedure TPoint.Show; begin PutPixel(X, Y, Col); end; procedure TPoint.Hide; begin PutPixel(X, Y, GetBkColor); end; procedure TPoint.Move(NewX, NewY: Integer); var Radius1:integer; begin
{В этом месте не грамотно реализован метод объекта.
Более правильным было бы разбиение одного метода на несколько методов.}
Hide; X := X + (NewX*xx); Y := Y + (NewY*yy); if x>gxm+Random(10)-5 then xx:=-1; if xgym+Random(10)-5 then yy:=-1; if y(gxm div 2) then Radius:=x div 10; if x>(gxm div 2) then Radius:=(gxm div 10) -(x div 10); if y<(gym div 2) then Radius1:=y div 5; if y>(gym div 2) then Radius1:=(gym div 5) -(y div 5); Radius:=(Radius+Radius1) div 2; Show; end; constructor TTreug.Init(InitX, InitY: Integer; InitRadius: Integer;Igx, Igy,Igxm, Igym: Integer); begin scet:=0; x:=InitX; y:=InitY; Radius:=InitRadius; xx:=1; yy:=1; gx:=Igx; gy:=Igy; gxm:=Igxm; gym:=Igym; Razm:=Radius; end; procedure TTreug.Show; begin SetColor(Col); line(x,y-Radius,x+Radius,y+Radius); line(x+Radius,y+Radius,x-Radius,y+Radius); Line(x-Radius,y+Radius,x,y-Radius); end; procedure TTreug.Hide; begin SetColor( GetBkColor); line(x,y-Radius,x+Radius,y+Radius); line(x+Radius,y+Radius,x-Radius,y+Radius); Line(x-Radius,y+Radius,x,y-Radius); End; procedure TCircle.Show; var i:real; begin SetColor(Col); Circle(x,y,Radius); line(x,y-2*Radius+5,x-2*Radius,y+Radius); Line(x-2*Radius,y+Radius,x+2*Radius,y+Radius); Line(x+2*Radius,y+Radius,x,y-2*Radius+5); end; procedure TCircle.Hide; var i:real; begin SetColor( GetBkColor); Circle(x,y,Radius); line(x,y-2*Radius+5,x-2*Radius,y+Radius); Line(x-2*Radius,y+Radius,x+2*Radius,y+Radius); Line(x+2*Radius,y+Radius,x,y-2*Radius+5); End; procedure TCircleK.Show; var i:real; begin SetColor(Col); Circle(x,y,Radius); line(x,y-2*Radius,x-2*Radius+6,y+Radius); Line(x-2*Radius+6,y+Radius,x+2*Radius-6,y+Radius); Line(x+2*Radius-6,y+Radius,x,y-2*Radius); Circle(x,y,Radius*2); end; procedure TCircleK.Hide; var i:real; begin SetColor( GetBkColor); Circle(x,y,Radius); line(x,y-2*Radius,x-2*Radius+6,y+Radius); Line(x-2*Radius+6,y+Radius,x+2*Radius-6,y+Radius); Line(x+2*Radius-6,y+Radius,x,y-2*Radius); line(x,y-2*Radius,x-2*Radius,y+Radius); Line(x-2*Radius,y+Radius,x+2*Radius,y+Radius); Line(x+2*Radius,y+Radius,x,y-2*Radius);} Circle(x,y,Radius*2); End; procedure SetColors; begin Graph.SetColor(14); Graph.SetBkColor(1); Graph.SetFillStyle(0,1) end; begin Gd := Detect; InitGraph(Gd, Gm, 'd:\ms-dos\TPascal\'); if GraphResult <> grOk then Halt(1); ClearDevice; new(te); gh:=te; gt:=gh; for i:=1 to Colich do begin new(te); gh^.next:=te; gh:=gh^.next; end; gh:=gt; Randomize; for i:=1 to Colich do begin gh^.LPoint.Init(Random(50)+100,Random(50)+100,11,11,610,450); gh^.LPoint.Show; gh:=gh^.next; end; gh:=gt; {-------------------------Треугольник-------------------------------------} new(teT); ghT:=teT; gtT:=ghT; for i:=1 to ColichT do begin new(teT); ghT^.next:=teT; ghT:=ghT^.next; end; ghT:=gtT; for i:=1 to ColichT do begin ghT^.LTreug.Init(Random(100)+50,Random(100)+50,5,45,45,600,400); ghT^.LTreug.Show; ghT:=ghT^.next; end; ghT:=gtT; {-------------------------Круг-------------------------------------} new(teC); ghC:=teC; gtC:=ghC; for i:=1 to ColichC do begin new(teC); ghC^.next:=teC; ghC:=ghC^.next; end; ghC:=gtC; for i:=1 to ColichC do begin ghC^.LCircle.Init(Random(150),Random(150),5,40,40,575,425); ghC^.LCircle.Show; ghC:=ghC^.next; end; ghC:=gtC; {--------------------------------------------------------------} new(teCK); ghCK:=teCK; gtCK:=ghCK; for i:=1 to ColichCK do begin new(teCK); ghCK^.next:=teCK; ghCK:=ghCK^.next; end; ghCK:=gtCK; for i:=1 to ColichCK do begin ghCK^.LCircleK.Init(Random(150),Random(150),5,40,40,575,425); ghCK^.LCircleK.Show; ghCK:=ghCK^.next; end; ghCK:=gtCK; repeat gh:=gt; for i:=1 to Colich do begin gh^.lPoint.scet:=gh^.lPoint.scet+1; if gh^.lPoint.scet>100+Random(100) then begin gh^.lPoint.scet:=0; gh^.lPoint.Col:=Random(14)+1; end; gh^.lPoint.Move(i,i); gh:=gh^.next; end; ghT:=gtT; for i:=1 to ColichT do begin ghT^.lTreug.scet:=ghT^.lTreug.scet+1; if ghT^.lTreug.scet>100+Random(100) then begin ghT^.lTreug.scet:=0; ghT^.lTreug.Col:=Random(14)+1; end; ghT^.lTreug.Move(i,i); ghT:=ghT^.next; end; ghC:=gtC; for i:=1 to ColichC do begin ghC^.lCircle.scet:=ghC^.lCircle.scet+1; if ghC^.lCircle.scet>100+Random(100) then begin ghC^.lCircle.scet:=0; ghC^.lCircle.Col:=Random(14)+1; end; ghC^.lCircle.Move(i,i); ghC:=ghC^.next; end; ghCK:=gtCK; for i:=1 to ColichCK do begin ghCK^.lCircleK.scet:=ghCK^.lCircleK.scet+1; if ghCK^.lCircleK.scet>100+Random(100) then begin ghCK^.lCircleK.scet:=0; ghCK^.lCircleK.Col:=Random(14)+1; end; ghCK^.lCircleK.Move(i,i); ghCK:=ghCK^.next; end; delay(20); until keypressed; c:=readkey; CloseGraph; gh:=gt; for i:=1 to Colich do begin gh:=gt^.next; Dispose(gt); gt:=gh; end; ghT:=gtT; for i:=1 to ColichT do begin ghT:=gtT^.next; Dispose(gtT); gtT:=ghT; end; ghC:=gtC; for i:=1 to ColichC do begin ghC:=gtC^.next; Dispose(gtC); gtC:=ghC; end; ghCK:=gtCK; for i:=1 to ColichC do begin ghCK:=gtCK^.next; Dispose(gtCK); gtCK:=ghCK; end; end.

Все предложения присылайте на  Email

Нам будет приятно если Вы установите код нашей кнопки

<A HREF="http://www.iatp.kharkov.ua/sites/program/index.htm">
<IMG SRC="http://www.iatp.kharkov.ua/sites/program/images/baner.gif"
ALT=" Сайт Системного Программиста" BORDER=0 HEIGHT=31 WIDTH=88></A>

Харьков 2001 - 2003
(с) Софронов П.Н. 2001 - 2003

(с) Команда "Системных Программистов" 2002 - 2003



http://subscribe.ru/
E-mail: ask@subscribe.ru
Отписаться
Убрать рекламу

В избранное