25
Programación juego de la culebrita program juego; uses CRT,GRAPH,DOS; const max=(40*20); type tvector = array[1..max] of integer; procedure dibujo; begin textcolor(black); TextBackground(yellow); //writeln(' '); writeln('MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMMMMMMMMMMMM**""""""""""**MMMMMMMM MMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMMMMMM*""` `""MMMMMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMM"`` ^*MMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMM*"" ^*MMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMM"` "*MMMMMMMMMMMM'); writeln('MMMMMMMMMM" ^*MMMMMMMMMM'); writeln('MMMMMMMMP "MMMMMMMMM'); writeln('MMMMMMM` . ?MMMMMMM'); writeln('MMMMM!` ..xnHMMMMMMMHnx.. #MMMMMM'); writeln('MMMMM xHMMMMMMMMMMMMMMMMMMMHn: `MMMMM'); writeln('MMMM" :HMMMMMMMMMMMMMMMM*MMMMMMMMMH. "MMMM'); writeln('MMM! xMMMMMMM**"""*MMM#" ^?MMMMMMMM: MMMM'); writeln('MMM xMMMMMM*" -nn. MMMMMMMMMk `MMM'); writeln('MM> HMMMMM"` `" "MMMMMMMMMX DMM'); writeln('MM HMMMMM" .. "MMMMMMMMM XMM'); writeln('MM XMMMMM" xMMM #MMMMf`XM~ MMM'); writeln('MX :MMMMM" "MMMM. *H+ """ .MM> MMM'); writeln('ML XMMMMX 4MMMMM. .xdMMh: xHMMM MMM'); writeln('M> MMMMM> "MMMMMMhnnnHMMMMMMMM XMMM" "MMM'); writeln('ML :MMMMMk `MMMMMMMMMMMMMMM? ..dMMM" XMMM'); writeln('MX "MMMMMX "*MMMMMMMMMMMMMMMMMM" MMMM'); writeln('MM `MMMMM ^"MMMMMMMMMMMMM*" MMMMM'); writeln('MMX ?MMMML `^""""""` dMMMMM');

Programación juego culebrita

  • Upload
    kare

  • View
    811

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Programación juego culebrita

Programación juego de la culebrita

program juego; uses CRT,GRAPH,DOS; const max=(40*20); type tvector = array[1..max] of integer; procedure dibujo; begin textcolor(black); TextBackground(yellow); //writeln(' '); writeln('MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMMMMMMMMMMMM**""""""""""**MMMMMMMMMMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMMMMMM*""` `""MMMMMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMM"`` ^*MMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMM*"" ^*MMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMM"` "*MMMMMMMMMMMM'); writeln('MMMMMMMMMM" ^*MMMMMMMMMM'); writeln('MMMMMMMMP "MMMMMMMMM'); writeln('MMMMMMM` . ?MMMMMMM'); writeln('MMMMM!` ..xnHMMMMMMMHnx.. #MMMMMM'); writeln('MMMMM xHMMMMMMMMMMMMMMMMMMMHn: `MMMMM'); writeln('MMMM" :HMMMMMMMMMMMMMMMM*MMMMMMMMMH. "MMMM'); writeln('MMM! xMMMMMMM**"""*MMM#" ^?MMMMMMMM: MMMM'); writeln('MMM xMMMMMM*" -nn. MMMMMMMMMk `MMM'); writeln('MM> HMMMMM"` `" "MMMMMMMMMX DMM'); writeln('MM HMMMMM" .. "MMMMMMMMM XMM'); writeln('MM XMMMMM" xMMM #MMMMf`XM~ MMM'); writeln('MX :MMMMM" "MMMM. *H+ """ .MM> MMM'); writeln('ML XMMMMX 4MMMMM. .xdMMh: xHMMM MMM'); writeln('M> MMMMM> "MMMMMMhnnnHMMMMMMMM XMMM" "MMM'); writeln('ML :MMMMMk `MMMMMMMMMMMMMMM? ..dMMM" XMMM'); writeln('MX "MMMMMX "*MMMMMMMMMMMMMMMMMM" MMMM'); writeln('MM `MMMMM ^"MMMMMMMMMMMMM*" MMMMM'); writeln('MMX ?MMMML `^""""""` dMMMMM');

