Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Snake BETA 2 - SNAKE2.BAK

SNAKE2.BAK

Caricato da: Oligoatria
Scarica il programma completo

  1. Program snake;   { By Oligoatria 12/05 }
  2.  
  3. uses crt;
  4.  
  5. { definizione type e variabili per il salvataggio dell'highscore }
  6. type
  7.  rec = record
  8.   nome: string;
  9.   punti: integer;
  10.   lunghezza: integer;
  11.  end;
  12.  
  13. var
  14.  high: array[1..10] of rec;
  15.  i2: integer;
  16.  recsi: boolean;
  17.  { salvataggio su file }
  18.  save: file of rec;
  19.  
  20.  
  21. const
  22.  Cdelay=80;
  23.  
  24. var
  25.  x,y: integer;
  26.  { movimento snake }
  27.   v: array[1..100] of integer;
  28.   Vdelay: integer;
  29.   (*su,destra: boolean;*)
  30.   x1,y1: array[1..100] of integer;
  31.   tmp,i,j,lun: integer;
  32.   com: char;
  33.   mov: array[1..100] of integer;    (* 1 = sinistra -- 2 = destra -- 3 = su -- 4 = giu *)
  34.   (* se si vuole fare un tipo di movimento che segue la visuale
  35.    dello snake basta fare un mov a scalare in senso antiorario *)
  36.  { punti e bonus }
  37.   x2,y2,x3,y3,count: integer;
  38.  vite,punti:integer;
  39.  com2: char;
  40.  imm: char;
  41.  
  42.  
  43.  
  44. Procedure grafica; (* da pong, sempre by GDL3BAB *)
  45.  begin
  46.   clrscr;
  47.   textcolor(red);
  48.   gotoxy(1,1);
  49.   for i:=1 to 70 do
  50.    write('Ä');
  51.   gotoxy(1,40);
  52.   for i:=1 to 70 do
  53.    write('Ä');
  54.   for y:=1 to 40 do
  55.    begin
  56.     gotoxy(1,y);
  57.     write('³');
  58.    end;
  59.   for y:=1 to 40 do
  60.    begin
  61.     gotoxy(70,y);
  62.     write('³');
  63.    end;
  64.   gotoxy(1,40);
  65.   write('À');
  66.   gotoxy(70,1);
  67.   write('¿');
  68.   gotoxy(70,40);
  69.   write('Ù');
  70.   gotoxy(1,1);
  71.   write('Ú');
  72.  end;
  73.  
  74. Procedure comsnake;
  75.  begin
  76.   if keypressed then
  77.    begin
  78.     com:=readkey;
  79.     (* Snake non pu• tornare indietro a 180ø *)
  80.     if (mov[1]=1) and (com='6') then
  81.      sound(150)
  82.     else
  83.      if (mov[1]=2) and (com='4') then
  84.       sound(150)
  85.      else
  86.       if (mov[1]=3) and (com='5') then
  87.        sound(150)
  88.       else
  89.        if (mov[1]=4) and (com='8') then
  90.         sound(150)
  91.        else
  92.         begin
  93.          if (com='p') then
  94.           repeat until keypressed;
  95.            case com of
  96.             '4': mov[1]:=1;
  97.             '6': mov[1]:=2;
  98.             '8': mov[1]:=3;
  99.             '5': mov[1]:=4;
  100.            end;
  101.         end;
  102.    end;
  103.  end;
  104.  
  105. Procedure movsnake;
  106.  begin
  107.   case mov[i] of
  108.    1: x1[i]:=x1[i]-1;
  109.    2: x1[i]:=x1[i]+1;
  110.    3: y1[i]:=y1[i]-1;
  111.    4: y1[i]:=y1[i]+1;
  112.   end;
  113.   (* RALLENTA AI BORDI *)
  114.   if (x1[1]<4) or (x1[1]>67) or (y1[1]<4) or (y1[1]>37) then
  115.    Vdelay:=Cdelay + 50;
  116.  end;
  117.  
  118. Procedure writesnake;
  119.  begin
  120.   for i:=1 to lun do
  121.    begin
  122.     gotoxy(x1[i],y1[i]);
  123.     write(' ');
  124.    end;
  125.   comsnake;
  126.   for i:=1 to lun do
  127.    movsnake;
  128.   for i:=1 to lun do
  129.    begin
  130.     textcolor(yellow);
  131.     gotoxy(x1[i],y1[i]);
  132.     write('é');
  133.    end;
  134.  end;
  135.  
  136. Procedure copiamov;
  137.  begin
  138.   for tmp:=lun-1 downto 1 do
  139.    mov[tmp+1]:=mov[tmp];
  140.  end;
  141.  
  142. Procedure writebonus;
  143.  begin
  144.   textcolor(green);
  145.   gotoxy(x2,y2);
  146.   write('è');
  147.   gotoxy(70,50);
  148.   textcolor(0);
  149.   write(' ');
  150.  end;
  151.  
  152. Procedure contattobonus;
  153.  begin
  154.   if (x1[1]=x2) and (y1[1]=y2) then
  155.    begin
  156.     punti:=punti+10;
  157.     x2:=random(68)+2;
  158.     y2:=random(38)+2;
  159.     lun:=lun+1;
  160.     i:=lun-1;
  161.     case mov[i] of
  162.      1: begin
  163.          x1[lun]:=x1[i]+1;
  164.          y1[lun]:=y1[i];
  165.         end;
  166.      2: begin
  167.          x1[lun]:=x1[i]-1;
  168.          y1[lun]:=y1[i];
  169.         end;
  170.      3: begin
  171.          x1[lun]:=x1[i];
  172.          y1[lun]:=y1[i]+1;
  173.         end;
  174.      4: begin
  175.          x1[lun]:=x1[i];
  176.          y1[lun]:=y1[i]-1;
  177.         end;
  178.     end;
  179.     sound(300);
  180.    end;
  181.   if (x1[1]=x3) and (y1[1]=y3) then
  182.    begin
  183.     count:=100;
  184.     punti:=punti+50;
  185.     sound(400);
  186.    end;
  187.  end;
  188.  
  189. Procedure punti_;
  190.  begin
  191.   gotoxy(2,48);
  192.   textcolor(white);
  193.   writeln('Punti = ',punti);
  194.   write('Lunghezza = ',lun);
  195.  end;
  196.  
  197. Procedure contatti_morte;
  198.  begin
  199.   for i:=1 to lun do
  200.    for j:=1 to lun do
  201.     if (x1[i]=x1[j]) and (y1[i]=y1[j]) then
  202.      if i<>j then
  203.       begin
  204.        vite:=vite-1;
  205.        sound(500);
  206.       end;
  207.   for i:=1 to lun do
  208.    begin
  209.     if (x1[i]<2) or (x1[i]>69) or (y1[i]<2) or (y1[i]>39) then
  210.      begin
  211.       vite:=vite-1;
  212.       sound(500);
  213.      end;
  214.    end;
  215.  end;
  216.  
  217. Procedure bonus2_;
  218.  begin
  219.   count:=count+1;
  220.   textcolor(yellow);
  221.   if (count>50) and (count<100) then
  222.    begin
  223.     gotoxy(x3,y3);
  224.     case imm of      (* IDEA GRAFICA BY BERGAMIN MARCO *)
  225.      '/': imm:='|';
  226.      '|': imm:='\';
  227.      '\': imm:='Ä';
  228.      'Ä': imm:='/';
  229.     end;
  230.     write(imm);
  231.     gotoxy(70,50);
  232.     textcolor(0);
  233.     write(' ');
  234.    end
  235.   else
  236.    if count=50 then
  237.     begin
  238.      x3:=random(68)+2;
  239.      y3:=random(38)+2;
  240.     end
  241.    else
  242.     if count=100 then
  243.      begin
  244.       gotoxy(x3,y3);
  245.       write(' ');
  246.       x3:=50;
  247.       y3:=50;
  248.      end;
  249.   if count=400 then
  250.    count:=0;
  251.   (* aumento velocit… *)
  252.   if ((lun mod 10)=0) then
  253.    begin
  254.     Vdelay:=Vdelay-40;
  255.     x2:=x1[1];
  256.     y2:=y1[1];
  257.    end;
  258.  end;
  259.  
  260. Procedure scrivi_record;
  261.  begin
  262.   clrscr;
  263.   RESET(SAVE);
  264.   FOR I:=1 TO 10 DO
  265.    READ(SAVE,HIGH[I]);
  266.   gotoxy(1,1);
  267.   write('NOME');
  268.   gotoxy(20,1);
  269.   write('PUNTEGGIO');
  270.   gotoxy(40,1);
  271.   write('LUNGHEZZA');
  272.   for i:=1 to 10 do
  273.    begin
  274.     gotoxy(1,i+2);
  275.     write(high[i].nome);
  276.     gotoxy(20,i+2);
  277.     write(high[i].punti);
  278.     gotoxy(40,i+2);
  279.     write(high[i].lunghezza);
  280.    end;
  281.   readln;
  282.   CLOSE(SAVE);
  283.  end;
  284.  
  285. Procedure trova_record;
  286.  begin
  287.   RESET(SAVE);
  288.   clrscr;
  289.   recsi:=false;
  290.   i:=1;
  291.    while (recsi=false) and (i<=10) do
  292.     begin
  293.      if punti>high[i].punti then
  294.       begin
  295.        for i2:=10 downto (i+1) do
  296.         begin
  297.          high[i2].punti:=high[i2-1].punti;
  298.          high[i2].nome:=high[i2-1].nome;
  299.          high[i2].lunghezza:=high[i2-1].lunghezza;
  300.         end;
  301.        high[i].punti:=punti;
  302.        high[i].lunghezza:=lun;
  303.        writeln('Scrivi il tuo nome');
  304.        readln(high[i].nome);
  305.        recsi:=true;
  306.        for i:=1 to 10 do
  307.         WRITE(SAVE,HIGH[I]);
  308.        scrivi_record;
  309.       end;
  310.      i:=i+1;
  311.     end;
  312.  end;
  313.  
  314.  
  315.  
  316. begin
  317.  imm:='/';
  318.  count:=0;
  319.  textcolor(white);
  320.  repeat
  321.  ASSIGN(SAVE, 'SAVE.TXT');
  322.  clrscr;
  323.  writeln('[1] = Gioca');
  324.  writeln('[2] = High Score');
  325.  writeln('[3] = Esci');
  326.  com2:=readkey;
  327.  if com2='1' then
  328.   begin
  329.    clrscr;
  330.    randomize;
  331.    grafica;
  332.    (* INIZIALIZZAZIONE SNAKE E COORDINATE PUNTI E BONUS *)
  333.    vite:=1;
  334.    punti:=0;
  335.    x2:=random(68)+2;
  336.    y2:=random(38)+2;
  337.    x3:=random(68)+2;
  338.    y3:=random(38)+2;
  339.    lun:=5;
  340.    for i:=1 to lun do
  341.     begin
  342.      mov[i]:=2;
  343.      x1[i]:=38-i;
  344.      y1[i]:=20;
  345.     end;
  346.   while (com<>'\') and (vite>0) do
  347.    begin
  348.     Vdelay:=Cdelay;
  349.     copiamov;
  350.     writesnake;
  351.     writebonus;
  352.     bonus2_;
  353.     contattobonus;
  354.     punti_;
  355.     contatti_morte;
  356.     delay(Vdelay);
  357.     nosound;
  358.    end;
  359.   trova_record;
  360.   end
  361.  else
  362.   if com2='õ' then
  363.    begin
  364.     readln(punti);
  365.     readln(lun);
  366.     trova_record;
  367.    end
  368.   else
  369.    if com2='2' then
  370.     begin
  371.      scrivi_record;
  372.     end;
  373.  until com2='3';
  374. end.