|
Program tris;
uses crt,mouse;
var pareggio:boolean;
g1,g2:string[15];
r,e,i:byte;
p1,p2:integer;
sim:char;
n:array [1..9] of char;
procedure init_mouse;
var i:byte;
begin (*inizializza il mouse*)
initmouse;
i:=detectmouse;
if i=0 then
begin
donemouse;
writeln('ERRORE')
end
else
setmousexy(0,0)
end;
procedure write_tris;
begin (*Output delle caselle di gioco*)
gotoxy(1,5);
writeln(' ³ ³ ');
writeln(' ³ ³ ');
writeln(' ³ ³ ');
writeln(' ÄÄÄÄÄÅÄÄÄÄÄÅÄÄÄÄÄ');
writeln(' ³ ³ ');
writeln(' ³ ³ ');
writeln(' ³ ³ ');
writeln(' ÄÄÄÄÄÅÄÄÄÄÄÅÄÄÄÄÄ');
writeln(' ³ ³ ');
writeln(' ³ ³ ');
write(' ³ ³ ')
end;
function read_tris:byte;
var x,y:byte;
eventi:tmouseevent;
begin (*Input delle caselle di gioco*)
read_tris:=0;
repeat
getmouseevent(eventi);
for x:=2 to 6 do
for y:=5 to 7 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=1
end;
for x:=8 to 12 do
for y:=5 to 7 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=2
end;
for x:=14 to 18 do
for y:=5 to 7 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=3
end;
for x:=2 to 6 do
for y:=9 to 11 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=4
end;
for x:=8 to 12 do
for y:=9 to 11 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=5
end;
for x:=14 to 18 do
for y:=9 to 11 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=6
end;
for x:=2 to 6 do
for y:=13 to 15 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=7
end;
for x:=8 to 12 do
for y:=13 to 15 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=8
end;
for x:=14 to 18 do
for y:=13 to 15 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_tris:=9
end
until read_tris<>0
end;
procedure write_end;
begin (*Output delle caselle di fine partita*)
gotoxy(22,6);
write('ÚÄÄÄÄÄÄÄÄÄÄ¿');
gotoxy(22,7);
write('³ CONTINUA ³ ');
gotoxy(22,8);
write('ÀÄÄÄÄÄÄÄÄÄÄÙ ');
gotoxy(22,9);
write('ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿');
gotoxy(22,10);
write('³ NUOVA PARTITA ³ ');
gotoxy(22,11);
write('ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ');
gotoxy(22,12);
write('ÚÄÄÄÄÄÄ¿');
gotoxy(22,13);
write('³ ESCI ³ ');
gotoxy(22,14);
write('ÀÄÄÄÄÄÄÙ ')
end;
procedure delete_end;
begin (*Output che cancella le caselle di fine partita*)
gotoxy(22,6);
clreol;
gotoxy(22,7);
clreol;
gotoxy(22,8);
clreol;
gotoxy(22,9);
clreol;
gotoxy(22,10);
clreol;
gotoxy(22,11);
clreol;
gotoxy(22,12);
clreol;
gotoxy(22,13);
clreol;
gotoxy(22,14);
clreol
end;
function read_end:byte;
var x,y:byte;
eventi:tmouseevent;
begin (*Input delle caselle di fine partita*)
read_end:=0;
repeat
getmouseevent(eventi);
for x:=22 to 33 do
for y:=6 to 8 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_end:=1
end;
for x:=22 to 38 do
for y:=9 to 11 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_end:=2
end;
for x:=22 to 29 do
for y:=12 to 14 do
begin
if (eventi.buttons=1) and (eventi.x=x) and (eventi.y=y) then
read_end:=3
end
until read_end<>0
end;
begin (*programma*)
repeat
repeat
clrscr;
writeln(' TRIS v1.0');
writeln;
writeln;
write('Inserisci il nome del giocatore 1: ');
readln(g1);
writeln;
write('Inserisci il nome del giocatore 2: ');
readln(g2);
if ( (g1='') or (g2='') ) and (g1=g2) then
begin
writeln;
write('Uno o piu'' campi sono stati lasciati vuoti e');
write('i due nomi devono essere diversi.');
readln
end
else
begin
if (g1='') or (g2='') then
begin
writeln;
write('Uno o piu'' campi sono stati lasciati vuoti.');
readln
end;
if g1=g2 then
begin
writeln;
write('I due nomi devono essere diversi.');
readln
end
end
until (g1<>'') and (g2<>'') and (g1<>g2);
clrscr;
init_mouse;
cursoroff;
p1:=0;
p2:=0;
sim:='O';
gotoxy(1,1);
clreol;
write(g1,': ',p1,' ',g2,': ',p2);
repeat
write_tris;
delete_end;
for i:=1 to 9 do
n[i]:='v';
repeat
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
begin
pareggio:=true;
break
end;
if sim='X' then
sim:='O'
else
sim:='X';
gotoxy(1,3);
clreol;
write('E'' il turno di ');
if sim='X' then
write(g1,'.')
else
write(g2,'.');
repeat
r:=read_tris
until n[r]='v';
n[r]:=sim;
case r of
1:begin
gotoxy(4,6);
write(sim)
end;
2:begin
gotoxy(10,6);
write(sim)
end;
3:begin
gotoxy(16,6);
write(sim)
end;
4:begin
gotoxy(4,10);
write(sim)
end;
5:begin
gotoxy(10,10);
write(sim)
end;
6:begin
gotoxy(16,10);
write(sim)
end;
7:begin
gotoxy(4,14);
write(sim)
end;
8:begin
gotoxy(10,14);
write(sim)
end;
9:begin
gotoxy(16,14);
write(sim)
end
end
until ( (n[1]=sim) and (n[2]=sim) and (n[3]=sim) ) or
( (n[4]=sim) and (n[5]=sim) and (n[6]=sim) ) or
( (n[7]=sim) and (n[8]=sim) and (n[9]=sim) ) or
( (n[1]=sim) and (n[4]=sim) and (n[7]=sim) ) or
( (n[2]=sim) and (n[5]=sim) and (n[8]=sim) ) or
( (n[3]=sim) and (n[6]=sim) and (n[9]=sim) ) or
( (n[1]=sim) and (n[5]=sim) and (n[9]=sim) ) or
( (n[3]=sim) and (n[5]=sim) and (n[7]=sim) );
if pareggio=true then
begin
gotoxy(1,3);
clreol;
write('Pareggio.');
pareggio:=false;
end
else
begin
if sim='X' then
p1:=p1+1
else
p2:=p2+1;
gotoxy(1,1);
clreol;
write(g1,': ',p1,' ',g2,': ',p2);
gotoxy(1,3);
clreol;
write('Ha vinto ');
if sim='X' then
write(g1,'.')
else
write(g2,'.')
end;
write_end;
e:=read_end
until (e=2) or (e=3);
donemouse;
clrscr;
cursoron;
gotoxy(1,3);
if p1=p2 then
write('Pareggio.')
else
begin
write('Ha vinto ');
if p1>p2 then
write(g1,'.')
else
write(g2,'.')
end;
gotoxy(1,5);
write(g1,': ',p1);
gotoxy(1,6);
write(g2,': ',p2);
gotoxy(1,8);
write('Premi INVIO per continuare.');
readln
until e=3
end.
|
|