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
FORZA 4 - forza 4.pas

forza 4.pas

Caricato da: Punkettone90
Scarica il programma completo

  1. program forza_4;
  2. uses crt;
  3. var log:array[1..6,1..9] of integer;
  4.     i,j,a,b,cont,numero,val_log,bb:integer;
  5.     tasto,risp:char;
  6.     finito,vinx,viny,fine:boolean;
  7.     cancella,nome,x,y:string;
  8.  
  9.  
  10. procedure intestazione;
  11.   begin
  12.     writeln('BENVENUTO NEL GIOCO DEL FORZA 4');
  13.     writeln();
  14.     write('come ti chiami 1 giocatore?  ');
  15.     readln(x);
  16.     write('come ti chiami 2 giocatore?  ');
  17.     readln(y);
  18.     clrscr;
  19.   end;
  20.  
  21.  
  22. procedure struttura;
  23.   begin
  24.    for i:=1 to 6 do
  25.     begin
  26.        for j:=1 to 4 do
  27.         begin
  28.         writeln('       |       |       |       |       |       |       |       |       |');
  29.         end;
  30.      writeln('---------------------------------------------------------------------------');
  31.     end;
  32.   end;
  33.  
  34.  
  35.  
  36. procedure caricare;
  37.   begin
  38.  
  39.     for j:=1 to 6 do
  40.      begin
  41.         writeln;
  42.         for i:=1 to 9 do
  43.           begin
  44.              log[j,i]:=2;
  45.           end;
  46.      end;
  47.  
  48.  
  49.     i:=0;
  50.     cancella:='                                                                    ';
  51.     cont:=0;
  52.     vinx:=false;
  53.     viny:=false;
  54.     fine:=false;
  55.     a:=4;
  56.     b:=2;
  57.   end;
  58.  
  59.  
  60.  
  61. procedure check;
  62.   begin
  63.  
  64.      for j:=1 to 6 do
  65.       begin
  66.           for i:=1 to 6 do
  67.            begin
  68.               if (log[j,i]=1) and (log[j,i+1]=1) and (log[j,i+2]=1) and (log[j,i+3]=1)
  69.                 then vinx:=true;
  70.  
  71.               if (log[j,i]=3) and (log[j,i+1]=3) and (log[j,i+2]=3) and (log[j,i+3]=3)
  72.                 then viny:=true;
  73.  
  74.            end;
  75.        end;
  76.  
  77.  
  78.      for i:=1 to 9 do
  79.       begin
  80.           for j:=1 to 3 do
  81.            begin
  82.               if (log[j,i]=1) and (log[j+1,i]=1) and (log[j+2,i]=1) and (log[j+3,i]=1)
  83.                 then vinx:=true;
  84.  
  85.               if (log[j,i]=3) and (log[j+1,i]=3) and (log[j+2,i]=3) and (log[j+3,i]=3)
  86.                 then viny:=true;
  87.            end;
  88.        end;
  89.  
  90.  
  91.  
  92.     for j:=1 to 6 do
  93.      begin
  94.         for i:=1 to 9 do
  95.           begin
  96.              if (j>=4) and (i<=6)
  97.               then
  98.                 begin
  99.                    if (log[j,i]=1) and (log[j-1,i+1]=1) and (log[j-2,i+2]=1) and (log[j-3,i+3]=1)
  100.                      then vinx:=true;
  101.  
  102.                    if (log[j,i]=3) and (log[j-1,i+1]=3) and (log[j-2,i+2]=3) and (log[j-3,i+3]=3)
  103.                      then viny:=true;
  104.                 end;
  105.  
  106.           end;
  107.  
  108.      end;
  109.  
  110.  
  111.  
  112.     for j:=1 to 6 do
  113.      begin
  114.         for i:=1 to 9 do
  115.           begin
  116.              if (j<=3) and (i<=6)
  117.               then
  118.                 begin
  119.                    if (log[j,i]=1) and (log[j+1,i+1]=1) and (log[j+2,i+2]=1) and (log[j+3,i+3]=1)
  120.                      then vinx:=true;
  121.  
  122.                    if (log[j,i]=3) and (log[j+1,i+1]=3) and (log[j+2,i+2]=3) and (log[j+3,i+3]=3)
  123.                      then viny:=true;
  124.                 end;
  125.  
  126.           end;
  127.  
  128.      end;
  129.  
  130.   end;
  131.  
  132.  
  133. procedure movimento;
  134.   begin
  135.       if (cont=1)
  136.        then
  137.          begin
  138.           b:=2;
  139.           a:=4;
  140.          end
  141.         else gotoxy(a,b);
  142.  
  143. finito:=false;
  144.  repeat
  145.  
  146.  
  147.     tasto:=readkey;
  148.      if tasto=char(0)
  149.       then tasto:=readkey;
  150.  
  151.     if tasto=char(77)
  152.      then
  153.        begin
  154.           a:=a+8;
  155.             if a=76
  156.              then a:=68
  157.              else gotoxy(a,b);
  158.        end;
  159.  
  160.     if tasto=char(75)
  161.      then
  162.        begin
  163.           a:=a-8;
  164.           if a=-4
  165.            then a:=4
  166.            else gotoxy(a,b);
  167.        end;
  168.  
  169.  
  170.     if tasto='a'
  171.      then finito:=true;
  172.  
  173.  until finito;
  174.    end;
  175.  
  176.  
  177.  
  178. procedure ass_logica;
  179.  var r,k,prov:integer; esci:boolean;
  180.   begin
  181.  
  182.    esci:=false;
  183.    prov:=(a-4) div 8;
  184.    k:=prov+1;
  185.    r:=7;
  186.  
  187.     repeat
  188.       r:=r-1;
  189.        if (log[r,k]=2)
  190.         then
  191.           begin
  192.             log[r,k]:=val_log;
  193.             esci:=true;
  194.           end;
  195.  
  196.     until esci=true;
  197.  
  198.    r:=r-1;
  199.    bb:=b+(r*5);
  200.  
  201.   end;
  202.  
  203.  
  204. procedure croce_o_cerchio;
  205.  begin
  206.  
  207.  
  208.  
  209.        if cont mod 2 =1
  210.         then
  211.           begin
  212.            gotoxy(a,bb);
  213.            writeln('\/');
  214.            gotoxy(a,(bb+1));
  215.            writeln('/\');
  216.            gotoxy(a,bb);
  217.            end
  218.           else
  219.            begin
  220.              gotoxy(a,bb);
  221.              writeln('OO');
  222.              gotoxy(a,(bb+1));
  223.              writeln('OO');
  224.              gotoxy(a,bb);
  225.            end;
  226.  
  227.  end;
  228.  
  229.  
  230.  
  231.  
  232. procedure scritte;
  233.   begin
  234.     if (vinx=false) and (viny=false)
  235.      then
  236.        begin
  237.         gotoxy(2,34);
  238.         writeln(cancella);
  239.         gotoxy(2,34);
  240.         writeln('tocca al giocatore ',numero,': ',nome,'   premi "a" per confermare');
  241.         gotoxy(a,b);
  242.        end;
  243.        if (vinx=true) or (viny=true)
  244.         then
  245.           begin
  246.              gotoxy(2,34);
  247.              writeln(cancella);
  248.              gotoxy(2,34);
  249.              writeln('IL GIOCATORE ',numero,': ',nome,', HA VINTO!');
  250.              writeln();
  251.           end
  252.          else gotoxy(a,b);
  253.  
  254.        if (fine) and (vinx=false) and (viny=false)
  255.          then
  256.           begin
  257.              gotoxy(2,34);
  258.              writeln(cancella);
  259.              gotoxy(2,34);
  260.              writeln('PARTITA PARI');
  261.              writeln();
  262.           end;
  263.      end;
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. begin
  271. repeat
  272. intestazione;
  273. struttura;
  274. caricare;
  275.  
  276.  repeat
  277.  
  278.  
  279.  
  280.   cont:=cont+1;
  281.     if cont mod 2=1
  282.      then
  283.        begin
  284.          numero:=1;
  285.          nome:=x;
  286.          val_log:=1;
  287.        end
  288.      else
  289.       begin
  290.         numero:=2;
  291.         nome:=y;
  292.         val_log:=3;
  293.       end;
  294.  
  295.      scritte;
  296.  
  297.      movimento;
  298.  
  299.      ass_logica;
  300.  
  301.      croce_o_cerchio;
  302.  
  303.       check;
  304.  
  305.       scritte;
  306.  
  307.   until (cont=54) or (vinx=true) or (viny=true);
  308.  
  309.  
  310. repeat
  311. gotoxy(2,36);
  312. writeln(cancella);
  313. gotoxy(2,36);
  314. writeln('vuoi fare un''altra partita?  <s/n>');
  315.  
  316. readln(risp);
  317.  
  318. until (risp='s') or (risp='n');
  319.  
  320. clrscr;
  321.  
  322. until risp='n';
  323.  
  324. end.