uses crt; const sx=5; sy=5;
var count,max,n:byte; x,y:byte; c:char;
{ NEU DUNG TP THI COPY TU DAY DEN EEEEEEEEEEEE}
Procedure Delay(ms:word);
var t: longint; n:real;
begin n:=ms/1000;
t := meml[0:$46C];
repeat until meml[0:$46C] - t > n*18.2;
end;
{EEEEEEEEEEEEEE NEU DUNG FP THI XOA DI}
procedure vekhung(x1,y1,x2,y2:word);
var z,a,b:word;
begin
if (x1<>x2) and (y1<>y2) then
begin
a:=wherex; b:=wherey;
if x1>x2 then
begin z:=x1; x1:=x2; x2:=z; end;
if y1>y2 then
begin z:=y1; y1:=y2; y2:=z; end;
gotoxy(x1,y1); write(#201);
if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
gotoxy(x2,y1); write(#187);
gotoxy(x1,y2); write(#200);
if x2-x1>1 then for z:=1 to x2-x1-1 do write(#205);
gotoxy(x2,y2); write(#188);
if y2-y1>1 then for z:=1 to y2-y1-1 do begin
gotoxy(x1,z+y1); write(#186); end;
if y2-y1>1 then for z:=1 to y2-y1-1 do begin
gotoxy(x2,z+y1); write(#186); end;
end;
gotoxy(a,b);
end;
procedure draw;
var i:byte;
begin
window(sx,sy,sx+15,sy+16);
if count>0 then
for i:=1 to count do
write('þ');
for i:=count+1 to 255 do write('.'); write('.');
window(1,1,80,25);
gotoxy(sx+25,sy); write('Max: ',max:7);
gotoxy(sx+25,sy+1); write('Count: ',count:5);
gotoxy(sx+25+20,sy); write('Nuoc truoc cua ban: ',x:5);
gotoxy(sx+25+20,sy+1); write('Nuoc truoc cua may: ',y:5);
end;
procedure clear(m:byte);
begin
if m=0 then m:=random(max-1)+1;
begin y:=m; count:=count-m; end;
end;
Procedure New;
begin
repeat
count:=random(250)+5; draw; delay(100);
max:=random(count div 3)+count div 6;
until keypressed; while keypressed do readkey;
end;
begin
repeat
textcolor(Yellow); textbackground(Brown); clrscr;
vekhung(Sx-2,sy-2,sx+18,sy+18);
vekhung(sx+22,sy-2,sx+39,sy+3);
vekhung(sx+42,sy-2,80-2,sy+3);
vekhung(sx+22,sy+5,80-2,sy+9);
vekhung(sx+22,sy+11,80-2,sy+18);
gotoxy(30,1); write(#71#97#109#101#32#88#111#97#32#67#111);
gotoxy(15,25); write(#66#97#110#32#81#117#121#101#110#58#32,
#107#105#101#110#95#99#111#105#95#49#57#57#55,
#64#121#97#104#111#111#46#99#111#109#46#118#110);
gotoxy(sx+25,sy+13); write('Xoa mot so quan ( 0 < n < MAX ).');
gotoxy(sx+25,sy+15); write('Ai xoa cuoi cung nguoi do thang.');
gotoxy(sx+25,sy+7);
write('Press any key to start'); New; draw;
repeat
repeat
gotoxy(sx+25,sy+7); write('Nhap so quan can xoa: ');
readln(n); gotoxy(sx+25,sy+7); write('':30);
if (n>max) or (n=0) then
begin gotoxy(sx+25,sy+7); write('':30); end;
if (n>max) or (n=0) then
begin gotoxy(sx+25,sy+7); write('Loi! 0<n<MAX.Hit a key'); readkey; end;
until (n<=max) and (n>0); x:=n; clear(n); draw;
if count=0 then begin gotoxy(sx+25,sy+7);
write('Ban da thang! Hit a key '); draw;
readkey; gotoxy(sx+25,sy+7);
write('[ ESC ] : Quit [ Any key ] : Replay');
c:=readkey; end
else begin if count<=max then begin
gotoxy(sx+25,sy+7); write('A n a l y z i n g...'); delay(500);
y:=count; clear(y); end
else begin gotoxy(sx+25,sy+7); write('A n a l y z i n g...'); delay(500);
y:=count mod (max+1); clear(y); end;
draw; if count=0 then begin draw; gotoxy(sx+25,sy+7);
write('Ban da thua! Hit a key '); draw;
readkey; gotoxy(sx+25,sy+7);
write('[ ESC ] : Quit [ Any key ] : Replay');
c:=readkey; end; end;
until count=0;
until c=#27;
end.