Page 2: Programación juego culebrita

writeln('MMMk "*MMMMk .HMMMMMM'); writeln('MMMMX "MMMMh. xMMMMMMMM'); writeln('MMMMMM: `MMMMMh. :MMMMMMMMMM'); writeln('MMMMMMMk `#MMMMMh:. .xMMMMMMMMMMMM'); writeln('MMMMMMMMMk. `"MMMMMMMn:. .xMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMh:. `*MMMMMMMMnx.. .xnHMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMHx. `" "MMMMMMMMHnnnnnnHHMMMMMMMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'); writeln('MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'); writeln(' Presione enter para continuar '); readkey; TextBackground(black); end; /////////////////////////////// PONE $ ////////////////////////////// procedure PESOS(cantidadpesos:integer;var vectorpesosx:tvector;var vectorpesosy:tvector); var x,y,i:integer; begin textcolor(green); randomize; for i:=1 to cantidadpesos do begin // CONSTRUCCION // repeat x:=random(40); y:=random(20); until ((x>5) and (y>5))and((x<>6)and(y<>6)); gotoxy(x,y); writeln(chr(5)); vectorpesosx[i]:=x; vectorpesosy[i]:=y; end; end;

Page 3: Programación juego culebrita

/////////////////////////////// DIFICULTAD /////////////////// procedure tiempo3(niv:char); var n:real; nivel:longint; begin n:=0; case niv of 'f':begin //nivel:=999999; nivel:=3999999; end; 'm':begin nivel:=1799999; end; 'd':begin nivel:=1179999; end; end;//case while n<>nivel do begin n:=n+0.5; end; end; ///////////////////////////// TIEMPO /////////////////////////// procedure tiempo2; var n:real; begin n:=0; while n<>709999 do begin n:=n+0.5; end; end; Procedure tiempo(num:integer); var

Page 4: Programación juego culebrita

i:integer; hour,min,sec,hsec:word; h,m,s,hh:word; sec2:word; hh2:word; begin getTime(hour,min,sec,hsec); repeat begin getTime(h,m,s,hh); sec2:=s-sec; end; until sec2=num; end; //////////////////////////////// INICIALIZO VECTOR //////////////// procedure inicializarvector(var vec:tvector); var i:integer; begin for i:=1 to max do begin vec[i]:=0; end; end; //////////////////////////////// INICIAL ////////////////////////////// procedure INICIAL; var x,y,x2,y2,cont:integer; begin textcolor(white); gotoxy(40,23); writeln(' ',chr(169)); x:=5; y:=5; y2:=5; x2:=5; cont:=0;

Page 5: Programación juego culebrita

repeat gotoxy(5,y); writeln(chr(179)); inc(y); until y=20; repeat gotoxy(40,y2); writeln(chr(179)); inc(y2); until y2=20; repeat gotoxy(x2,20); writeln(chr(196)); inc(x2); until x2=40; repeat gotoxy(x,5); writeln(chr(196)); inc(x); until x=40; gotoxy(6,6); writeln(''); gotoxy(5,5); writeln(chr(218)); gotoxy(40,5); writeln(chr(191)); gotoxy(5,20); writeln(chr(192)); gotoxy(40,20); writeln(chr(217)); end; //////////////////////////// SUMA $ ///////////////////////////////////// procedure SUMAPESOS(cant:integer;var vecx:tvector;var vecy:tvector;var m:integer;x:integer;y:integer;var suma:integer;var sum:boolean); var i:integer; begin

Page 6: Programación juego culebrita

