Pascal/Turbo Pascal - guardar/cargar partida pascal, urgente!!

 
Vista:

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.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

guardar/cargar partida pascal, urgente!!

Publicado por ramon (2158 intervenciones) el 05/05/2013 23:14:48
De la forma que tienes el programa es complicado guardar las partidas tendrías que hacerlo en
un archivo de texto variable a variable para poder cargarlas después igual mala cosa.
Te recomiendo uses registro en vez de tanta variable.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

guardar/cargar partida pascal, urgente!!

Publicado por ramon (2158 intervenciones) el 06/05/2013 21:08:11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{Mira esto seria una forma}
 
type
string8 = string[8];
 
var
   f : text;
   tec : char;
   nom : string8;
   cargado : boolean;
 
procedure guarda_jugada;
var
  nombre : string[8];
  dy, ty : integer;
begin
   write('   Entre nombre Archivo 8 Caracteres : ');
   readln(nombre);
   assign(f,nombre + '.dat');
  {$I-} reset(f); {$I+}
  if ioresult <> 0 then
  begin
      rewrite(f);
     for dy := 1 to 8 do
       for ty := 1 to 8 do
       begin
          writeln(f,tablero_B1[dy,ty]);
          writeln(f,tablero_B2[dy,ty]);
          writeln(f,tablero_D1[dy,ty]);
          writeln(f,tablero_D2[dy,ty]);
          writeln(f,tablero_T1[dy,ty]);
          writeln(f,tablero_T2[dy,ty]);
          writeln(f,b[dy,ty]);
          writeln(f,t[dy,ty]);
          writeln(f,mb[dy,ty]);
          writeln(f,b1[dy,ty]);
          writeln(f,b2[dy,ty]);
          writeln(f,d1[dy,ty]);
          writeln(f,d2[dy,ty]);
          writeln(f,t1[dy,ty]);
          writeln(f,t2[dy,ty]);
     end;
         writeln(f,i);
         writeln(f,j);
         writeln(f,k);
         writeln(f,contador1);
         writeln(f,contador2);
         writeln(f,direc);
         close(f);
     end
 else
    begin
    writeln('  El Archivo De Nombre : ',nombre,' Ya Existe Pulse [Enter]');
    readln;
    exit;
    end;
 end;
 
 procedure cargajuego(nom : string8);
 var
   dy, ty : integer;
 begin
    assign(f,nom + '.dat');
  {$I-} reset(f); {$I+}
  if ioresult <> 0 then
  begin
      writeln('   El Archivo Pedido No Existe Pulse [Enter]');
      readln;
      cargado := false;
      exit;
  end
 else
    begin
       for dy := 1 to 8 do
        for ty := 1 to 8 do
       begin
         readln(f,tablero_B1[dy,ty]);
         readln(f,tablero_B2[dy,ty]);
         readln(f,tablero_D1[dy,ty]);
         readln(f,tablero_D2[dy,ty]);
         readln(f,tablero_T1[dy,ty]);
         readln(f,tablero_T2[dy,ty]);
         readln(f,b[dy,ty]);
         readln(f,t[dy,ty]);
         readln(f,mb[dy,ty]);
         readln(f,b1[dy,ty]);
         readln(f,b2[dy,ty]);
         readln(f,d1[dy,ty]);
         readln(f,d2[dy,ty]);
         readln(f,t1[dy,ty]);
         readln(f,t2[dy,ty]);
       end;
         readln(f,i);
         readln(f,j);
         readln(f,k);
         readln(f,contador1);
         readln(f,contador2);
         readln(f,direc);
         close(f);
         cargado := true;
    end;
 end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar