Pac-Man versione 1.0 - PAC_MAN.PAS
Cerca
 











PAC_MAN.PAS

Caricato da: Alex
Scarica il programma completo

  1. program pac_man;
  2.  
  3. uses crt,graph,grafpac;
  4.  
  5. type
  6.  casi = (Vuoto,Muro,Cibo,Pac,Gosth);
  7.  fantasmi =(man,rosso,rosa,azzurro,arancione);
  8.  schermo= array [1..33,0..24] of casi;
  9.  direzione= (N,S,E,O,Stop);
  10.  posto = record
  11.   tipo:fantasmi;
  12.   mov:direzione;
  13.   scia:casi;
  14.   x,y:integer;
  15.  end;
  16.  
  17. var
  18.  wait:char;
  19.  vite:byte;
  20.  t:boolean;
  21.  campo : schermo;
  22.  mur:text;
  23.  movtemp : direzione;
  24.  coor:integer;
  25.  pospac:posto;
  26.  x,y,zx,zz:integer;
  27.  l:char;
  28.  score:integer;
  29.  modo,grafica:smallint;
  30.  z:integer;
  31.  jonny,pinky,toni,speed:posto;
  32.  k:integer;
  33.  
  34. CONST
  35.  Su=72;Zu=80;Sn=75;Dx=77;
  36.  Veloc=27000;
  37.  MX=33;MY=24;
  38.  diff=50;
  39. function sbati(campo:schermo; movimento:direzione;pos:posto):boolean;
  40. var x,y:integer; t:boolean;
  41. begin
  42.  t:=false;
  43.  x:=pos.x;
  44.  y:=pos.y;
  45.  case movimento of
  46.   S: if campo[x,y+1]=Muro then t:= true;
  47.   N: if campo[x,y-1]=Muro then t:= true;
  48.   E: if campo[x+1,y]=Muro then t:= true;
  49.   O: if campo[x-1,y]=Muro then t:= true;
  50.  end;
  51.  sbati:=t;
  52. end;
  53. procedure shift(var movimento:direzione; var campo:schermo;var pos:posto;var score:integer);
  54. var x,y,l: integer;
  55. begin
  56.  case pospac.mov of
  57.  N :l:=1;
  58.  S :l:=2;
  59.  E :l:=3;
  60.  O :l:=4;
  61.  end;
  62.  x:=pos.x;
  63.  y:=pos.y;
  64.   case movimento of
  65.   N:
  66.       begin
  67.        if campo[x,y-1]=Cibo then
  68.         score:=score+10;
  69.        campo[x,y]:=Vuoto;
  70.        disegna(3,x,y,l);
  71.        campo[x,y-1]:=Pac;
  72.        disegna(2,x,y-1,l);
  73.        pos.y:=y-1;
  74.       end;
  75.   S:
  76.       begin
  77.        if campo[x,y+1]=Cibo then
  78.         score:=score+10;
  79.        campo[x,y]:=Vuoto;
  80.        disegna(3,x,y,0);
  81.        campo[x,y+1]:=Pac;
  82.        disegna(2,x,y+1,l);
  83.        pos.y:=y+1;
  84.       end;
  85.   O:
  86.       begin
  87.        if campo[x-1,y]=Cibo then
  88.         score:=score+10;
  89.        campo[x,y]:=Vuoto;
  90.        disegna(3,x,y,0);
  91.        campo[x-1,y]:=Pac;
  92.        disegna(2,x-1,y,l);
  93.        pos.x:=x-1;
  94.       end;
  95.   E:
  96.       begin
  97.        if campo[x+1,y]=Cibo then
  98.         score:=score+10;
  99.        campo[x,y]:=Vuoto;
  100.        disegna(3,x,y,0);
  101.        campo[x+1,y]:=Pac;
  102.        disegna(2,x+1,y,l);
  103.        pos.x:=x+1;
  104.       end;
  105.  end;
  106. end;
  107.  
  108. function movete:direzione;
  109. var movimento:direzione;
  110. begin
  111.  repeat
  112.  l:=readkey;
  113.  until (ord(upcase(l))=Su) or (ord(upcase(l))=Zu) or (ord(upcase(l))=Sn) or (ord(upcase(l))=Dx);
  114.  case ord(upcase(l)) of
  115.   Su : movimento:=N;
  116.   Zu : movimento:=S;
  117.   Sn : movimento:=O;
  118.   Dx : movimento:=E;
  119.  end;
  120.  movete:=movimento;
  121. end;
  122.  
  123. procedure intrameze(var campo:schermo);
  124.  var mur:text;
  125.      x,y,i,n:integer;
  126.   begin
  127.    assign(mur,'mur1.txt');
  128.    reset(mur);
  129.    while not eof(mur) do
  130.    begin
  131.      readln(mur,x);
  132.      readln(mur,y);
  133.      campo[x,y]:=Muro;
  134.    end;
  135.   end;
  136.  
  137. procedure shiftjonny(var jonny:posto; var campo:schermo);
  138. var k,x,y,z:integer;
  139.  
  140. begin
  141.  x:=jonny.x;
  142.  y:=jonny.y;
  143.  case jonny.tipo of
  144.   rosso : k:=4;
  145.   rosa : k:=13;
  146.   azzurro: k:=11;
  147.   arancione: k:=12;
  148.  end;
  149.  case jonny.mov of
  150.   E: begin
  151.       campo[x,y]:=jonny.scia;
  152.       jonny.scia:=campo[x+1,y];
  153.       campo[x+1,y]:=Gosth;
  154.       jonny.x:=x+1;
  155.       disfant(k,x+1,y);
  156.       case campo[x,y] of
  157.        Vuoto: z:=3;
  158.        Cibo: z:=4;
  159.        Muro: z:=1;
  160.       end;
  161.       disegna(z,x,y,0);
  162.     end;
  163.   O: begin
  164.       campo[x,y]:=jonny.scia;
  165.       jonny.scia:=campo[x-1,y];
  166.       campo[x-1,y]:=Gosth;
  167.       jonny.x:=x-1;
  168.       disfant(k,x-1,y);
  169.       case campo[x,y] of
  170.        Vuoto: z:=3;
  171.        Cibo: z:=4;
  172.        Muro: z:=1;
  173.       end;
  174.       disegna(z,x,y,0);
  175.     end;
  176.   N: begin
  177.       campo[x,y]:=jonny.scia;
  178.       jonny.scia:=campo[x,y-1];
  179.       campo[x,y-1]:=Gosth;
  180.       jonny.y:=y-1;
  181.       disfant(k,x,y-1);
  182.       case campo[x,y] of
  183.        Vuoto: z:=3;
  184.        Cibo: z:=4;
  185.        Muro: z:=1;
  186.       end;
  187.       disegna(z,x,y,0);
  188.      end;
  189.   S:begin
  190.       campo[x,y]:=jonny.scia;
  191.       jonny.scia:=campo[x,y+1];
  192.       campo[x,y+1]:=Gosth;
  193.       jonny.y:=y+1;
  194.       disfant(k,x,y+1);
  195.       case campo[x,y] of
  196.        Vuoto: z:=3;
  197.        Cibo: z:=4;
  198.        Muro: z:=1;
  199.       end;
  200.  
  201.       disegna(z,x,y,0);
  202.      end;
  203.  end;
  204. end;
  205. function dir_fant(campo:schermo;pospac,jonny:posto):direzione;
  206. var
  207.  px,py,x,y,i,k,z:integer;
  208.  sit: array [1..4] of direzione;
  209.  temp,t:direzione;
  210.  collisione,tx,ty:boolean;
  211. begin
  212.  px:=pospac.x;py:=pospac.y;
  213.  randomize;
  214.  x:=jonny.x;
  215.  y:=jonny.y;
  216.  k:=0;
  217.  for i:=1 to 4 do sit[i]:=Stop;
  218.  if not(campo[x,y-1]=Muro) then sit[1]:=N;
  219.  if not(campo[x,y+1]=Muro) then sit[2]:=S;
  220.  if not(campo[x-1,y]=Muro) then sit[3]:=O;
  221.  if not(campo[x+1,y]=Muro) then sit[4]:=E;
  222.  collisione:=sbati(campo,jonny.mov,jonny);
  223.  z:=0;
  224.  for i:= 1 to 4 do if sit[i]=Stop then z:=z+1;
  225.  
  226.  if not collisione then
  227.    case jonny.mov of
  228.     N:sit[2]:=Stop;
  229.     S:sit[1]:=Stop;
  230.     E:sit[3]:=Stop;
  231.     O:sit[4]:=Stop;
  232.    end;
  233.  if collisione or (z<=1) then
  234.     begin
  235.      repeat
  236.       k:=random(3999);
  237.       k:=k div 1000+1;
  238.       dir_fant:=sit[k];
  239.      until sit[k]<>stop;
  240.      if (jonny.tipo=Rosso)or (jonny.tipo=arancione) then
  241.      begin
  242.       if (px=x)and(y-py<diff)and(y-py>0)and not sbati(campo,N,jonny) then dir_fant:=N;
  243.       if (px=x)and(py-y<diff)and(py-y>0)and not sbati(campo,S,jonny) then dir_fant:=S;
  244.       if (py=y)and(x-px<diff)and(x-px>0)and not sbati(campo,O,jonny) then dir_fant:=O;
  245.       if (py=y)and(px-x<diff)and(px-x>0)and not sbati(campo,E,jonny) then dir_fant:=E;
  246.      end;
  247.     end
  248.  else
  249.    dir_fant:=jonny.mov;
  250. end;
  251.  
  252. function gnam(campo:schermo;pospac:posto):boolean;
  253. begin
  254.  gnam:=False;
  255.  if not(campo[pospac.x,pospac.y]=Pac) then
  256.   gnam:=True;
  257. end;
  258.  
  259. procedure cuori(vite:byte);
  260. begin
  261.  setviewport(552,40,getmaxx-2,100,ClipOn);
  262.  clearviewport;
  263.  for i:=1 to vite do
  264.  begin
  265.   setcolor(red);
  266.   setfillstyle(1,red);
  267.   arc(i*15-2,7,10,190,2);
  268.   line(i*15-4,8,i*15,13);
  269.   arc(i*15+2,7,350,190,2);
  270.   line(i*15+4,8,i*15,13);
  271.   floodfill(i*15,10,red);
  272.  end;
  273.  setviewport(0,0,getmaxx,getmaxy,clipon);
  274.  end;
  275. begin   {MAIN}
  276.  
  277.  vite:=3;
  278.  score:=0;
  279.  with jonny do
  280.  begin
  281.   scia:=Vuoto;
  282.   tipo:=rosso;
  283.   mov:=E;
  284.   x:=2;
  285.   y:=22;
  286.  end;
  287.  with pinky do
  288.  begin
  289.   scia:=Cibo;
  290.   tipo:=rosa;
  291.   mov:=E;
  292.   x:=2;
  293.   y:=2;
  294.  end;
  295.  with toni do
  296.  begin
  297.   scia:=Cibo;
  298.   tipo:=azzurro;
  299.   mov:=O;
  300.   x:=27;
  301.   y:=2;
  302.  end;
  303.  with speed do
  304.  begin
  305.   scia:=Cibo;
  306.   tipo:=arancione;
  307.   mov:=O;
  308.   x:=27;
  309.   y:=22;
  310.  end;
  311.  campo[27,22]:=Gosth;
  312.  campo[2,22]:=Gosth;
  313.  campo[2,2]:=Gosth;
  314.  campo[27,2]:=Gosth;
  315.  for x:=1 to MX do
  316.   for y:=1 to MY do
  317.  
  318.   if (x=1) or (x=MX-4) or (y=1) or (y=MY) then
  319.    campo[x,y]:=Muro
  320.   else
  321.   campo[x,y]:=Cibo;
  322.  
  323.  modo:=detect;grafica:=detect; initgraph(grafica,modo,'c:\tp\bgi');
  324.    setbkcolor(black);
  325.    setcolor(green);
  326.    setfillstyle(2,black);
  327.    rectangle(550,1,638,getmaxy-1);
  328.    floodfill(580,20,green);
  329. { inizio;}
  330.   intrameze(campo);
  331.   with pospac do
  332.   begin
  333.    tipo:=Man;
  334.    x:=20;
  335.    y:=7;
  336.   end;
  337.   campo[20,7]:=Pac;
  338.  
  339.  
  340.  for x:=1 to MX-6 do
  341.   for y:=1 to MY do
  342.    begin
  343.      case campo[x,y] of
  344.       Muro: coor:=1;
  345.       Pac: coor:=2;
  346.       Vuoto: coor:=3;
  347.       Cibo: coor:=4;
  348.      end;
  349.    disegna(coor,x,y,0);
  350.    end;
  351.    jonny.mov:=S;
  352.    cuori(vite);
  353.   repeat
  354.    repeat
  355.       movtemp:=pospac.mov;
  356.       pospac.mov:=movete;
  357.       if sbati(campo,pospac.mov,pospac) then pospac.mov:=movtemp;
  358.       repeat
  359.        if sbati(campo,pospac.mov,pospac) then pospac.mov:=Stop;
  360.        shift(pospac.mov,campo,pospac,score);
  361.        shiftjonny(jonny,campo);
  362.        shiftjonny(pinky,campo);
  363.        shiftjonny(toni,campo);
  364.        shiftjonny(speed,campo);
  365.        speed.mov:=dir_fant(campo,pospac,speed);
  366.        jonny.mov:=dir_fant(campo,pospac,jonny);
  367.        pinky.mov:=dir_fant(campo,pospac,pinky);
  368.        toni.mov:=dir_fant(campo,pospac,toni);
  369.        delay(Veloc);
  370.  
  371.  
  372.       until gnam(campo,pospac) or keypressed or (score>=3940);
  373.  
  374.    until gnam(campo,pospac)or (score>=3940);
  375.    if gnam(campo,pospac) then
  376.    begin
  377.    vite:=vite-1;
  378.    SetViewPort(552,100,637,200,Clipon);
  379.    OutTextXY(1,30,'Premi');
  380.    OuttextXY(1,50,'Invio');
  381.    while ord(wait)<>13 do
  382.     read(wait);
  383.    ClearViewport;
  384.    Setviewport(0,0,getmaxx,getmaxy,clipon);
  385.    campo[pospac.x,pospac.y]:=Vuoto;
  386.    disegna(3,pospac.x,pospac.y,1);
  387.    campo[20,7]:=Pac;
  388.    with pospac do
  389.    begin
  390.     x:=20;
  391.     y:=7;
  392.     mov:=O;
  393.    end;
  394.    disegna(2,20,7,3);
  395.    cuori(vite);
  396.    end;
  397.  until (vite=0) or (score>=3940);
  398.   if vite=0 then
  399.   OutTextXY(555,100,'GAME_OVER')
  400.   else
  401.   OuttextXY(555,100,'Hai_Vinto');
  402.   readln;
  403.   closegraph;
  404.  
  405.   clrscr;
  406.   write('Il Tuo punteggio Š: ',score);
  407.  readln;
  408. end.
 

Creative Commons License
Il layout di questo sito è concesso sotto licenza Creative Commons.
Per maggiori informazioni sulle licenze dei contenuti del sito, clicca.