for i:=1 to cant do begin if ((vecx[i]=x)and(vecy[i]=y)) then begin suma:=suma+10; m:=m+1; vecx[i]:=0; vecy[i]:=0; sum:=true; end; end; end; ///////////////////////////////////// SE REPITE?? //////////////// procedure verifica (x:integer;y:integer;vecX:tvector; vecY:tvector; var repite:boolean); var aux,aux2,j:integer; begin for j:=1 to max do begin if ((vecX[j]=x)and(vecY[j]=y))then begin repite:=false; end; end; end; /////////////////////////////////// INFORMA PERFECTO //////////////////// procedure salir2; var n:char; a:char; begin a:=chr(13); repeat textcolor(white); gotoxy(9,13); writeln('Presione ENTER para avanzar.'); n:=readkey; until (n=a);

Page 7: Programación juego culebrita

end; procedure perfecto2(suma:integer); var i:integer; j:integer; begin textcolor(green); sound(2); gotoxy(14,12); for j:=0 to 2 do begin for i:=0 to 18 do begin textcolor(i); gotoxy(14,11); writeln('-NIVEL COMPLETO!'); tiempo2; end; end; salir2; end; procedure continuar; var n:char; a:char; begin a:=chr(13); repeat textcolor(white); gotoxy(9,12); writeln('Presione ENTER para continuar.'); n:=readkey; until (n=a); end; ///////////////////////////////// MENU ///////////////////////// procedure menu; begin begin gotoxy(17,6);

Page 8: Programación juego culebrita

textcolor(yellow); write('L');textcolor(white);write('A'); gotoxy(20,6); textcolor(yellow);write('S'); textcolor(white);write('E'); textcolor(yellow);write('R'); textcolor(white);write('P'); textcolor(yellow);write('I'); textcolor(white);write('E'); textcolor(yellow);write('N'); textcolor(white);write('T'); textcolor(yellow);write('E'); gotoxy(16,10); textcolor(yellow); write('C'); gotoxy(17,10); textcolor(white); write('omenzar'); gotoxy(16,12); textcolor(yellow); write('I'); gotoxy(17,12); textcolor(white); write('nstrucciones'); gotoxy(16,14); textcolor(yellow); write('S'); gotoxy(17,14); textcolor(white); write('alir'); end; end; /////////////////////////////////// INSTRUCCIONES //////////////////// procedure instrucciones; var enter:char; x,y:integer;

Page 9: Programación juego culebrita

begin clrscr; inicial; gotoxy(15,6); textcolor(yellow);write('I'); textcolor(white);write('N'); textcolor(yellow);write('S'); textcolor(white);write('T'); textcolor(yellow);write('R'); textcolor(white);write('U'); textcolor(yellow);write('C'); textcolor(white);write('C'); textcolor(yellow);write('I'); textcolor(white);write('O'); textcolor(yellow);write('N'); textcolor(white);write('E'); textcolor(yellow);write('S'); gotoxy(7,9); textcolor(white); write('Movimientos con las flechas'); gotoxy(7,11); textcolor(white); write('Juntar ',chr(5),' para poder avanzar'); gotoxy(7,13); textcolor(white); write('IR a "EXIT" para pasar de NIVEL'); gotoxy(7,17); textcolor(yellow); write(' Presione ENTER para volver'); if keypressed=false then begin for x:=5 to 40 do begin tiempo2; gotoxy(x,5); writeln(chr(4)); gotoxy(x,20); writeln(chr(4)); end; for y:=5 to 20 do begin

Page 10: Programación juego culebrita

tiempo2; gotoxy(40,y); writeln(chr(4)); gotoxy(5,y); writeln(chr(4)); end; for x:=40 to 5 do begin tiempo2; gotoxy(x,20); writeln(chr(4)); end; for y:=20 to 5 do begin tiempo2; gotoxy(5,y); writeln(chr(4)); end; end; repeat begin enter:=readkey; end; until enter=chr(13); end; ////////////////////////////// CARGA NIVEL //////////////////// procedure carganivel(numniv:integer); var x:integer; n:integer; begin clrscr; inicial; textcolor(white); gotoxy(13,10); writeln(chr(17)); gotoxy(29,10); writeln(chr(16)); gotoxy(16,9);

