(******************************************) (* Programm uss *) (* Programmeerija Birgit Bollverk m-21 *) (* 30.11.97 *) (******************************************) uses crt; const con = $0607; coff = $ffff; reknimi = 'rekordid.txt'; inimene = 'Inimene'; valja : boolean = false; type koht = record x,y : shortint; end; rekord = record nimi : string[20]; punktid : word; end; rekmass = array[1..10]of rekord; rekfile = file of rekord; kmass = array[0..1500]of koht; var rek : rekmass; procedure cursor(w : word); assembler; asm mov ah,1 mov cx,w int $10 end; procedure uus(var a : koht); begin a.x:=random(37)+2; a.y:=random(46)+2; end; procedure joonista; Var i:byte; begin textmode(256); textcolor(red); for i:= 1 to 40 do begin gotoxy(i, 1); write(#219); gotoxy(i, 49); write(#219); end; for i:= 2 to 48 do begin gotoxy(1, i); write(#219); gotoxy(40, i); write(#219); end; textcolor(green); end; procedure uussuund(var s : koht); begin case readkey of #0: case readkey of #72: if s.y<>1 then begin s.y:=-1; s.x:=0; end; #77: if s.x<>-1 then begin s.y:=0; s.x:=1; end; #80: if s.y<>-1 then begin s.y:=1; s.x:=0; end; #75: if s.x<>1 then begin s.y:=0; s.x:=-1; end; end; #27: valja:=true; end; end; procedure surm(var e,nr : byte; var suund,uss,oige : koht; var pikkus,abipikkus,p : word); begin gotoxy(10, 19); write('* * * * * * * * * * '); gotoxy(10, 20); write('* * '); gotoxy(10, 21); write('* Surma said * '); gotoxy(10, 22); write('* * '); gotoxy(10, 23); write('* Vajuta ENTERIT * '); gotoxy(10, 24); write('* * '); gotoxy(10, 25); write('* * * * * * * * * * '); readkey; e:= e-1; joonista; gotoxy(1, 50); write('Punktid: ',p:4, 'Elud: ':25,e); cursor(coff); pikkus:=0; nr:=1; uus(oige); gotoxy(oige.x,oige.y); write(nr); pikkus:=0; abipikkus:=pikkus; uus(uss); gotoxy(uss.x,uss.y); write(#219); suund.x:=0; suund.y:=0; uussuund(suund); end; function ylesaba(uss : kmass; pikkus : word):boolean; var i : word; begin for i:=1 to pikkus do if (uss[0].x=uss[i].x) and (uss[0].y=uss[i].y) then begin ylesaba:=true; exit; end; ylesaba:=false; end; function poleuss(x : koht; u : kmass; p : word):boolean; var i : word; begin for i:=0 to p do if (u[i].x=x.x) and (u[i].y=x.y) then begin poleuss:=false; exit; end; poleuss:=true; end; procedure naitarekordeid; var f : rekfile; olend : rekord; i : byte; begin assign(f,reknimi); {$I-} reset(f); {$I+} if IOResult<>0 then begin assign(f,reknimi); {$I-} rewrite(f); {$I+} if IOResult<>0 then begin writeln('Mingi jama failimajandusega....'); halt(1); end; olend.nimi:=inimene; olend.punktid:=0; for i:=1 to 10 do begin write(f,olend); writeln(olend.nimi,' ',olend.punktid); rek[i]:=olend; end; end else for i:=1 to 10 do begin read(f,olend); writeln(olend.nimi,' ',olend.punktid); rek[i]:=olend; end; close(f); readkey; end; procedure uuedrekordid(punktid : word); var koht,i,j : byte; abi : rekord; f : rekfile; begin textmode(3); for i:=1 to 10 do writeln(rek[i].nimi,' ',rek[i].punktid); writeln; if rek[10].punktid0 then begin writeln('Mingi jama failimajandusega....'); halt(1); end; clrscr; for i:=1 to 10 do begin writeln(rek[i].nimi,' ',rek[i].punktid); write(f,rek[i]) end; close(f); end; readkey; clrscr; end; procedure liikumine; var suund,oige : koht; nr,elud,i : byte; punktid,pikkus,abipikkus : word; uss : kmass; begin gotoxy(1, 50); write('Punktid: 0', 'Elud: 5':26); cursor(coff); randomize; nr:=1; elud:=5; uus(oige); gotoxy(oige.x,oige.y); write(nr); pikkus:=0; abipikkus:=pikkus; repeat uus(uss[0]); until (uss[0].x<>oige.x)and(uss[0].y<>oige.y); gotoxy(uss[0].x,uss[0].y); write(#219); suund.x:=0; suund.y:=0; uussuund(suund); punktid:=0; if not valja then repeat if keypressed then uussuund(suund); if abipikkus=pikkus then begin gotoxy(uss[pikkus].x,uss[pikkus].y); write(' '); end else abipikkus:=abipikkus+1; if pikkus>0 then for i:=abipikkus-1 downto 0 do uss[i+1]:=uss[i]; uss[0].x:=uss[0].x+suund.x; uss[0].y:=uss[0].y+suund.y; if (uss[0].x>39) or (uss[0].x<2) or (uss[0].y>48) or (uss[0].y<2) or ylesaba(uss,abipikkus) then surm(elud,nr,suund,uss[0],oige,pikkus,abipikkus,punktid) else if (oige.x=uss[0].x) and (oige.y=uss[0].y) then begin punktid:=punktid+nr; pikkus:=pikkus+nr; nr:=nr+1; repeat uus(oige); until poleuss(oige,uss,pikkus); gotoxy(oige.x,oige.y); write(nr mod 10); gotoxy(10,50); write(punktid:4); end; gotoxy(uss[0].x,uss[0].y); write(#219); delay(150); until (elud=0) or valja; uuedrekordid(punktid); cursor(con); end; begin naitarekordeid; joonista; liikumine; end.