Pascal/Turbo Pascal - Por favor ayuda urgente en corrección de programa

 
Vista:
sin imagen de perfil

Por favor ayuda urgente en corrección de programa

Publicado por Tony Garcia (1 intervención) el 01/12/2014 17:01:43
Tengo este programa, el profesor solo nos dio la base (lo que esta en mayusculas) pero no se si tenga error en cuando a la carga de archivos , por que al mmomento de tratar de continuar el juego, este se abre pero no carga lo datos guardados, si alguien me pudiera ayudar a ver mi error y corregirlo seria genial, de ante mano gracias

program Untitled;

uses crt;

TYPE tipo_punt = ^tipo_nodo;

tipo_nodo = record
dato: string;
si, no: tipo_punt;
end;

var opcion,continuar, respuesta :char;
si, no, raiz, punt, anterior : tipo_punt;
ANIMAL, PREGUNTA : STRING;

Var fan : file of tipo_punt;
{ temporal : file of tipo_punt; }


Procedure crearju;

Begin
Assign(fan,'animales.dat');
{$I-}
Reset(fan);
{$I+}
If(IoResult<>0) Then
Rewrite(fan);

NEW(RAIZ);
RAIZ^.DATO := 'VIVE EN EL AGUA';
NEW(SI);
SI^.DATO := 'TIBURON';
SI^.SI := NIL; SI^.NO := NIL; RAIZ^.SI := SI;
NEW(NO);
NO^.DATO := 'RATON' ; NO^.SI := NIL; NO^.NO := NIL; RAIZ^.NO := NO;
write(fan,RAIZ);
close(fan);
WRITELN('Preparandose para inciar juego, precione tecla para continuar');
readkey;
exit;
end;

Procedure jug;

Begin
clrscr;
WHILE CONTINUAR = 'S' DO
BEGIN
clrscr;
Assign(fan,'animales.dat');
{$I-}
Reset(fan);
{$I+}
Read(fan,RAIZ);

WRITELN('PIENSE EN UN ANIMAL');
PUNT := RAIZ;
WHILE PUNT <> NIL DO
BEGIN
WRITE('¨',PUNT^.DATO,'? (S/N): ');
READLN(RESPUESTA);
ANTERIOR := PUNT;
IF UPCASE(RESPUESTA) = 'S' THEN PUNT := PUNT^.SI;
IF UPCASE(RESPUESTA) = 'N' THEN PUNT := PUNT^.NO;
END;
IF UPCASE(RESPUESTA) = 'S'
THEN BEGIN
WRITE('HE GANADO');
readkey;
Close(fan);
exit;
END
ELSE BEGIN
NEW(SI); SI^.SI := NIL; SI^.NO := NIL;
NEW(NO); NO^.SI := NIL; NO^.NO := NIL;
WRITELN('HE PERDIDO, INGRESE EL ANIMAL QUE ESTABA PENSANDO');
READLN(ANIMAL);
WRITE('INGRESE UNA PREGUNTA QUE DIFERENCIE A ', ANIMAL);
WRITELN(' DE ', ANTERIOR^.DATO);
READLN(PREGUNTA);
WRITE('CUAL ES LA RESPUESTA DE ', PREGUNTA, ' PARA ', ANIMAL, '(S/N): ');
READLN(RESPUESTA);
IF UPCASE(RESPUESTA) = 'S'
THEN BEGIN
SI^.DATO := ANIMAL;
NO^.DATO := ANTERIOR^.DATO;
ANTERIOR^.DATO := PREGUNTA;
ANTERIOR^.SI := SI;
ANTERIOR^.NO := NO;
END;
IF UPCASE(RESPUESTA) = 'N'
THEN BEGIN
SI^.DATO := ANTERIOR^.DATO;
NO^.DATO := ANIMAL;
ANTERIOR^.DATO := PREGUNTA;
ANTERIOR^.SI := SI;
ANTERIOR^.NO := NO;

END;
WRITELN('GRACIAS AHORA CONOZCO OTRO ANIMAL');
END;
write(fan,RAIZ);
close(fan);
WRITE('¨DESEA CONTINUAR (S/N): ');
READLN(CONTINUAR);
end;
exit;
end;