Page 11: Programación juego culebrita

writeln('Cargando...'); n:=100 div 14; for x:=14 to 28 do begin tiempo2; tiempo2; gotoxy(19,11); writeln(n,'%'); gotoxy(x,10); writeln(chr(177)); n:=7+n; end; end; //////////////////////////////// INICIO NIVEL (PESOS) ///////////////// procedure inicionivel(numniv:integer;var vectorpesosx:tvector;var vectorpesosy:tvector;cantidadpesos:integer); begin pesos(cantidadpesos,vectorpesosx,vectorpesosy); textcolor(yellow); gotoxy(20,22); gotoxy(18,3); writeln('NIVEL ',numniv); end; ///////////////////////////////////// MENU ELEGIR NIVEL //////////// procedure eligonivel(var niv:char); begin clrscr; inicial; gotoxy(17,6); textcolor(yellow); write('E');textcolor(white);write('L'); textcolor(yellow);write('E'); textcolor(white);write('G'); textcolor(yellow);write('I'); textcolor(white);write('R'); write(' '); textcolor(yellow);write('N');

Page 12: Programación juego culebrita

textcolor(white);write('I'); textcolor(yellow);write('V'); textcolor(white);write('E'); textcolor(yellow);write('L'); gotoxy(18,9); textcolor(yellow); write('F'); gotoxy(19,9); textcolor(white); write('acil'); gotoxy(18,11); textcolor(yellow); write('M'); gotoxy(19,11); textcolor(white); write('edio'); gotoxy(18,13); textcolor(yellow); write('D'); gotoxy(19,13); textcolor(white); write('ificil'); repeat begin niv:=readkey; end; until ((niv='f')or(niv='m')or(niv='d')); end; procedure ganotodo; var i:integer; j:integer; begin clrscr; inicial; textcolor(green);

Page 13: Programación juego culebrita

sound(2); gotoxy(14,12); for j:=0 to 3 do begin for i:=0 to 18 do begin textcolor(i); gotoxy(6,11); writeln('---.... JUEGO COMPLETADO ....!!!'); tiempo2; end; end; salir2; end; procedure sacavidas(vidas:integer); var i:integer; begin case vidas of 2: begin for i:=1 to 15 do begin gotoxy(15,21); textcolor(red); writeln('VIDAS: ',chr(3),' ',chr(3),' '); tiempo2; gotoxy(15,21); textcolor(yellow); writeln('VIDAS: ',chr(3),' ',chr(3),' '); tiempo2; end;//for end; 1: begin for i:=1 to 15 do begin gotoxy(15,21); textcolor(red);

Page 14: Programación juego culebrita

writeln('VIDAS: ',chr(3),' '); tiempo2; gotoxy(15,21); textcolor(yellow); writeln('VIDAS: ',chr(3),' '); tiempo2; end;//for end; end;//case end; ///////////////////////////// BORRO COLA /////////////// procedure borro(var vecx:tvector;var vecy:tvector;k:integer); var a,b:integer; begin a:=vecx[k]; b:=vecy[k]; gotoxy(a,b); writeln(' '); vecx[k]:=0; vecy[k]:=0; end; /////////////////////// GUARDA EN VECTOR /////////////////////// procedure guarda(x:integer;y:integer;var vecX:tvector;var vecY:tvector;var i:integer); begin vecX[i]:=x; vecY[i]:=y; i:=i+1; end; //*/*/*/*/*/*/*/*/*/*/*/*/*/*//// NIVEL 1 /*/*/*/*/*/*/*/*/*/*/*/*/*/*/* procedure NIVEL1; var x,y:integer;

