Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
22
Добавлен:
17.04.2013
Размер:
146.43 Кб
Скачать

2.3 Листинг программы

Program Maksov_kursach;

uses Crt,Dos,Graph;

type knopka=object

public

LeftVerhX:integer;

LeftVerhY:integer;

RightNiznX:integer;

RightNiznY:integer;

Visible:boolean;

Color:byte;

Constructor Make(lx,ly,rx,ry:integer;col:byte);

Procedure Show;

Procedure Press;

end;

Constructor knopka.Make;

begin

LeftVerhX:=lx;

LeftVerhY:=ly;

RightNiznX:=rx;

RightNiznY:=ry;

Color:=col;

Visible:=False;

end;

Procedure knopka.Show;

Var

i:byte;

begin

Visible:=True;

SetLineStyle(0,0,3);

SetColor(8);

Rectangle(LeftVerhX+5,LeftVerhY+5,RightNiznX+5,RightNiznY+5);

SetFillStyle(SolidFill,8);

Bar(LeftVerhX+5,LeftVerhY+5,RightNiznX+5,RightNiznY+5);

SetColor(Color);

Rectangle(LeftVerhX,LeftVerhY,RightNiznX,RightNiznY);

SetFillStyle(SolidFill,2);

Bar(LeftVerhX+1,LeftVerhY+1,RightNiznX-1,RightNiznY-1);

end;

Procedure knopka.Press;

Var i:integer;

begin

sound(1000);

delay(100);

nosound;

SetColor(Color);

for i:=1 to 5 do

begin

setcolor(1);

line (LeftVerhX+i-1-1,LeftVerhY+i-1,RightNiznX+i,LeftVerhY+i-1);

line (LeftVerhX+i-1,LeftVerhY+i,LeftVerhX+i-1,RightNiznY+i);

setcolor(Color);

Rectangle(LeftVerhX+i,LeftVerhY+i,RightNiznX+i,RightNiznY+i);

SetFillStyle(SolidFill,2);

Bar(LeftVerhX+1+i,LeftVerhY+1+i,RightNiznX-1+i,RightNiznY-1+i);

end;

end;

Function Prinadl(x:knopka;a,b:integer):boolean;

begin

if (a>x.leftverhx) and (a<x.rightniznx) and(b>x.leftverhY) and(b<x.rightniznY) then Prinadl:=True

else Prinadl:=False;

end;

Procedure ShowMouseCursor;

begin

asm

mov ax,1;

int $33;

end

end;

function GetCoordCursorX: integer;

var c:integer;

begin

asm

mov ax,3;

int $33;

mov c,cx;

end;

GetCoordCursorX:=c;

end;

function GetCoordCursorY: integer;

var d:integer;

begin

asm

mov ax,3;

int $33;

mov d,dx;

end;

GetCoordCursorY:=d;

end;

Function PressedKnopka: byte;

var b:integer;

begin

asm

mov ax,3;

int $33;

mov b,bx;

end;

PressedKnopka:=b;

end;

Procedure HideMouse;

begin

asm

mov ax,2;

int $33;

end;

end;

Procedure Mimo;

begin

Rectangle(200,350,400,380);

SetColor(10);OutTextXY(210,360,'Сюда кликать бесполезно');

Delay(5000);

SetFillStyle(0,1);

Bar (199,349,401,381)

end;

Procedure Result(hr1,min1,sec1,msec1,hr2,min2,sec2,msec2:word);

var

s1,s2:string;

dt:word;

begin

SetFillStyle(SolidFill,1);

Bar(376,305,458,320);

str(hr2-hr1,s1);

if min1>min2 then dt:=(60-min1)+min2

else dt:=min2-min1;

str(dt,s2);

s1:=s1+':'+s2;

if sec2<sec1 then dt:=(60-sec1)+sec2

else dt:=sec2-sec1;

str(dt,s2);

s1:=s1+':'+s2;

if msec1>msec2 then dt:=(100-msec1)+msec2