Procedure res;
begin
writeln(' Datos Respaldados (Proximamente)');
readkey;
end;

Procedure rec;
begin
writeln(' Datos Cargados (Proximamente)');
readkey;
end;

Procedure lisan;
begin
clrscr;
writeln(' Listado de Animales que conosco (Proximamente)');
readkey;
end;

Procedure lispreg;
begin
clrscr;
writeln(' Listado de preguntas que conosco (Proximamente)');
readkey;
end;

Procedure lis;
begin
repeat
clrscr;
writeln(' Escoja que lista desea ver');
writeln('1./ Animales ');
writeln('2./ Preguntas ');
writeln('3./ Salir al menu anterior');
readln(opcion);

case opcion of
'1': lisan;
'2': lispreg;
'3': exit;
end;

until opcion = '3';
readkey;
end;

begin

repeat
clrscr;
CONTINUAR := 'S';
writeln(' Menu Principal de Juego');
writeln('0./ Inicialisar juego nuevo');
writeln('1./ Jugar/Continuar ');
writeln('2./ Respaldar ');
writeln('3./ Recuperar ');
writeln('4./ Listar ');
writeln('5./ Salir ');
readln(opcion);
case opcion of
'0': crearju;
'1': jug;
'2': res;
'3': rec;
'4': lis;
'5': exit;
end;
until opcion = '5';
readkey;
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

Por favor ayuda urgente en corrección de programa