Page 15: Programación juego culebrita

n:char; suma:integer; vecX,vecY:tvector; i:integer; repite:boolean; hour,min,sec,hsec:word; min2,sec2,min3,sec3,hh,mi,se,h:word; a,b:integer; c:char; aux,auxx,k:integer; perfecto:boolean; niv:char; sum:boolean; aumento:integer; p1,p2,p3,p4,p5,p6,p7,p8:boolean; hhh,m:integer; vectorpesosx,vectorpesosy:tvector; cantidadpesos:integer; perdio:boolean ; numniv:integer; vidas:integer; esquina,cambiox,cambioy:integer; tecla:boolean; esq:integer; begin cantidadpesos:=5; eligonivel(niv); numniv:=1; vidas:=3; gotoxy(35,22); writeln('VIDAS:'); cambiox:=2; perdio:=false; REPEAT ////////////// REPEAAAAATTTTTTTT /////////////////// perdio:=false; BEGIN clrscr;

Page 16: Programación juego culebrita

carganivel(numniv); clrscr; inicial; inicionivel(numniv,vectorpesosx,vectorpesosy,cantidadpesos); x:=6; y:=6; suma:=0; i:=1; aux:=2; perfecto:=false; c:='>'; auxx:=0; k:=1; sum:=false; aumento:=10; repite:=true; inicializarvector(vecX); inicializarvector(vecY); gotoxy(8,21); m:=0; tecla:=false; esq:=0; cambiox:=2; case vidas of 1 : begin gotoxy(15,21); textcolor(yellow); writeln('VIDAS: ',chr(3)); end; 2 : begin gotoxy(15,21); textcolor(yellow); writeln('VIDAS: ',chr(3),' ',chr(3)); end; 3 : begin gotoxy(15,21); textcolor(yellow); writeln('VIDAS: ',chr(3),' ',chr(3),' ',chr(3));

Page 17: Programación juego culebrita

end; end;//case m:=0; if i=1 then begin //tomo la hora inicial getTime(hour,min,sec,hsec); end; while((x>5)and(y>5)and(x<40)and(y<20)and(repite=true))do begin a:=x; b:=y; //DEFINO NUEVOS X,Y tiempo3(niv); // NIVEL DE PANTALLA if keypressed=false then begin case aux of 1: begin esq:=0; x:=x-1; tecla:=false; end; 2: begin x:=x+1; // PARA QUE AVANCE SOLO..../ tecla:=false; esq:=0; end; 3: begin y:=y+1; tecla:=false; esq:=1; end; 4: begin y:=y-1; tecla:=false;

Page 18: Programación juego culebrita

esq:=1; end; end;//case end else begin repeat {Verif8ica que sean FLECHAS lo que se escribe} begin n:=readkey; end;//repeat until ((n=chr(77))or(n=chr(72))or(n=chr(80))or(n=chr(75))); case n of {Cambia x,y segun la FLECHA} (chr(75)) : begin if aux<>2 then begin x:=x-1; c:='<'; aux:=1; if cambioy=1 then begin esquina:=4; end; if cambioy=2 then begin esquina:=2; end; if cambioy=0 then begin esquina:=0; end; tecla:=true; cambioy:=0; cambiox:=1; end else

Page 19: Programación juego culebrita

begin x:=x+1; end end; (chr(77)) : begin if aux<>1 then begin x:=x+1; c:='>'; aux:=2; if cambioy=1 then begin esquina:=3; end; if cambioy=2 then begin esquina:=1; end; if cambioy=0 then begin esquina:=0; end; cambioy:=0; tecla:=true; cambiox:=2; end else begin x:=x-1; end end; (chr(80)) : begin if aux<>4 then begin y:=y+1; c:='v'; aux:=3; //NUEVA PARTEEEE if cambiox=1 then begin esquina:=1; end;

Page 20: Programación juego culebrita

