|
program forza_4;
uses crt;
var log:array[1..6,1..9] of integer;
i,j,a,b,cont,numero,val_log,bb:integer;
tasto,risp:char;
finito,vinx,viny,fine:boolean;
cancella,nome,x,y:string;
procedure intestazione;
begin
writeln('BENVENUTO NEL GIOCO DEL FORZA 4');
writeln();
write('come ti chiami 1 giocatore? ');
readln(x);
write('come ti chiami 2 giocatore? ');
readln(y);
clrscr;
end;
procedure struttura;
begin
for i:=1 to 6 do
begin
for j:=1 to 4 do
begin
writeln(' | | | | | | | | |');
end;
writeln('---------------------------------------------------------------------------');
end;
end;
procedure caricare;
begin
for j:=1 to 6 do
begin
writeln;
for i:=1 to 9 do
begin
log[j,i]:=2;
end;
end;
i:=0;
cancella:=' ';
cont:=0;
vinx:=false;
viny:=false;
fine:=false;
a:=4;
b:=2;
end;
procedure check;
begin
for j:=1 to 6 do
begin
for i:=1 to 6 do
begin
if (log[j,i]=1) and (log[j,i+1]=1) and (log[j,i+2]=1) and (log[j,i+3]=1)
then vinx:=true;
if (log[j,i]=3) and (log[j,i+1]=3) and (log[j,i+2]=3) and (log[j,i+3]=3)
then viny:=true;
end;
end;
for i:=1 to 9 do
begin
for j:=1 to 3 do
begin
if (log[j,i]=1) and (log[j+1,i]=1) and (log[j+2,i]=1) and (log[j+3,i]=1)
then vinx:=true;
if (log[j,i]=3) and (log[j+1,i]=3) and (log[j+2,i]=3) and (log[j+3,i]=3)
then viny:=true;
end;
end;
for j:=1 to 6 do
begin
for i:=1 to 9 do
begin
if (j>=4) and (i<=6)
then
begin
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)
then vinx:=true;
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)
then viny:=true;
end;
end;
end;
for j:=1 to 6 do
begin
for i:=1 to 9 do
begin
if (j<=3) and (i<=6)
then
begin
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)
then vinx:=true;
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)
then viny:=true;
end;
end;
end;
end;
procedure movimento;
begin
if (cont=1)
then
begin
b:=2;
a:=4;
end
else gotoxy(a,b);
finito:=false;
repeat
tasto:=readkey;
if tasto=char(0)
then tasto:=readkey;
if tasto=char(77)
then
begin
a:=a+8;
if a=76
then a:=68
else gotoxy(a,b);
end;
if tasto=char(75)
then
begin
a:=a-8;
if a=-4
then a:=4
else gotoxy(a,b);
end;
if tasto='a'
then finito:=true;
until finito;
end;
procedure ass_logica;
var r,k,prov:integer; esci:boolean;
begin
esci:=false;
prov:=(a-4) div 8;
k:=prov+1;
r:=7;
repeat
r:=r-1;
if (log[r,k]=2)
then
begin
log[r,k]:=val_log;
esci:=true;
end;
until esci=true;
r:=r-1;
bb:=b+(r*5);
end;
procedure croce_o_cerchio;
begin
if cont mod 2 =1
then
begin
gotoxy(a,bb);
writeln('\/');
gotoxy(a,(bb+1));
writeln('/\');
gotoxy(a,bb);
end
else
begin
gotoxy(a,bb);
writeln('OO');
gotoxy(a,(bb+1));
writeln('OO');
gotoxy(a,bb);
end;
end;
procedure scritte;
begin
if (vinx=false) and (viny=false)
then
begin
gotoxy(2,34);
writeln(cancella);
gotoxy(2,34);
writeln('tocca al giocatore ',numero,': ',nome,' premi "a" per confermare');
gotoxy(a,b);
end;
if (vinx=true) or (viny=true)
then
begin
gotoxy(2,34);
writeln(cancella);
gotoxy(2,34);
writeln('IL GIOCATORE ',numero,': ',nome,', HA VINTO!');
writeln();
end
else gotoxy(a,b);
if (fine) and (vinx=false) and (viny=false)
then
begin
gotoxy(2,34);
writeln(cancella);
gotoxy(2,34);
writeln('PARTITA PARI');
writeln();
end;
end;
begin
repeat
intestazione;
struttura;
caricare;
repeat
cont:=cont+1;
if cont mod 2=1
then
begin
numero:=1;
nome:=x;
val_log:=1;
end
else
begin
numero:=2;
nome:=y;
val_log:=3;
end;
scritte;
movimento;
ass_logica;
croce_o_cerchio;
check;
scritte;
until (cont=54) or (vinx=true) or (viny=true);
repeat
gotoxy(2,36);
writeln(cancella);
gotoxy(2,36);
writeln('vuoi fare un''altra partita? <s/n>');
readln(risp);
until (risp='s') or (risp='n');
clrscr;
until risp='n';
end.
|
|