主题:一个写字板程序
var
OrigMode,LastCol,LastRow: Word;
Ch: Char;
Done: Boolean;
procedure Initialize;
begin
CheckBreak:=False;
OrigMode:=LastMode;
TextMode(Lo(LastMode)+Font8x8);
LastCol:=Lo(WindMax)+1;
LastRow:=Hi(WindMax)+1;
GoToXY(1,LastRow);
TextBackground(Black);
TextColor(White);
Write(' Ins-InsLine ',
'Del-DelLine ',
#27#24#25#26'-Cursor ',
'Alt-W-Window ',
'Alt-R-Random ',
'Esc-Exit');
Dec(LastRow,80 div LastCol);
Randomize;
end; { Init }
procedure MakeWindow;
var
X,Y,Width,Height: Word;
begin
Width:=Random(LastCol-2)+2;
Height:=Random(LastRow-2)+2;
X:=Random(LastCol-Width)+1;
Y:=Random(LastRow-Height)+1;
Window(X,Y,X+Width,Y+Height);
if OrigMode = Mono then
begin
TextBackground(White);
TextColor(Black);
ClrScr;
Window(X+1,Y+1,X+Width-1,Y+Height-1);
TextBackground(Black);
TextColor(White);
ClrScr;
end
else
begin
TextBackground(Random(8));
TextColor(Random(7)+9);
end;
ClrScr;
end; { MakeWindow }
procedure RandomText;
begin
repeat
Write(Chr(Random(256-32)+32));
until KeyPressed;
end; { RandomText }
begin { program body }
Initialize;
MakeWindow;
Done:=False;
repeat
Ch:=ReadKey;
case Ch of
#0:
begin
Ch:=ReadKey;
case Ch of
#17: MakeWindow;
#19: RandomText;
#45: Done:=True;
#72: GotoXY(WhereX,WhereY-1);
#75: GotoXY(WhereX-1,WhereY);
#77: GotoXY(WhereX+1,WhereY);
#80: GotoXY(WhereX,WhereY+1);
#82: InsLine;
#83: DelLine;
end;
end;
#3: Done:=True;
#13: WriteLn;
#27: Done:=True;
else
Write(Ch);
end;
until Done;
TextMode(OrigMode);
end.