if cambiox=2 then begin esquina:=2; end; if cambiox=0 then begin esquina:=5; end; tecla:=true; cambiox:=0; cambioy:=1; end else begin y:=y-1; end end; (chr(72)) : begin if aux<>3 then begin y:=y-1; c:='^'; aux:=4; if cambiox=1 then begin esquina:=3; end ; if cambiox=2 then begin esquina:=4; end; if cambiox=0 then begin esquina:=5; end; tecla:=true; cambiox:=0;

Page 21: Programación juego culebrita

cambioy:=2; end else begin y:=y+1; end end; end;//case end; //A PARTIR DE ACA YA TENGO DEFINIDOS X,Y verifica(x,y,vecX,vecY,repite); // SE REPITE guarda(x,y,vecX,vecY,i); // GUARDA EN EL VECTOR gotoxy(x,y); // POSICIONA CURSOR EN NUEVO LUGAR sumapesos(cantidadpesos,vectorpesosx,vectorpesosy,m,x,y,suma,sum);//,p1,p2,p3,p4,p5,p6,p7,p8); //SUMA SI HUBO PESOS if m=cantidadpesos then begin textcolor(yellow); gotoxy(40,19); writeln(' EXIT!'); end; gotoxy(x,y); textcolor(yellow); //ESCRIBE NUEVA CABEZA DE SERPIENTE writeln(c); gotoxy(a,b); //ESCRIBE NUEVA PARTE DEL CUERPO DE SERPIENTE if tecla=true then begin case esquina of 0: begin writeln(chr(205)); end; 1: begin writeln(chr(201));

Page 22: Programación juego culebrita

end; 2: begin writeln(chr(187)); end; 3: begin writeln(chr(200)); end; 4: begin writeln(chr(188)); end; 5: begin writeln(chr(186)); end; end;//case end//if case else begin if esq=0 then begin writeln(chr(205)); end else begin writeln(chr(186)); end; end; if auxx=4 then begin gotoxy(6,6); writeln(' '); end; //////////////////// if sum=true then begin auxx:=0; end; if auxx>4 then begin borro(vecx,vecy,k);

Page 23: Programación juego culebrita

k:=k+1; end; ///////////////////// sum:=false; //ESCRIBE NUEVO PUNTAJE auxx:=auxx+1; end; //while if suma=(cantidadpesos*10) then begin perfecto:=true; end; getTime(hour,min2,sec2,hsec); min3:=min2-min; //TOMA TIEMPO FINAL, Y CALCULA TIEMPO TOTAL sec3:=sec2-sec; if ((x=40)and(y=19)and(perfecto=true)) then begin perfecto2(suma); end else begin perdio:=true; vidas:=vidas-1; sacavidas(vidas); numniv:=numniv-1; cantidadpesos:=cantidadpesos-5; if (vidas=2)or(vidas=1) then begin continuar; end; end; numniv:=numniv+1; cantidadpesos:=cantidadpesos+5; end; until ((cantidadpesos=20)or(vidas=0)); //el 20 son 5 mas de lo q quiero que corte if perdio=false then begin

Page 24: Programación juego culebrita

ganotodo; end; if perdio=true then begin textcolor(red); gotoxy(16,10); sound(2); writeln('¡GAME OVER!'); //MENSAJE PERDIO end; end; ////////////////////// VOLVER AL MENU ///////////////// procedure salir; var n:char; a:char; begin a:=chr(13); repeat textcolor(white); gotoxy(7,13); writeln('Presione ENTER para volver al MENU'); n:=readkey; until (n=a); end; ////////////////////////// * PRINCIPAL * ////////////////////////// var op:char; begin clrscr; dibujo; repeat begin clrscr; inicial; menu; op:=readkey; if op='i'then

Page 25: Programación juego culebrita

begin instrucciones; end; if op='c' then begin clrscr; inicial; nivel1; salir; end; end; until op='s'; end.