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 v1.0 - SNAKE.PAS

SNAKE.PAS

Caricato da:
Scarica il programma completo

  1. uses crt;
  2. type
  3.  classifica=record
  4.  nome:string;
  5.  punteggio:integer;
  6. end;
  7.  
  8. procedure cursoroff;
  9.  assembler;
  10.  asm
  11.   mov ah,1
  12.   mov ch,20h
  13.   int 10h
  14. end;
  15.  
  16. procedure cursoron;
  17.  assembler;
  18.  asm
  19.   mov ah,1
  20.   mov ch,6
  21.   mov cl,7
  22.   int 10h
  23. end;
  24.  
  25. function chrfind(x,y:byte):char;
  26. var indirizzo: word;
  27.     depo     : char;
  28. begin
  29.  indirizzo:=(x-1)*2+(y-1)*160;
  30.  asm
  31.   push es
  32.   push di
  33.   mov ax,0B800H
  34.   mov es,ax
  35.   mov di,indirizzo
  36.   mov al,es:[di]
  37.   mov depo,al
  38.   pop es
  39.   pop di
  40.  end;
  41.  chrfind:=depo;
  42. end;
  43.  
  44.  
  45. type
  46.  opzioni=(New_game,Highscore,exit);
  47.  
  48. function menu(x,y,z,w:byte):opzioni;
  49. var a,b:byte;
  50.  c:char;
  51. begin
  52.  for a:=1 to 3*w do
  53.  begin
  54.   gotoxy(x,y+a-1);
  55.   for b:=1 to z do
  56.    write('Û');
  57.  end;
  58.  gotoxy(x,y+w);
  59.  for a:=1 to z do
  60.   write('Ü');
  61.  gotoxy(x,y+2*w);
  62.  for a:=1 to z do
  63.   write('Ü');
  64.  x:=x+z div 2 -4;
  65.  y:=y+w div 2;
  66.  textcolor(12);
  67.  gotoxy(x,y);
  68.  write('New game');
  69.  gotoxy(x,y+w);
  70.  write('Highscore');
  71.  gotoxy(x+2,y+2*w);
  72.  write('Exit');
  73.  a:=1;
  74.  textbackground(10);
  75.  repeat
  76.   case a of
  77.    1: begin
  78.        gotoxy(x,y);
  79.        write('New_game');
  80.       end;
  81.    2: begin
  82.        gotoxy(x,y+w);
  83.        write('Highscore');
  84.       end;
  85.    3: begin
  86.        gotoxy(x+2,y+2*w);
  87.        write('Exit');
  88.       end;
  89.   end;
  90.   textbackground(1);
  91.   c:=readkey;
  92.   if (c=#50) or (c=#56) then
  93.    case a of
  94.    1: begin
  95.        gotoxy(x,y);
  96.        write('New_game');
  97.       end;
  98.    2: begin
  99.        gotoxy(x,y+w);
  100.        write('Highscore');
  101.       end;
  102.    3: begin
  103.        gotoxy(x+2,y+2*w);
  104.        write('Exit');
  105.       end;
  106.   end;
  107.   if c=#50 then
  108.    if a<3 then
  109.     a:=a+1
  110.    else
  111.     a:=1;
  112.   if c=#56 then
  113.    if a>1 then
  114.     a:=a-1
  115.    else
  116.     a:=3;
  117.   textbackground(10);
  118.  until c=#13;
  119.  case a of
  120.   1: menu:=new_game;
  121.   2: menu:=highscore;
  122.   3: menu:=exit;
  123. end;
  124. end;
  125.  
  126. procedure sfondo(x,y,z,w:byte);
  127. var i:integer;
  128.  
  129. begin
  130.  textbackground(x);
  131.  for i:=1 to 2000 do
  132.   write(' ');
  133.  gotoxy(1,1);
  134.  textbackground(y);
  135.  for i:=1 to 80 do
  136.   write(' ');
  137.  gotoxy(1,1);
  138.  textcolor(z);
  139.  write('Punteggio: 0');
  140.  gotoxy(60,1);
  141.  write('vite: ');
  142.  textbackground(x);
  143.  textcolor(w);
  144. end;
  145.  
  146. var
  147.  x,y,u,v  : array[1..100] of byte;
  148.  i,b,g,d  : byte;
  149.  c        : char;
  150.  morto,s  : boolean;
  151.  vite     : byte;
  152.  scelta   : opzioni;
  153.  high     : file of classifica;
  154.  p,h      : integer;
  155.  classif  : classifica;
  156.  t        : string;
  157.  
  158. begin
  159.  assign(high,'highsc~1.dat');
  160.  clrscr;
  161.  cursoroff;
  162.  vite:=3;
  163.  repeat
  164.   scelta:=menu(15,5,60,3);
  165.   if scelta=exit then
  166.    halt;
  167.   if scelta=highscore then
  168.   begin
  169.    reset(high);
  170.    {$I+}
  171.    read(high,classif);
  172.    {$I-}
  173.    if ioresult<>0 then
  174.     write('Non ci sono punteggi salvati')
  175.    else
  176.    begin
  177.     clrscr;
  178.     write('Il miglior punteggio finora Š ',classif.punteggio,' di ',classif.nome);
  179.    end;
  180.    close(high);
  181.   end;
  182.  until scelta<>highscore;
  183.  sfondo(1,3,12,14);
  184.  repeat
  185.   for b:=1 to i do
  186.   begin
  187.    gotoxy(x[b],y[b]);
  188.    write(' ');
  189.   end;
  190.   if morto=true then
  191.   begin
  192.    s:=true;
  193.    vite:=vite-1;
  194.    gotoxy(u[d],v[d]);
  195.    write(' ');
  196.   end;
  197.   gotoxy(67,1);
  198.   textbackground(3);
  199.   textcolor(12);
  200.   write(vite);
  201.   textbackground(1);
  202.   textcolor(14);
  203.   morto:=false;
  204.   i:=4;
  205.   g:=i;
  206.   gotoxy(2,3);
  207.   for b:=1 to i do
  208.    write('Û');
  209.   b:=0;
  210.   repeat
  211.    b:=b+1;
  212.    g:=g-1;
  213.    x[b]:=2+g;
  214.    y[b]:=3;
  215.   until g=0;
  216.   u[1]:=1;
  217.   v[1]:=1;
  218.   d:=1;
  219.   repeat
  220.    if chrfind(u[d],v[d])<>'' then
  221.    begin
  222.     if d=100 then
  223.      d:=1
  224.     else
  225.      d:=d+1;
  226.     randomize;
  227.     u[d]:=random(80)+1;
  228.     v[d]:=random(25)+2;
  229.     gotoxy(u[d],v[d]);
  230.     i:=i+1;
  231.     textcolor(12);
  232.     textbackground(3);
  233.     gotoxy(12,1);
  234.     if s=false then
  235.     begin
  236.      p:=p+100;
  237.      write(p-100);
  238.     end
  239.     else
  240.      s:=false;
  241.     textcolor(13);
  242.     textbackground(1);
  243.     gotoxy(u[d],v[d]);
  244.     write('');
  245.     textcolor(14);
  246.    end;
  247.    c:=readkey;
  248.    case c of
  249.     #50: repeat
  250.           g:=i;
  251.           gotoxy(x[g],y[g]);
  252.           write(' ');
  253.           repeat
  254.            if g=1 then
  255.             y[1]:=y[1]+1
  256.            else
  257.            begin
  258.             x[g]:=x[g-1];
  259.             y[g]:=y[g-1];
  260.            end;
  261.            gotoxy(x[g],y[g]);
  262.            write('Û');
  263.            g:=g-1;
  264.           until g=0;
  265.           delay(150);
  266.           if (y[1]=26) or (chrfind(x[1],y[1]+1)='Û') then
  267.            morto:=true;
  268.          until keypressed or morto=true;
  269.     #52: repeat
  270.           g:=i;
  271.           gotoxy(x[g],y[g]);
  272.           write(' ');
  273.           repeat
  274.            if g=1 then
  275.             x[1]:=x[1]-1
  276.            else
  277.            begin
  278.             x[g]:=x[g-1];
  279.             y[g]:=y[g-1];
  280.            end;
  281.            gotoxy(x[g],y[g]);
  282.            write('Û');
  283.            g:=g-1;
  284.           until g=0;
  285.           delay(150);
  286.           if (x[1]=0) or (chrfind(x[1]-1,y[1])='Û') then
  287.            morto:=true;
  288.          until keypressed or morto=true;
  289.  
  290.     #54: repeat
  291.           g:=i;
  292.           gotoxy(x[g],y[g]);
  293.           write(' ');
  294.           repeat
  295.            if g=1 then
  296.             x[1]:=x[1]+1
  297.            else
  298.            begin
  299.             x[g]:=x[g-1];
  300.             y[g]:=y[g-1];
  301.            end;
  302.            gotoxy(x[g],y[g]);
  303.            write('Û');
  304.            g:=g-1;
  305.           until g=0;
  306.           delay(150);
  307.           if (x[1]=81) or (chrfind(x[1]+1,y[1])='Û') then
  308.            morto:=true;
  309.          until keypressed or morto=true;
  310.     #56: repeat
  311.           g:=i;
  312.           gotoxy(x[g],y[g]);
  313.           write(' ');
  314.           repeat
  315.            if g=1 then
  316.             y[1]:=y[1]-1
  317.            else
  318.            begin
  319.             x[g]:=x[g-1];
  320.             y[g]:=y[g-1];
  321.            end;
  322.            gotoxy(x[g],y[g]);
  323.            write('Û');
  324.            g:=g-1;
  325.           until g=0;
  326.           delay(150);
  327.           if (y[1]=1) or (chrfind(x[1],y[1]-1)='Û') then
  328.            morto:=true;
  329.          until keypressed or morto=true;
  330.     #13: begin
  331.           gotoxy(37,12);
  332.           write('Uscire?');
  333.           gotoxy(38,13);
  334.           write('S/N');
  335.           repeat
  336.            c:=readkey;
  337.            if (c='S') or (c='s') then
  338.             halt;
  339.           until (c='N') or (c='n');
  340.           gotoxy(37,12);
  341.           write('       ');
  342.           gotoxy(38,13);
  343.           write('   ');
  344.           for b:=1 to i do
  345.           begin
  346.            gotoxy(x[b],y[b]);
  347.            write('Û');
  348.           end;
  349.          end;
  350.     #27: halt;
  351.    end;
  352.   until morto=true;
  353.  until vite=0;
  354.  clrscr;
  355.  cursoron;
  356.  if p<classif.punteggio then
  357.   write('Mi dispiace ma il tuo punteggio non Š il pi— alto')
  358.  else
  359.  begin
  360.   writeln('WOW!!!! Punteggio pi— alto!!!');
  361.   rewrite(high);
  362.   classif.punteggio:=p;
  363.   writeln('Come ti chiami?');
  364.   readln(t);
  365.   classif.nome:=t;
  366.   write(high,classif);
  367.  end;
  368.  readln;
  369. end.