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 con input da mouse - tris.pas

tris.pas

Caricato da: Leodema98
Scarica il programma completo

  1. Program tris;
  2. uses crt,mouse;
  3.  
  4. var pareggio:boolean;
  5.     g1,g2:string[15];
  6.     r,e,i:byte;
  7.     p1,p2:integer;
  8.     sim:char;
  9.     n:array [1..9] of char;
  10.  
  11. procedure init_mouse;
  12. var i:byte;
  13.  
  14. begin (*inizializza il mouse*)
  15.   initmouse;
  16.   i:=detectmouse;
  17.   if i=0 then
  18.     begin
  19.     donemouse;
  20.     writeln('ERRORE')
  21.     end
  22.          else
  23.     setmousexy(0,0)
  24. end;
  25.  
  26.  
  27. procedure write_tris;
  28.  
  29. begin (*Output delle caselle di gioco*)
  30.   gotoxy(1,5);
  31.   writeln('      ³     ³     ');
  32.   writeln('      ³     ³     ');
  33.   writeln('      ³     ³     ');
  34.   writeln(' ÄÄÄÄÄÅÄÄÄÄÄÅÄÄÄÄÄ');
  35.   writeln('      ³     ³     ');
  36.   writeln('      ³     ³     ');
  37.   writeln('      ³     ³     ');
  38.   writeln(' ÄÄÄÄÄÅÄÄÄÄÄÅÄÄÄÄÄ');
  39.   writeln('      ³     ³     ');
  40.   writeln('      ³     ³     ');
  41.     write('      ³     ³     ')
  42. end;
  43.  
  44.  
  45. function read_tris:byte;
  46.  
  47. var x,y:byte;
  48.     eventi:tmouseevent;
  49.  
  50. begin (*Input delle caselle di gioco*)
  51.   read_tris:=0;
  52.   repeat
  53.     getmouseevent(eventi);
  54.     for x:=2 to 6 do
  55.       for y:=5 to 7 do
  56.         begin
  57.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  58.           read_tris:=1
  59.         end;
  60.     for x:=8 to 12 do
  61.       for y:=5 to 7 do
  62.         begin
  63.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  64.           read_tris:=2
  65.         end;
  66.     for x:=14 to 18 do
  67.       for y:=5 to 7 do
  68.         begin
  69.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  70.           read_tris:=3
  71.         end;
  72.     for x:=2 to 6 do
  73.       for y:=9 to 11 do
  74.         begin
  75.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  76.           read_tris:=4
  77.         end;
  78.     for x:=8 to 12 do
  79.       for y:=9 to 11 do
  80.         begin
  81.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  82.           read_tris:=5
  83.         end;
  84.     for x:=14 to 18 do
  85.       for y:=9 to 11 do
  86.         begin
  87.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  88.           read_tris:=6
  89.         end;
  90.     for x:=2 to 6 do
  91.       for y:=13 to 15 do
  92.         begin
  93.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  94.           read_tris:=7
  95.         end;
  96.     for x:=8 to 12 do
  97.       for y:=13 to 15 do
  98.         begin
  99.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  100.           read_tris:=8
  101.         end;
  102.     for x:=14 to 18 do
  103.       for y:=13 to 15 do
  104.         begin
  105.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  106.           read_tris:=9
  107.         end
  108.   until read_tris<>0
  109. end;
  110.  
  111.  
  112. procedure write_end;
  113.  
  114. begin (*Output delle caselle di fine partita*)
  115.   gotoxy(22,6);
  116.   write('ÚÄÄÄÄÄÄÄÄÄÄ¿');
  117.   gotoxy(22,7);
  118.   write('³ CONTINUA ³ ');
  119.   gotoxy(22,8);
  120.   write('ÀÄÄÄÄÄÄÄÄÄÄÙ ');
  121.   gotoxy(22,9);
  122.   write('ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿');
  123.   gotoxy(22,10);
  124.   write('³ NUOVA PARTITA ³ ');
  125.   gotoxy(22,11);
  126.   write('ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ');
  127.   gotoxy(22,12);
  128.   write('ÚÄÄÄÄÄÄ¿');
  129.   gotoxy(22,13);
  130.   write('³ ESCI ³ ');
  131.   gotoxy(22,14);
  132.   write('ÀÄÄÄÄÄÄÙ ')
  133. end;
  134.  
  135.  
  136. procedure delete_end;
  137.  
  138. begin (*Output che cancella le caselle di fine partita*)
  139.   gotoxy(22,6);
  140.   clreol;
  141.   gotoxy(22,7);
  142.   clreol;
  143.   gotoxy(22,8);
  144.   clreol;
  145.   gotoxy(22,9);
  146.   clreol;
  147.   gotoxy(22,10);
  148.   clreol;
  149.   gotoxy(22,11);
  150.   clreol;
  151.   gotoxy(22,12);
  152.   clreol;
  153.   gotoxy(22,13);
  154.   clreol;
  155.   gotoxy(22,14);
  156.   clreol
  157. end;
  158.  
  159. function read_end:byte;
  160.  
  161. var x,y:byte;
  162.     eventi:tmouseevent;
  163.  
  164. begin (*Input delle caselle di fine partita*)
  165.   read_end:=0;
  166.   repeat
  167.     getmouseevent(eventi);
  168.     for x:=22 to 33 do
  169.       for y:=6 to 8 do
  170.         begin
  171.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  172.           read_end:=1
  173.         end;
  174.     for x:=22 to 38 do
  175.       for y:=9 to 11 do
  176.         begin
  177.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  178.           read_end:=2
  179.         end;
  180.     for x:=22 to 29 do
  181.       for y:=12 to 14 do
  182.         begin
  183.         if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
  184.           read_end:=3
  185.         end
  186.   until read_end<>0
  187. end;
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. begin (*programma*)
  195.   repeat
  196.     repeat
  197.       clrscr;
  198.       writeln('          TRIS v1.0');
  199.       writeln;
  200.       writeln;
  201.       write('Inserisci il nome del giocatore 1: ');
  202.       readln(g1);
  203.       writeln;
  204.       write('Inserisci il nome del giocatore 2: ');
  205.       readln(g2);
  206.       if ( (g1='') or (g2='') ) and (g1=g2) then
  207.         begin
  208.         writeln;
  209.         write('Uno o piu'' campi sono stati lasciati vuoti e');
  210.         write('i due nomi devono essere diversi.');
  211.         readln
  212.         end
  213.                                             else
  214.         begin
  215.         if (g1='') or (g2='') then
  216.           begin
  217.           writeln;
  218.           write('Uno o piu'' campi sono stati lasciati vuoti.');
  219.           readln
  220.           end;
  221.         if g1=g2 then
  222.           begin
  223.           writeln;
  224.           write('I due nomi devono essere diversi.');
  225.           readln
  226.           end
  227.         end
  228.     until (g1<>'') and (g2<>'') and (g1<>g2);
  229.     clrscr;
  230.     init_mouse;
  231.     cursoroff;
  232.     p1:=0;
  233.     p2:=0;
  234.     sim:='O';
  235.     gotoxy(1,1);
  236.     clreol;
  237.     write(g1,': ',p1,'   ',g2,': ',p2);
  238.     repeat
  239.       write_tris;
  240.       delete_end;
  241.       for i:=1 to 9 do
  242.         n[i]:='v';
  243.       repeat
  244.         if (n[1]<>'v') and (n[2]<>'v') and (n[3]<>'v') and (n[4]<>'v') and (n[5]<>'v') and (n[6]<>'v') and (n[7]<>'v') and (n[8]<>'v') and (n[9]<>'v') then
  245.           begin
  246.           pareggio:=true;
  247.           break
  248.           end;
  249.         if sim='X' then
  250.           sim:='O'
  251.                    else
  252.           sim:='X';
  253.         gotoxy(1,3);
  254.         clreol;
  255.         write('E'' il turno di ');
  256.         if sim='X' then
  257.           write(g1,'.')
  258.                    else
  259.           write(g2,'.');
  260.         repeat
  261.           r:=read_tris
  262.         until n[r]='v';
  263.         n[r]:=sim;
  264.         case r of
  265.           1:begin
  266.               gotoxy(4,6);
  267.               write(sim)
  268.             end;
  269.           2:begin
  270.               gotoxy(10,6);
  271.               write(sim)
  272.             end;
  273.           3:begin
  274.               gotoxy(16,6);
  275.               write(sim)
  276.             end;
  277.           4:begin
  278.               gotoxy(4,10);
  279.               write(sim)
  280.             end;
  281.           5:begin
  282.               gotoxy(10,10);
  283.               write(sim)
  284.             end;
  285.           6:begin
  286.               gotoxy(16,10);
  287.               write(sim)
  288.             end;
  289.           7:begin
  290.               gotoxy(4,14);
  291.               write(sim)
  292.             end;
  293.           8:begin
  294.               gotoxy(10,14);
  295.               write(sim)
  296.             end;
  297.           9:begin
  298.               gotoxy(16,14);
  299.               write(sim)
  300.             end
  301.         end
  302.       until ( (n[1]=sim) and (n[2]=sim) and (n[3]=sim) ) or
  303.             ( (n[4]=sim) and (n[5]=sim) and (n[6]=sim) ) or
  304.             ( (n[7]=sim) and (n[8]=sim) and (n[9]=sim) ) or
  305.             ( (n[1]=sim) and (n[4]=sim) and (n[7]=sim) ) or
  306.             ( (n[2]=sim) and (n[5]=sim) and (n[8]=sim) ) or
  307.             ( (n[3]=sim) and (n[6]=sim) and (n[9]=sim) ) or
  308.             ( (n[1]=sim) and (n[5]=sim) and (n[9]=sim) ) or
  309.             ( (n[3]=sim) and (n[5]=sim) and (n[7]=sim) );
  310.       if pareggio=true then
  311.         begin
  312.         gotoxy(1,3);
  313.         clreol;
  314.         write('Pareggio.');
  315.         pareggio:=false;
  316.         end
  317.                        else
  318.         begin
  319.         if sim='X' then
  320.           p1:=p1+1
  321.                    else
  322.           p2:=p2+1;
  323.         gotoxy(1,1);
  324.         clreol;
  325.         write(g1,': ',p1,'   ',g2,': ',p2);
  326.         gotoxy(1,3);
  327.         clreol;
  328.         write('Ha vinto ');
  329.         if sim='X' then
  330.           write(g1,'.')
  331.                    else
  332.           write(g2,'.')
  333.         end;
  334.       write_end;
  335.       e:=read_end
  336.     until (e=2) or (e=3);
  337.     donemouse;
  338.     clrscr;
  339.     cursoron;
  340.     gotoxy(1,3);
  341.     if p1=p2 then
  342.       write('Pareggio.')
  343.              else
  344.       begin
  345.       write('Ha vinto ');
  346.       if p1>p2 then
  347.       write(g1,'.')
  348.                else
  349.       write(g2,'.')
  350.       end;
  351.     gotoxy(1,5);
  352.     write(g1,': ',p1);
  353.     gotoxy(1,6);
  354.     write(g2,': ',p2);
  355.     gotoxy(1,8);
  356.     write('Premi INVIO per continuare.');
  357.     readln
  358.   until e=3
  359. end.