guardar/cargar partida pascal, urgente!!
Publicado por lara (1 intervención) el 05/05/2013 19:26:50
Hola, tengo que hacer el clásico juego de hundir la flota (que ya le tengo hecho), pero ahora necesito que uno de mis dos jugadores pueda guardar la partida cuando quiera y reanudarla tambien cuando quiera, y estoy bastante perdida. Agradeceria mucho que me echaseis una mano. Gracias por adelanteado!!!
esto es lo que tengo hasta ahora:
program hundir_la_flota;
uses
crt;
type
tipo_tablero1 = array [1..8,1..8] of string;
var
tablero_B1:tipo_tablero1;
tablero_B2:tipo_tablero1;
tablero_D1:tipo_tablero1;
tablero_D2:tipo_tablero1;
tablero_T1:tipo_tablero1;
tablero_T2:tipo_tablero1;
i:integer;
j:integer;
k:integer;
contador1 : integer;
contador2 :integer;
direc:string;
b:tipo_tablero1;
t:tipo_tablero1;
mb : tipo_tablero1;
fin : real;
fin1 : real;
fin2 : real;
b1 : tipo_tablero1;
b2 : tipo_tablero1;
d1 : tipo_tablero1;
d2 : tipo_tablero1;
t1 : tipo_tablero1;
t2 : tipo_tablero1;
procedure inicia_tablero_barcos (var tb : tipo_tablero1);
{inicia el tablero de barcos con todos los valores agua A}
var
i,j:integer;
begin
for i := 1 to 8 do
for j:= 1 to 8 do
begin
tb[i,j] := 'A';
end;
end;
procedure inicia_tablero_control (var td : tipo_tablero1);
{inicia el tablero de los barcos bombardeados con todos las posiciones sin marcar X}
var
i,j:integer;
begin
for i:=1 to 8 do
for j:= 1 to 8 do
begin
td[i,j] := 'X';
end;
end;
procedure inicia_tablero_tamano (var tt: tipo_tablero1);
{inicia el tablero de las dimensiones de los barcos con todas las posiciones 0}
var
i,j : integer;
begin
for i:=1 to 8 do
for j:=1 to 8 do
begin
tt[i,j] := ' ';
end;
end;
procedure introducir_barcos (var b : tipo_tablero1; var t : tipo_tablero1);
{creamos las posiciones de nuestros barcos}
var
i:integer;
j:integer;
k:integer;
direc:string;
begin writeln;
writeln('barco de DIMENSION 1');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
b[i,j] := 'B';
t[i,j] := 'UNO';
writeln;
writeln('barco de DIMENSION 2');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
writeln;
writeln('DIRECCION: arriba/abajo/izquierda/derecha ');
readln(direc);
if direc = 'izquierda' then
for j:=j downto 2 do
begin
b[i,j] := 'B';
t[i,j] := 'DOS';
end
else
if direc = 'derecha' then
for j:=j to 2 do
begin
b[i,j]:='B';
t[i,j]:='DOS';
end
else
if direc = 'arriba' then
for i:=i downto 2 do
begin
b[i,j]:='B';
t[i,j]:='DOS';
end
else
if direc = 'abajo' then
for i:=i to 2 do
begin
b[i,j]:='B';
t[i,j]:='DOS';
end;
writeln;
writeln('barco de DIMENSION 3');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
writeln;
writeln('DIRECCION: arriba/abajo/izquierda/derecha');
readln(direc);
if direc = 'izquierda' then
for j:=j downto 3 do
begin
b[i,j] := 'B';
t[i,j] := 'TRES';
end
else
if direc = 'derecha' then
for j:=j to 3 do
begin
b[i,j]:='B';
t[i,j]:='TRES';
end
else
if direc = 'arriba' then
for i:=i downto 3 do
begin
b[i,j]:='B';
t[i,j]:='TRES';
end
else
if direc = 'abajo' then
for i:=i to 3 do
begin
b[i,j]:='B';
t[i,j]:='TRES';
end;
writeln;
writeln('barco de DIMENSION 4');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
writeln;
writeln('DIRECCION: arriba/abajo/izquierda/derecha ');
readln(direc);
if direc = 'izquierda' then
for j:=j downto 4 do
begin
b[i,j] := 'B';
t[i,j] := 'CUATRO';
end
else
if direc = 'derecha' then
for j:=j to 4 do
begin
b[i,j]:='B';
t[i,j]:='CUATRO';
end
else
if direc = 'arriba' then
for i:=i downto 4 do
begin
b[i,j]:='B';
t[i,j]:='CUATRO';
end
else
if direc = 'abajo' then
for i:=i to 4 do
begin
b[i,j]:='B';
t[i,j]:='CUATRO';
end;
end;
procedure muestra_bombardeados (var mb: tipo_tablero1);
var
i,j:integer;
begin
for i:= 1 to 8 do
begin
for j:= 1 to 8 do
begin
write(mb[i,j],' ');
end;
writeln;
end;
end;
procedure dispara (var b1:tipo_tablero1;
var b2:tipo_tablero1;
var d1:tipo_tablero1;
var d2:tipo_tablero1;
var t1:tipo_tablero1;
var t2:tipo_tablero1);
{iniciamos el juego}
var
i,j: integer;
contador1 :integer;
contador2 :integer;
fin : real;
fin1 : real;
fin2 : real;
begin
contador1 :=0;
contador2 :=0;
begin
while fin <>1 do
begin
fin1 :=4;
fin2 :=4;
repeat
begin
writeln;
writeln('turno JUGADOR 1');
writeln;
writeln('su tablero de control de disparos es: ');
begin
muestra_bombardeados(d1)
end;
repeat
writeln;
writeln('introduzca la coordenada FILA del barco a atacar: ');
readln(i);
if i>8 then
begin
writeln;
writeln('esta fuera del rango, intentelo de nuevo');
end;
until i<=8;
repeat
writeln;
writeln('introduzca la coordenada COLUMNA del barco a atacar: ');
readln(j);
if j>8 then
begin
writeln;
writeln('esta fuera del rango, intentelo de nuevo');
end;
until j<=8;
if b2[i,j]='B' then
begin writeln;
writeln('has alcanzado un BARCO de dimension ',t2[i,j]);
d1[i,j]:='B';
contador1 := contador1 + 1;
end
else
begin
writeln;
writeln('AGUA');
writeln;
writeln('fin de tu turno ');
d1[i,j]:='A';
end;
if b2[i,j]<> 'B' then
begin
fin1 := 2;
end;
if contador1 >=10 then
begin
fin1 := 2;
writeln;
writeln('GANADOR jugador 1');
writeln;
writeln('FELICIDADES!');
end;
end;
until fin1 = 2;
if contador1 >= 10 then
begin
fin := 1
end;
if contador1 <10 then
begin
repeat
begin
writeln;
writeln('turno JUGADOR 2');
writeln;
writeln('su tablero de control de disparos es: ');
begin
muestra_bombardeados(d2)
end;
repeat
writeln;
writeln('introduce la coordenada fila del barco a atacar: ');
readln(i);
if i>8 then
begin
writeln;
writeln('esta fuera del rango');
end;
until i<=8;
repeat
writeln;
writeln('introduce la coordenada columna del barco a atacar: ');
readln(j);
if j>8 then
begin
writeln;
writeln('esta fuera del rango');
end;
until j<=8;
if b1[i,j]='B' then
begin writeln;
writeln('has alcanzado un BARCO de dimension ',t1[i,j]);
d2[i,j]:='B';
contador2 := contador2 +1;
end
else
begin
writeln;
writeln('AGUA');
writeln;
writeln('fin de su turno ');
d2[i,j]:='A';
end;
if b1[i,j]<>'B' then
begin
fin2:=2;
end;
if contador2>=10 then
begin
fin2 := 2;
writeln;
writeln('GANADOR jugador 2');
writeln;
writeln('FELICIDADES!');
end;
end;
until fin2 = 2;
end;
if contador2>=10 then
begin
fin := 1;
end;
end;
end;
end;
begin (*del programa principal*);
writeln('BIENVENIDO A HUNDIR LA FLOTA');
inicia_tablero_barcos(tablero_B1);
inicia_tablero_barcos(tablero_B2);
inicia_tablero_control(tablero_D1);
inicia_tablero_control(tablero_D2);
inicia_tablero_tamano(tablero_T1);
inicia_tablero_tamano(tablero_T2);
writeln;
writeln('JUGADOR 1 introduzca sus barcos');
writeln;
introducir_barcos(tablero_B1,tablero_T1);
writeln;
writeln('JUGADOR 2 introduzca sus barcos');
writeln;
introducir_barcos(tablero_B2,tablero_T2);
dispara(tablero_B1,tablero_B2,tablero_D1,tablero_D2,tablero_T1,tablero_T2);
end.
esto es lo que tengo hasta ahora:
program hundir_la_flota;
uses
crt;
type
tipo_tablero1 = array [1..8,1..8] of string;
var
tablero_B1:tipo_tablero1;
tablero_B2:tipo_tablero1;
tablero_D1:tipo_tablero1;
tablero_D2:tipo_tablero1;
tablero_T1:tipo_tablero1;
tablero_T2:tipo_tablero1;
i:integer;
j:integer;
k:integer;
contador1 : integer;
contador2 :integer;
direc:string;
b:tipo_tablero1;
t:tipo_tablero1;
mb : tipo_tablero1;
fin : real;
fin1 : real;
fin2 : real;
b1 : tipo_tablero1;
b2 : tipo_tablero1;
d1 : tipo_tablero1;
d2 : tipo_tablero1;
t1 : tipo_tablero1;
t2 : tipo_tablero1;
procedure inicia_tablero_barcos (var tb : tipo_tablero1);
{inicia el tablero de barcos con todos los valores agua A}
var
i,j:integer;
begin
for i := 1 to 8 do
for j:= 1 to 8 do
begin
tb[i,j] := 'A';
end;
end;
procedure inicia_tablero_control (var td : tipo_tablero1);
{inicia el tablero de los barcos bombardeados con todos las posiciones sin marcar X}
var
i,j:integer;
begin
for i:=1 to 8 do
for j:= 1 to 8 do
begin
td[i,j] := 'X';
end;
end;
procedure inicia_tablero_tamano (var tt: tipo_tablero1);
{inicia el tablero de las dimensiones de los barcos con todas las posiciones 0}
var
i,j : integer;
begin
for i:=1 to 8 do
for j:=1 to 8 do
begin
tt[i,j] := ' ';
end;
end;
procedure introducir_barcos (var b : tipo_tablero1; var t : tipo_tablero1);
{creamos las posiciones de nuestros barcos}
var
i:integer;
j:integer;
k:integer;
direc:string;
begin writeln;
writeln('barco de DIMENSION 1');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
b[i,j] := 'B';
t[i,j] := 'UNO';
writeln;
writeln('barco de DIMENSION 2');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
writeln;
writeln('DIRECCION: arriba/abajo/izquierda/derecha ');
readln(direc);
if direc = 'izquierda' then
for j:=j downto 2 do
begin
b[i,j] := 'B';
t[i,j] := 'DOS';
end
else
if direc = 'derecha' then
for j:=j to 2 do
begin
b[i,j]:='B';
t[i,j]:='DOS';
end
else
if direc = 'arriba' then
for i:=i downto 2 do
begin
b[i,j]:='B';
t[i,j]:='DOS';
end
else
if direc = 'abajo' then
for i:=i to 2 do
begin
b[i,j]:='B';
t[i,j]:='DOS';
end;
writeln;
writeln('barco de DIMENSION 3');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
writeln;
writeln('DIRECCION: arriba/abajo/izquierda/derecha');
readln(direc);
if direc = 'izquierda' then
for j:=j downto 3 do
begin
b[i,j] := 'B';
t[i,j] := 'TRES';
end
else
if direc = 'derecha' then
for j:=j to 3 do
begin
b[i,j]:='B';
t[i,j]:='TRES';
end
else
if direc = 'arriba' then
for i:=i downto 3 do
begin
b[i,j]:='B';
t[i,j]:='TRES';
end
else
if direc = 'abajo' then
for i:=i to 3 do
begin
b[i,j]:='B';
t[i,j]:='TRES';
end;
writeln;
writeln('barco de DIMENSION 4');
repeat
writeln;
writeln('introduzca fila: ');
readln(i);
if i>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until i<=8;
repeat
writeln;
writeln('introduzca columna: ');
readln(j);
if j>8 then
begin
writeln;
writeln('fuera de rango, intentelo de nuevo ');
end;
until j<=8;
writeln;
writeln('DIRECCION: arriba/abajo/izquierda/derecha ');
readln(direc);
if direc = 'izquierda' then
for j:=j downto 4 do
begin
b[i,j] := 'B';
t[i,j] := 'CUATRO';
end
else
if direc = 'derecha' then
for j:=j to 4 do
begin
b[i,j]:='B';
t[i,j]:='CUATRO';
end
else
if direc = 'arriba' then
for i:=i downto 4 do
begin
b[i,j]:='B';
t[i,j]:='CUATRO';
end
else
if direc = 'abajo' then
for i:=i to 4 do
begin
b[i,j]:='B';
t[i,j]:='CUATRO';
end;
end;
procedure muestra_bombardeados (var mb: tipo_tablero1);
var
i,j:integer;
begin
for i:= 1 to 8 do
begin
for j:= 1 to 8 do
begin
write(mb[i,j],' ');
end;
writeln;
end;
end;
procedure dispara (var b1:tipo_tablero1;
var b2:tipo_tablero1;
var d1:tipo_tablero1;
var d2:tipo_tablero1;
var t1:tipo_tablero1;
var t2:tipo_tablero1);
{iniciamos el juego}
var
i,j: integer;
contador1 :integer;
contador2 :integer;
fin : real;
fin1 : real;
fin2 : real;
begin
contador1 :=0;
contador2 :=0;
begin
while fin <>1 do
begin
fin1 :=4;
fin2 :=4;
repeat
begin
writeln;
writeln('turno JUGADOR 1');
writeln;
writeln('su tablero de control de disparos es: ');
begin
muestra_bombardeados(d1)
end;
repeat
writeln;
writeln('introduzca la coordenada FILA del barco a atacar: ');
readln(i);
if i>8 then
begin
writeln;
writeln('esta fuera del rango, intentelo de nuevo');
end;
until i<=8;
repeat
writeln;
writeln('introduzca la coordenada COLUMNA del barco a atacar: ');
readln(j);
if j>8 then
begin
writeln;
writeln('esta fuera del rango, intentelo de nuevo');
end;
until j<=8;
if b2[i,j]='B' then
begin writeln;
writeln('has alcanzado un BARCO de dimension ',t2[i,j]);
d1[i,j]:='B';
contador1 := contador1 + 1;
end
else
begin
writeln;
writeln('AGUA');
writeln;
writeln('fin de tu turno ');
d1[i,j]:='A';
end;
if b2[i,j]<> 'B' then
begin
fin1 := 2;
end;
if contador1 >=10 then
begin
fin1 := 2;
writeln;
writeln('GANADOR jugador 1');
writeln;
writeln('FELICIDADES!');
end;
end;
until fin1 = 2;
if contador1 >= 10 then
begin
fin := 1
end;
if contador1 <10 then
begin
repeat
begin
writeln;
writeln('turno JUGADOR 2');
writeln;
writeln('su tablero de control de disparos es: ');
begin
muestra_bombardeados(d2)
end;
repeat
writeln;
writeln('introduce la coordenada fila del barco a atacar: ');
readln(i);
if i>8 then
begin
writeln;
writeln('esta fuera del rango');
end;
until i<=8;
repeat
writeln;
writeln('introduce la coordenada columna del barco a atacar: ');
readln(j);
if j>8 then
begin
writeln;
writeln('esta fuera del rango');
end;
until j<=8;
if b1[i,j]='B' then
begin writeln;
writeln('has alcanzado un BARCO de dimension ',t1[i,j]);
d2[i,j]:='B';
contador2 := contador2 +1;
end
else
begin
writeln;
writeln('AGUA');
writeln;
writeln('fin de su turno ');
d2[i,j]:='A';
end;
if b1[i,j]<>'B' then
begin
fin2:=2;
end;
if contador2>=10 then
begin
fin2 := 2;
writeln;
writeln('GANADOR jugador 2');
writeln;
writeln('FELICIDADES!');
end;
end;
until fin2 = 2;
end;
if contador2>=10 then
begin
fin := 1;
end;
end;
end;
end;
begin (*del programa principal*);
writeln('BIENVENIDO A HUNDIR LA FLOTA');
inicia_tablero_barcos(tablero_B1);
inicia_tablero_barcos(tablero_B2);
inicia_tablero_control(tablero_D1);
inicia_tablero_control(tablero_D2);
inicia_tablero_tamano(tablero_T1);
inicia_tablero_tamano(tablero_T2);
writeln;
writeln('JUGADOR 1 introduzca sus barcos');
writeln;
introducir_barcos(tablero_B1,tablero_T1);
writeln;
writeln('JUGADOR 2 introduzca sus barcos');
writeln;
introducir_barcos(tablero_B2,tablero_T2);
dispara(tablero_B1,tablero_B2,tablero_D1,tablero_D2,tablero_T1,tablero_T2);
end.
Valora esta pregunta


0