else dt:=msec2-msec1;

str(dt,s2);

s1:='Время между нажатиями равно '+s1+':'+s2;

Rectangle(150,300,460,330);

SetColor(10); OutTextXY(160,310,s1);

Delay(5000);

end;

Procedure Again(n1,n2:knopka);

begin

SetFillStyle(0,1);

Rectangle(170,100,440,150);

SetColor(10);OutTextXY(180,110,'Желаете продолжить работу?');

HideMouse;

n1.Show;

n2.Show;

SetColor(4);OutTextXY(113,228,'Да!');OutTextXY(448,228,'Нет!');

ShowMouseCursor;

end;

Function PrKn(n1,n2,n3:knopka;a,b:integer):byte;

var

s:boolean;

begin

S:=False;

if Prinadl(n1,a,b) then

begin

PrKn:=1;

s:=true;

end;

if Prinadl(n2,a,b) then

begin

PrKn:=2;

s:=true;

end;

if Prinadl(n3,a,b) then

begin

PrKn:=3;

S:=True;

end;

if not s then prkn:=0

end;

var

Driver,Mode,x,y:integer;

Kn1,Kn2,Kn3:knopka;

n:byte;

hr1,min1,sec1,msec1,hr2,min2,sec2,msec2:word;

z,z1,z2:boolean;

Begin

clrscr;

Driver:=Vga;

Mode:=VgaHi;

InitGraph(Driver,Mode,'bgi');

if GraphResult<>grOk then

begin

WriteLn('Не могу инициализировать графику!');

HALT;

end;

SetViewPort(0,0,639,479,True);

SetColor(11);

SetLineStyle(0,0,3);

Rectangle(0,0,639,479);

SetBkColor(1);

SetColor(10);OutTextXY(100,50,'ПРОГРАММА, ОПРЕДЕЛЯЮЩАЯ ВРЕМЯ МЕЖДУ НАЖАТИЯМИ КНОПОК');

SetColor(10);

OutTextXY(75,60,'Сначала следует нажимать на левую кнопку, затем- на правуЮ');

SetColor(10);OutTextXY(110,469,'Для выхода нажмите любую клавишу на клавиатурЕ');

Kn1.make(110,220,160,240,10);

Kn1.Show;

Kn2.make(440,220,490,240,10);

Kn2.Show;

Kn3.make(260,220,310,240,10);

Kn3.Show;

ShowMouseCursor;

z:=False;

z1:=z;

z2:=z1;

repeat

x:= GetCoordCursorX;

y:= GetCoordCursorY;

if PressedKnopka=1 then

begin

n:=PrKn(kn1,kn2,kn3,x,y);

HideMouse;

if n=1 then

begin

kn1.press;

delay(5000);

if not z2 then GetTime(hr1,min1,sec1,msec1);

z:=true;

if z2 then

begin

SetFillStyle(0,1);

Bar(169,99,441,151);

Bar(149,299,461,331);

z1:=false;

kn1.Show;

kn2.Show;

z2:=False;

z:=False;

end;

end;

if (n=3) and (z) then

begin

Kn3.Press;

GetTime(hr2,min2,sec2,msec2);

{SetFillStyle(SolidFill,1);

Bar(376,305,458,320);

}

result(hr1,min1,sec1,msec1,hr2,min2,sec2,msec2);

Delay(5000);

kn3.Show;

end;

if (n=2) and (z) then

begin

GetTime(hr2,min2,sec2,msec2);

if z2 then halt;

kn2.press;

z1:=True;

end;

if n=0 then

begin

Mimo;

end;

ShowMouseCursor;

if (z1) and (not z2) then

begin

z2:=true;

result(hr1,min1,sec1,msec1,hr2,min2,sec2,msec2);

Again(kn1,kn2);

end

end;

if PressedKnopka=2 then

begin

sound(1000);

delay(5000);

nosound;

end;

until keypressed;

End.

Соседние файлы в папке Курсач по ОВП