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
TRIS 1.0 fra due giocatori - tris.pas

tris.pas

Caricato da: Punkettone90
Scarica il programma completo

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