program hada; uses crt; const menux=10; menuy=20; maxdlzka=50; var v,h,ryxl,prek,krz:integer; teleport:boolean; ch:char; procedure menu(x,y:integer); begin textbackground(0); textcolor(0); write(' '); textbackground(0); clrscr; textcolor(green); gotoxy(x-1,y-1); write('MENU:'); textcolor(blue); gotoxy(x,y+1); write(' nova hra'); gotoxy(x,y+2); write(' ryxlost:'); gotoxy(x,y+3); write(' velkost pola:'); gotoxy(x,y+4); write(' pocet hracov:'); gotoxy(x,y+5); write(' prekazky:'); gotoxy(x,y+6); write(' teleport:'); gotoxy(x,y+7); write(' koniec (ESC)'); textcolor(green); gotoxy(10,43); write('Ovladanie:'); gotoxy(15,44); write('1. hrac pouziva klasicke sipky'); gotoxy(15,45); write('Pripadny 2. hrac ma klavesy W,A,S,D'); textcolor(blue); gotoxy(10,48); write('Spracoval ... RG 8-) '); gotoxy(10,49); write('2007'); end; procedure kurzor(x,y:integer); begin gotoxy(x-1,y+krz-1); write(' '); gotoxy(x-1,y+krz+1); write(' '); textcolor(red); gotoxy(x-1,y+krz); write(#26); textcolor(1); gotoxy(x+10,y+2); write(ryxl); gotoxy(x+15,y+3); write(v); gotoxy(x+15,y+4); write(h); gotoxy(x+15,y+5); write(prek); gotoxy(x+15,y+6); if teleport then write('Ano') else write('Nie'); gotoxy(1,1); end; procedure nova_hra; type had=record smer,life,skore,dlzka,index,a,b:integer; pole,pomhad,pomhad2:array[1..maxdlzka,1..2] of byte; skonc:boolean; end; var i,speedpom,w,ryxlost,pomsmer1,pomsmer2,poc_prekazok,vyherna_dlzka:integer; ch1,ch2,ch3:char; zobrata,neteleportuj:boolean; x1,x2,y1,y2,x,y,t1x,t1y,t2x,t2y:integer; prekazky:array[1..100,1..2] of byte; hrac:array[1..2]of had; procedure ploxa; var i,j,k,x,y:integer; ok:boolean; begin clrscr; gotoxy(1,50); textbackground(0); textcolor(1); if h=1 then write('pocet zivotov: ',hrac[1].life,' skore: ',hrac[1].skore) else write('skore 1: ',hrac[1].skore,' skore 2: ',hrac[2].skore); case v of 1: begin x1:=30; y1:=20; x2:=50; y2:=35; end; 2: begin x1:=15; y1:=10; x2:=65; y2:=41; end; 3: begin x1:=1; y1:=1; x2:=80; y2:=48; end; end; if teleport then begin for i:=1 to 2 do begin repeat ok:=true; x:=random(x2-x1-3)+x1+2; y:=random(y2-y1-4)+y1+2; if (y=30) and (x>30) and (x<40) then ok:=false; if (y=25) and (x>30) and (x<40) then ok:=false; if i=2 then begin if (t1x<41) and (x<40) then ok:=false; if (t1x>41) and (x>40) then ok:=false; end; if ok=true then begin if i=1 then begin t1x:=x; t1y:=y; end else begin t2x:=x; t2y:=y; end; gotoxy(x,y); textbackground(white); write('T'); end; until ok; end; end else begin t1x:=80; t1y:=50; t2x:=80; t2y:=50; end; gotoxy(x1,y1); textbackground(red); for i:=1 to (x2-x1) do write(' '); gotoxy(x1,y2); for i:=1 to (x2-x1) do write(' '); for i:=y1 to (y2) do begin gotoxy(x1,i); write(' '); gotoxy(x2,i); write(' '); end; if prek>=1 then begin case v of 1: case prek of 1:j:=5; 2:j:=10; 3:j:=15; end; 2: case prek of 1:j:=10; 2:j:=20; 3:j:=30; end; 3: case prek of 1:j:=33; 2:j:=66; 3:j:=99; end; end; poc_prekazok:=j; for i:=1 to j do begin repeat ok:=false; x:=random(x2-x1-1)+x1+1; y:=random(y2-y1-1)+y1+1; if ((abs(x-t1x)<4) and (abs(y-t1y)<4)) or ((abs(x-t2x)<4) and (abs(y-t2y)<4)) or ( ((y=25) or (y=30)) and (x<38) and (x>29) ) then ok:=true; if not ok then begin for k:=1 to i-1 do begin if ((prekazky[k,1]=x) and (prekazky[k,2]=y)) then begin ok:=true; break; end; end; end; until ok=false; prekazky[i,1]:=x; prekazky[i,2]:=y; textbackground(black); gotoxy(x,y); write('X'); end; end; end; procedure kresli(t:integer); var i:integer; begin textbackground(black); if hrac[t].index=1 then gotoxy(hrac[t].pole[maxdlzka,1],hrac[t].pole[maxdlzka,2]) else gotoxy(hrac[t].pole[hrac[t].index-1,1],hrac[t].pole[hrac[t].index-1,2]); if (wherex<>t1x) or (wherey<>t1y) then if (wherex<>t2x) or (wherey<>t2y) then write(' '); if t=1 then textbackground(green) else textbackground(blue); if hrac[t].index+hrac[t].dlzka-1<=maxdlzka then begin i:=(hrac[t].index+hrac[t].dlzka-1); gotoxy(hrac[t].pole[i,1],hrac[t].pole[i,2]); end; if hrac[t].index+hrac[t].dlzka-1>maxdlzka then begin i:=(hrac[t].index+hrac[t].dlzka-1) mod maxdlzka; gotoxy(hrac[t].pole[i,1],hrac[t].pole[i,2]); end; if (hrac[t].pole[i,1]<>t1x) or (hrac[t].pole[i,2]<>t1y) then if (hrac[t].pole[i,1]<>t2x) or (hrac[t].pole[i,2]<>t2y) then write(' '); gotoxy(78,50); textbackground(0); textcolor(0); write(' ',#8); textcolor(blue); end; procedure vymenhada(t:integer); var i,j:integer; begin hrac[t].pomhad:=hrac[t].pole; j:=hrac[t].index; for i:=1 to hrac[t].dlzka do begin if j>maxdlzka then j:=1; hrac[t].pomhad2[i,1]:=hrac[t].pole[j,1]; hrac[t].pomhad2[i,2]:=hrac[t].pole[j,2]; inc(j); end; for i:=1 to hrac[t].dlzka do begin hrac[t].pomhad[i,1]:=hrac[t].pomhad2[hrac[t].dlzka-i+1,1]; hrac[t].pomhad[i,2]:=hrac[t].pomhad2[hrac[t].dlzka-i+1,2]; end; hrac[t].a:=hrac[t].pole[hrac[t].index,1]; hrac[t].b:=hrac[t].pole[hrac[t].index,2]; if (hrac[t].index+1)<=maxdlzka then begin if (hrac[t].a-hrac[t].pole[hrac[t].index+1,1])=0 then if (hrac[t].b-hrac[t].pole[hrac[t].index+1,2])=1 then hrac[t].smer:=3 else hrac[t].smer:=1 else if (hrac[t].a-hrac[t].pole[hrac[t].index+1,1])=1 then hrac[t].smer:=2 else hrac[t].smer:=4; end else begin if (hrac[t].a-hrac[t].pole[1,1])=0 then if (hrac[t].b-hrac[t].pole[1,2])=1 then hrac[t].smer:=3 else hrac[t].smer:=1 else if (hrac[t].a-hrac[t].pole[1,1])=1 then hrac[t].smer:=2 else hrac[t].smer:=4; end; hrac[t].index:=1; for i:=1 to hrac[t].dlzka do begin hrac[t].pole[i,1]:=hrac[t].pomhad[i,1]; hrac[t].pole[i,2]:=hrac[t].pomhad[i,2]; end; end; procedure inspekcia(t:integer); var i,j,k,l:integer; begin j:=hrac[t].index; for i:=1 to hrac[t].dlzka-3 do begin if j>maxdlzka then j:=1; if (hrac[t].pole[j,1]=hrac[t].a) and (hrac[t].pole[j,2]=hrac[t].b) then hrac[t].skonc:=true; inc(j); end; if (hrac[t].a=x1) or (hrac[t].a=x2) or (hrac[t].b=y1) or (hrac[t].b=y2) then hrac[t].skonc:=true; for i:=1 to poc_prekazok do begin if (hrac[t].a=prekazky[i,1]) and (hrac[t].b=prekazky[i,2]) then hrac[t].skonc:=true; end; if (hrac[1].skonc) and (h=1) and (t=1) then begin if hrac[1].life>1 then begin dec(hrac[1].life); end else begin dec(hrac[1].life); textbackground(0); clrscr; gotoxy(15,15); writeln('Game Over'); gotoxy(15,18); textcolor(white); write('nahrate skore: ',hrac[1].skore); gotoxy(78,50); textcolor(0); write(' ',#8); textcolor(blue); delay(3000); end; end; if h=2 then begin for k:=1 to 2 do begin if k=1 then l:=2 else l:=1; j:=hrac[l].index; for i:=1 to hrac[l].dlzka do begin if j>maxdlzka then j:=1; if (hrac[l].pole[j,1]=hrac[k].a) and (hrac[l].pole[j,2]=hrac[k].b) then hrac[k].skonc:=true; inc(j); end; end; end; if (h=2) and (hrac[t].skonc) then begin clrscr; dec(hrac[t].skore,30); gotoxy(15,13); if t=1 then textcolor(green); if t=2 then if not hrac[1].skonc then begin textcolor(blue); write('Zomrel 2.(modry) hrac, odpocitava sa mu 30 bodov ;-)'); end else begin textcolor(white); write('Zomreli obaja hraci, odpocitava sa im po 30 bodov ;-)'); end; end; if (h=2) then if t=2 then if (hrac[1].skonc) and (not hrac[2].skonc) then begin gotoxy(15,13); write('Zomrel 1.(zeleny) hrac, odpocitava sa mu 30 bodov ;-)'); end; end; procedure test_na_kokocinu(t:integer); begin if (hrac[t].a=x) and (hrac[t].b=y) then begin zobrata:=true; if hrac[t].index=1 then hrac[t].index:=maxdlzka else dec(hrac[t].index); if h=1 then hrac[1].skore:=hrac[1].skore+((w*10)+10) else hrac[t].skore:=hrac[t].skore+((w*10)+10); gotoxy(1,50); textbackground(0); if h=1 then write('pocet zivotov: ',hrac[1].life,' skore: ',hrac[1].skore) else write('skore 1: ',hrac[1].skore,' skore 2: ',hrac[2].skore,' '); inc(hrac[t].dlzka); end end; procedure kokocina; var alright:boolean; i,j,t,k:integer; begin repeat alright:=false; x:=random(x2-x1-1)+x1+1; y:=random(y2-y1-1)+y1+1; for t:=1 to h do begin j:=hrac[t].index; i:=0; repeat inc(i); if j>maxdlzka then j:=1; if (hrac[t].pole[j,1]=x) and (hrac[t].pole[j,2]=y) then alright:=true; if (x=t1x) and (y=t1y) then alright:=true; if (x=t2x) and (y=t2y) then alright:=true; for k:=1 to poc_prekazok do if (prekazky[k,1]=x) and (prekazky[k,2]=y) then begin alright:=true; break; end; inc(j); until (alright) or (i=hrac[t].dlzka); end; until not alright; if h=1 then begin case ryxl of 1:ryxlost:=round(speedpom-(w*25)); 2:ryxlost:=round(speedpom-(w*21)); 3:ryxlost:=round(speedpom-(w*17)); 4:ryxlost:=round(speedpom-(w*13)); 5:ryxlost:=round(speedpom-(w*10)); end; w:=random(3); if w=0 then textbackground(yellow); if w=1 then textbackground(magenta); if w=2 then textbackground(lightgreen); end else textbackground(magenta); gotoxy(x,y); write(' '); textbackground(black); zobrata:=false; end; function je_v_teleporte(t:integer):boolean; var i,j:integer; begin je_v_teleporte:=false; j:=hrac[t].index; for i:=1 to hrac[t].dlzka do begin if j>maxdlzka then j:=1; if ((hrac[t].pole[j,1]=t1x) and (hrac[t].pole[j,2]=t1y)) or ((hrac[t].pole[j,1]=t2x) and (hrac[t].pole[j,2]=t2y)) then begin je_v_teleporte:=true; break; end; inc(j); end; end; begin {nova_hra} hrac[1].life:=3; hrac[1].skore:=0; hrac[2].skore:=0; w:=0; poc_prekazok:=0; case ryxl of 1:ryxlost:=125; 2:ryxlost:=105; 3:ryxlost:=85; 4:ryxlost:=65; 5:ryxlost:=45; end; speedpom:=ryxlost; case v of 1:vyherna_dlzka:=20; 2:vyherna_dlzka:=35; 3:vyherna_dlzka:=48; end; repeat while keypressed do readkey; if h=1 then w:=0; textbackground(black); clrscr; gotoxy(25,25); if (h=1) then begin if (hrac[1].life=1) then write('Mas este 1 zivot ta hraj daco') else write('Mas ',hrac[1].life,' zivoty more'); gotoxy(78,50); textbackground(0); textcolor(0); write(' ',#8); textcolor(blue); delay(2000); end; zobrata:=true; hrac[1].skonc:=false; hrac[2].skonc:=false; hrac[1].dlzka:=3; hrac[2].dlzka:=3; hrac[1].index:=1; hrac[2].index:=1; ploxa; for i:=1 to hrac[1].dlzka do begin hrac[1].pole[i,1]:=30+i; hrac[2].pole[i,1]:=30+i; hrac[1].pole[i,2]:=25; hrac[2].pole[i,2]:=30; end; hrac[1].a:=30+i; hrac[1].b:=25; hrac[2].a:=30+i; hrac[2].b:=30; hrac[1].smer:=2; hrac[2].smer:=hrac[1].smer; while keypressed do readkey; repeat if zobrata then kokocina; pomsmer1:=hrac[1].smer; pomsmer2:=hrac[2].smer; ch1:='u'; ch3:='u'; if h=2 then ch2:='u'; if keypressed then begin while keypressed do begin ch3:=readkey; if (ch3=#80) or (ch3=#72) or (ch3=#75) or (ch3=#77) then ch1:=ch3; if h=2 then if (ch3='w') or (ch3='a') or (ch3='s') or (ch3='d') then ch2:=ch3; end; case ch2 of 's':hrac[2].smer:=3; 'w':hrac[2].smer:=1; 'd':hrac[2].smer:=2; 'a':hrac[2].smer:=4; end; case ch1 of #80:hrac[1].smer:=3; #72:hrac[1].smer:=1; #75:hrac[1].smer:=4; #77:hrac[1].smer:=2; end; end; if abs(hrac[1].smer-pomsmer1)=2 then begin if (teleport) and (je_v_teleporte(1)) then hrac[1].smer:=pomsmer1; if (not je_v_teleporte(1)) or (not teleport) then vymenhada(1); end; if h=2 then if abs(hrac[2].smer-pomsmer2)=2 then begin if (teleport) and (je_v_teleporte(2)) then hrac[2].smer:=pomsmer2; if not (je_v_teleporte(2)) or (not teleport) then vymenhada(2); end; for i:=1 to h do begin if (teleport) then begin if (hrac[i].a=t1x) and (hrac[i].b=t1y) then begin hrac[i].a:=t2x; hrac[i].b:=t2y; end else if (hrac[i].a=t2x) and (hrac[i].b=t2y) then begin hrac[i].a:=t1x; hrac[i].b:=t1y; end; end; case hrac[i].smer of 1:dec(hrac[i].b); 2:inc(hrac[i].a); 3:inc(hrac[i].b); 4:dec(hrac[i].a); end; if ((hrac[i].index+hrac[i].dlzka) mod maxdlzka)=0 then begin hrac[i].pole[maxdlzka,1]:=hrac[i].a; hrac[i].pole[maxdlzka,2]:=hrac[i].b; end else begin hrac[i].pole[((hrac[i].index+hrac[i].dlzka)mod maxdlzka),1]:=hrac[i].a; hrac[i].pole[((hrac[i].index+hrac[i].dlzka)mod maxdlzka),2]:=hrac[i].b; end; end; for i:=1 to h do begin if (hrac[i].index = maxdlzka) then hrac[i].index:=1 else inc(hrac[i].index); inspekcia(i); end; for i:=1 to h do test_na_kokocinu(i); if (h=1) and (not hrac[1].skonc) then kresli(1); if (h=2) and (not hrac[1].skonc) and (not hrac[2].skonc) then kresli(1); if (h=2) and (not hrac[2].skonc) and (not hrac[1].skonc) then kresli(2); delay(ryxlost); until (ch3=#27) or hrac[1].skonc or hrac[2].skonc or (hrac[1].dlzka=vyherna_dlzka) or (hrac[2].dlzka=vyherna_dlzka); if (h=1) then if (hrac[1].dlzka=vyherna_dlzka) then begin clrscr; gotoxy(15,18); textcolor(white); write('Blahozelame...VYHRAL SI !!!!!'); gotoxy(15,25); write('(Odporucame ti zvysit rychlost, zmensit'); gotoxy(14,26); write('hracie pole alebo si zvolit viac prekazok)'); gotoxy(15,30); write('Stlac klavesu pre navrat do hlavneho menu'); gotoxy(78,50); textbackground(0); textcolor(0); write(' ',#8); delay(2000); while keypressed do readkey; repeat until keypressed; ch3:=#27; end; if (h=2) and (ch3<>#27) then begin if (hrac[1].dlzka=vyherna_dlzka) or (hrac[2].dlzka=vyherna_dlzka) then begin gotoxy(15,12); if (hrac[1].dlzka=vyherna_dlzka) then writeln('Vyhral to prvy(zeleny) hrac!!!') else writeln('Vyhral to prvy(zeleny) hrac!!!'); end; gotoxy(15,17); textcolor(white); writeln('Chcete hrat dvojka znovu ???'); gotoxy(15,19); write('[lib.klavesa - ano ; n/N/ESC - nie]'); gotoxy(78,50); textbackground(0); textcolor(0); write(' ',#8); delay(1000); while keypressed do readkey; ch1:=readkey; if (ch1='n') or (ch1='N') or (ch1=#27) then begin textbackground(black); clrscr; gotoxy(15,15); textcolor(red); if hrac[1].skore > hrac[2].skore then write('Vyhral to 1.(zeleny) hrac'); if hrac[1].skore < hrac[2].skore then write('Vyhral to 2.(modry) hrac'); if hrac[1].skore = hrac[2].skore then write('Vasa hra skoncila remizou'); textcolor(blue); gotoxy(15,17); write('Nahrane skore:'); gotoxy(20,19); write('1.(zeleny) hrac: ',hrac[1].skore); gotoxy(20,20); write('2.(modry) hrac: ',hrac[2].skore); gotoxy(15,30); textcolor(green); write('Stiskni klavesu pre vstup do hlavneho menu'); gotoxy(78,50); textbackground(0); textcolor(0); write(' ',#8); while keypressed do readkey; delay(1500); repeat until keypressed; ch3:=#27; end; end; until (ch3=#27) or (hrac[1].life=0); ch1:=#0; while keypressed do readkey; menu(menux,menuy); end; begin textmode(co80+font8x8); randomize; textbackground(black); clrscr; h:=1; v:=1; ryxl:=1; krz:=1; prek:=0; teleport:=false; menu(menux,menuy); kurzor(menux,menuy); repeat ch:=readkey; case ch of #72:if krz>1 then krz:=krz-1; #80:if krz<7 then krz:=krz+1; #13: case krz of 1:nova_hra; 2:if ryxl<5 then ryxl:=ryxl+1 else ryxl:=1; 3:if v<3 then v:=v+1 else v:=1; 4:if h=1 then h:=2 else h:=1; 5:if prek<3 then prek:=prek+1 else prek:=0; 6:if teleport then teleport:=false else teleport:=true; 7:ch:=#27; end; end; kurzor(menux,menuy); until ch=#27; end.