Publicado por ramon (2158 intervenciones) el 21/12/2014 22:56:58
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
{Mira esto te podar ayudar y te comento.
la forma que realizas el proceso es errónea para archivos puesto que solo guardas las direcciones de memoria
con lo cual mientras el juego este activo leerá los datos pero cuando salgas los perderás con lo cual no podrás
tomarlos después}
 
 program animales;
 uses
    crt;
 type
 
    listan = ^datosjuego;
       datosjuego = record
               dato : string;
             si, no : string;
           sig, ant : listan;
             end;
  var
    prim, anter, ultim, actual : listan;
    f : file of datosjuego;
    losdatos : datosjuego;
    animal, resp : char;
 
  procedure guardadatos(d : datosjuego);
  begin
     Assign(f,'animales.dat');
  {$I-} Reset(f); {$I+}
     If IoResult <> 0 Then
     begin
        rewrite(f);
        seek(f,0);
        write(f,d);
        close(f);
     end
  else
     begin
        seek(f,filesize(f));
        write(f,d);
        close(f);
     end;
  end;
 
  Procedure crearju(var nn : datosjuego);
   Begin
       nn.dato := 'Vive En El Agua';
       nn.si := 'Tiburon';
       nn.no := 'Raton';
       WRITELN('Preparandose para inciar juego, precione tecla para continuar');
       readkey;
     end;
 
 
 procedure insertarregistro(guar : boolean);
  begin
      if prim = nil then
      begin
          new(actual);
          actual^ := losdatos;
          actual^.sig := nil;
          actual^.ant := nil;
          prim := actual;
          ultim := actual;
      end
   else
      begin
          anter := ultim;
          new(actual);
          actual^ := losdatos;
          anter^.sig := actual;
          actual^.sig := nil;
          actual^.ant := anter;
          ultim := actual;
      end;
      if guar = true then
      guardadatos(actual^);
  end;
 
  procedure listarregistros;
  var
     tec : char;
     ll : longint;
   begin
       Assign(f,'animales.dat');
  {$I-} Reset(f); {$I+}
     If IoResult <> 0 Then
     begin
        writeln('  Error De Archivo O No Se Encuentra Pulse Una Tecla');
        readkey;
      end
   else
       begin
       prim := nil;
       for ll := 0 to filesize(f) - 1 do
       begin
       seek(f,ll);
       read(f,losdatos);
       insertarregistro(false);
      end;
       close(f);
       if prim <> nil then
       begin
          actual := prim;
          while actual <> nil do
          begin
              with actual^ do
              begin
              writeln(dato);
              writeln(si);
              writeln(no);
              end;
              writeln;
              actual := actual^.sig;
          end;
          writeln;
          writeln('///// Pulse Una Tecla //////');
          readkey;
       end;
    end;
   end;
 
   procedure cargajuego;
  var
    jh : longint;
   begin
     Assign(f,'animales.dat');
  {$I-} Reset(f); {$I+}
     If IoResult <> 0 Then
     begin
        writeln('   Error Falta Archivo O Esta Da¤ado Pulse Una Tecla');
        readkey;
     end
  else
      begin
         prim := nil;
         ultim := nil;
         for jh := 0 to filesize(f) - 1 do
         begin
            seek(f,jh);
            read(f,losdatos);
            insertarregistro(false);
         end;
      end;
   end;
 
  procedure jug(var nn : datosjuego);
  var
    temp : datosjuego;
    da : string;
    pulsa : char;
    paso, tp, cc, ju, ee : longint;
    put : listan;
  begin
     clrscr;
         cargajuego;
        ju := filesize(f) - 1;
         ee := random(ju);
         if ee > ju then
         ee := ju;
         put := prim;
         cc := 0;
         tp := ee;
     repeat
         while (cc <> ju) and (cc <> ee) do
         begin
            put := put^.sig;
            cc := cc + 1;
         end;
         nn := put^;
         WRITELN('PIENSE EN UN ANIMAL');
         WRITE('¨',nn.dato,'? (S/N) : ');
         READLN(animal);
         IF UPCASE(animal) = 'S' THEN
         BEGIN
             writeln(' HE GANADO');
             writeln(' El Animal Era El = ',nn.si);
         end
      else
         begin
         WRITELN('HE PERDIDO, INGRESE EL ANIMAL QUE ESTABA PENSANDO');
         READLN(temp.dato);
         WRITE('INGRESE UNA PREGUNTA QUE DIFERENCIE A ', temp.dato);
         WRITELN(' DE ', nn.DATO);
         READLN(da);
         WRITE('CUAL ES LA RESPUESTA DE ', temp.dato, ' PARA ',
                                         da, '(S/N) : ');
         READLN(RESP);
         if upcase(resp) = 'S' then
         begin
         temp.si := temp.dato;
         temp.no := nn.dato;
         temp.dato := da;
       end
   else
       begin
           temp.si := nn.dato;
           temp.no := temp.dato;
           temp.dato := da;
       end;
        losdatos := temp;
        insertarregistro(true);
        WRITELN('GRACIAS AHORA CONOZCO OTRO ANIMAL');
      end;
      writeln;
      WRITE('¨DESEA CONTINUAR (S/N): ');
      repeat
        pulsa := upcase(readkey);
      until pulsa in['S','N'];
      clrscr;
      if pulsa = 'S' then
      begin
          cargajuego;
         ju := filesize(f) - 1;
         paso := 0;
        repeat
         ee := random(ju);
         if ee <> tp then
         paso := paso + 1;
        until (tp <> ee) or (paso > 10);
        if paso > 10 then
        ee := 0;
         if ee > ju then
         ee := ju;
         cc := 0;
         tp := ee;
         paso := 0;
         put := prim;
      end;
   until pulsa = 'N';
  end;
 
   procedure menu;
  var
     tecl : char;
     sal : boolean;
  begin
     sal := false;
   repeat
   clrscr;
   writeln('******* Menu Principal *********');
   writeln;
   writeln('  0 = Inicialisar juego nuevo');
   writeln('  1 = Jugar/Continuar');
   writeln('  2 = Listar Los Datos');
   writeln('  3 = salir');
   writeln;
   writeln('<<<<< Elija Opcion >>>>>');
   repeat
       tecl := readkey;
   until tecl in[#49..#52];
  case tecl of
 #48 : begin clrscr;crearju(losdatos);insertarregistro(true); end;
 #49 : begin clrscr;jug(losdatos); end;
 #50 : begin clrscr; listarregistros; end;
 #51 : sal := true;
  end;
   until sal = true;
  end;
 
 
 
  begin
      prim := nil;
      ultim := nil;
      randomize;
      menu;
  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