Pascal/Turbo Pascal - Problema con el juego del gato en pascal

 
Vista:

Problema con el juego del gato en pascal

Publicado por pamela gomez (17 intervenciones) el 26/04/2012 06:52:38
Hola disculpen es q tengo q hacer el juego del gato en pascal con una matriz d 3x3 (los 2 jugadores tienen q ser la computadora: compu1 vrs compu2) y utilizando los comandos de random y randomize
el problema es q no se como hacerlo ni mucho menos se activar los dos comandos ya antes mencionados si no fuera mucha molestia me podrian poner un codigo fuente se les agradece.
Se les agradece la ayuda,gracias!!!!
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

Problema con el juego del gato en pascal

Publicado por ramon (2158 intervenciones) el 26/04/2012 18:06:03
1
2
3
4
5
6
7
8
9
10
11
12
{Disculpa pero como es el juego del gato si me explicas un poco te puedo a ayudar mejor.
los comando que a ces mención se procesan así.}
 var
      a, n : integer;
 begin
     randomize; {semilla inicial de generación de números aleatorios}
     repeat
          a := random(20); {genera un numero al azar de 0 a 20}
          write('  ',a); {imprimimos en pantalla el numero generado}
      n := n + 1; {incrementamos n en 1}
     until n > 10; {finalizamos cuando n sea mayor de 10 o sea 10 números mostraos}
  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

Problema con el juego del gato en pascal

Publicado por pamela gomez (17 intervenciones) el 27/04/2012 07:06:07
el juego consiste en que la computadora1 aleatoriamente pone ya sea una x ó un o en el gato igualmente la computadora2 , y la q gane se le suman unos puntos. pero todo esto se tiene q hacer en una matriz con las funciones
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

Problema con el juego del gato en pascal

Publicado por pamela gomez (17 intervenciones) el 27/04/2012 07:10:25
ejemplo juega la compu1 y con las funciones random(q no se como ponerlas a funcionar)marca con X ó 0,despues la compu2 tambien hace lo mismo hasta q una gane o empaten.Le agradesco de verdad si me pueden ayudar!!!!
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

Problema con el juego del gato en pascal

Publicado por ramon (2158 intervenciones) el 27/04/2012 23:44:16
{A ver si acerté}

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
program juegogato;
 uses
    crt;
  var
    semi, juga1, juga2 : integer;
    tecla : char;
    ant1, ant2, cont1, cont2, numer : integer;
    nomb, nombre1, nombre2 : string[20];
    sal : boolean;
 
 
   function numerofijado : integer;
   begin
      clrscr;
      gotoxy(1,2);write('Entre Nombre El Jugador N§ 1 : ');
      gotoxy(33,2);readln(nombre1);
      gotoxy(1,2);clreol;
      gotoxy(1,2);write('Entre Nombre El Jugador N§ 2 : ');
      gotoxy(33,2);readln(nombre2);
      numerofijado := numer;
   end;
 
   procedure jugaralgato;
   var
     salio, jue : integer;
   begin
     randomize;
     sal := false;
     repeat
     numer := random(20);
     until numer > 0;
     clrscr;
     salio := numerofijado;
     gotoxy(1,2);write('Ganara El Jugador Que Le Salga El ',
                            'N§ [',salio,'] Tres Veces');
      repeat
      jue := random(3);
      until jue in[1,2];
    case jue of
  1 : nomb := nombre1;
  2 : nomb := nombre2;
    end;
     juga1 := 0;
     juga2 := 0;
     cont1 := 0;
     cont2 := 0;
   repeat
      gotoxy(10,10);clreol;
      gotoxy(10,10);write('Pulse Barra Espaciadora El Jugador ',nomb);
      gotoxy(10,12);write('Aciertos ',nombre1,' = ',cont1,'     ',
                               'Aciertos ',nombre2,' = ',cont2);
      tecla := readkey;
      if tecla = #32 then
      begin
      if nomb = nombre1 then
      begin
      juga1 := random(20);
      gotoxy(20,14);write('Salio N§ :     ');
      gotoxy(20,14);write('Salio N§ : ',juga1);
      if (cont1 = 0) and (juga1 = salio) then
      begin
      cont1 := 1;
      end;
      nomb := nombre2;
      if juga1 = ant1 then
      cont1 := cont1 + 1;
      if (ant1 = 0) and (juga1 = salio) then
      ant1 := juga1;
      if cont1 = 3 then
      sal := true;
      end
     else
      begin
      juga2 := random(20);
      gotoxy(20,14);write('Salio N§ :     ');
      gotoxy(20,14);write('Salio N§ : ',juga2);
      if (cont2 = 0) and (juga2 = salio) then
      cont2 := 1;
      nomb := nombre1;
      if juga2 = ant2 then
      cont2 := cont2 + 1;
      if (ant2 = 0) and (juga2 = salio) then
      ant2 := juga2;
      if cont2 = 3 then
      sal := true;
      end;
     end;
   until (sal = true) or (tecla = #27);
   if nomb := nombre1 then
   nomb := nombre2;
   if nomb := nombre2 then
   nomb := nombre1;
   clrscr;
   writeln('    Ganador El Jugador [ ',nomb,' ]');
   readln;
   end;
 
 
  begin
     clrscr;
     jugaralgato;
  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

Problema con el juego del gato en pascal

Publicado por pamela gomez (17 intervenciones) el 02/05/2012 06:26:01
disculpa la tardansa en contestar pero lo el codigo q pusiste no me sirve no me compila.Asi q voy a subir lo q tengo hasta ahora para ver si le es mas facil entender lo q digo y asi sea mas facil para q me puedan ayudar.
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
PROGRAM JUEGO_GATO;
USES
    CRT;
 
VAR
    I,J: INTEGER;
    MATRIZ: ARRAY[1..3,1..3] OF REAL;
    COMPU1, COMPU2,C1,C2, POS: INTEGER;
    ascore1,bscore2,score1,score2,opcion:integer;
 
(*PROCEDIMIENTO QUE DA MUESTRA ERROR CUANDO ESTA OCUPADA LA CASILLA*)
PROCEDURE ERROR;
          BEGIN
               GOTOXY(27,22);
               TEXTCOLOR(LIGHTRED);
               WRITE('CASILLA OCUPADA, INTENTA DE NUEVO');
               TEXTCOLOR(WHITE);
          END;
 
(*PROCEDIMIENTO PARA MOSTRAR EL MENU PRINCIPAL*)
PROCEDURE CASILLAS;
            BEGIN
                 gotoxy(04,02);write('compu1:=X');
                 gotoxy(15,02);write('compu2:=O');
                 TEXTCOLOR(14);
                 MARCO2;
                 GOTOXY(11,10); WRITE('          ³          ³          ');
                 GOTOXY(11,11); WRITE('          ³          ³          ');
                 GOTOXY(11,12); WRITE('          ³          ³          ');
                 GOTOXY(11,13); WRITE('ÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ');
                 GOTOXY(11,14); WRITE('          ³          ³          ');
                 GOTOXY(11,15); WRITE('          ³          ³          ');
                 GOTOXY(11,16); WRITE('          ³          ³          ');
                 GOTOXY(11,17); WRITE('ÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ');
                 GOTOXY(11,18); WRITE('          ³          ³          ');
                 GOTOXY(11,19); WRITE('          ³          ³          ');
                 GOTOXY(11,20); WRITE('          ³          ³          ');
                 TEXTCOLOR(LIGHTGRAY);
                 READKEY;
            END;
 
 
procedure puntos;
          begin
               textcolor(20);
               gotoxy(06,04);write('compu1: ',ascore1);
               gotoxy(30,04);write('compu2: ',bscore2);
          end;
 
procedure pscore1;
          begin
               score1:=0;
               ascore1:=score1+100;
          end;
 
procedure pscore2;
          begin
               score2:=0;
               bscore2:=score2+100;
          end;
 
procedure menu;
          begin
               opcion:=1;
               gotoxy(55,10);write('1.volver a jugar');
               gotoxy(55,11);write('2.salir');
               read(opcion);
               if (opcion>=1) and (opcion<=2) then begin
                  case opcion of
                       1: begin
                               (*se vuelve a iniciar el juego*)
 
                          end;
                       end;
                  end
               else begin
                    gotoxy(55,12);write('opcion incorrecta');
                    readkey;
                    end;
          end;
 
 
(*PROGRAMA PRINCIPAL*)
BEGIN
     CLRSCR;
     puntos;
     ERROR;
     CASILLAS;(*LLAMA AL PROCEDIMIENTO DEL CUADRO*)
     repeat
           menu;
     until opcion=2;
END.

Aqui esta lo q llevo hasta ahora lo q necesito es que yo aprete una tecla y se marque con una equix algun lugar de la cuadricula(procedure casillas) esto con la funcion randomize,luego me avise q presione otra tecla para q se marque un 0 en la cuadricula(tambien con el randomize)y si en algun momento se marca una casilla ya ocupada me tire un mensaje que vuelva a presionar otra tecla para que se marque hasta q encuentre una casilla libre.y el que gane se le suma 100puntos y entra el menu q me dice si quiero volver a jugar(si es asi se limpia la cuadricula y los puntos se mantienen igual y si vuelve a ganar la misma compu entonces tendria 200puntos).
Esto es lo que necesito de verdad le agradeceria d todo corazon si me pueden ayudar porque esto lo ocupo para poder ganar el curso y si pudieran hacerlo antes del viernes porque lo tengo q presentar el viernes en la noche.
de verdad se los agradeceria bastante porque si me ayudan ganaria el curso asi q ustds serian mis heroes de verdad d antemano les agradesco la ayuda.!!!!!
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

Problema con el juego del gato en pascal

Publicado por MIKE (1 intervención) el 04/05/2012 03:29:08
EL CODIGO Q ELLA NECESITA ES EL DEL JUEGO LLAMADO EN INGLEZ , TIC TAC TOE...


___I__I___
___ I__I___
I I
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

Problema con el juego del gato en pascal

Publicado por pamela gomez (17 intervenciones) el 04/05/2012 06:56:28
asi es ese el juego ya arriba pusi lo q llevava hecho hasta el momento y tambien pusi lo q me falta para que entienda q es lo q me falta.Espero su ayuda lo mas pronto posible ya que necesito entregar el juego para el viernes.Gracias d antemano!!!!!
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

Problema con el juego del gato en pascal

Publicado por ramon (2158 intervenciones) el 04/05/2012 21:48:59
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
{A ver si esto te ayuda tendrás que trabajarlo un poco mas}
 
PROGRAM JUEGO_GATO;
USES
    CRT;
 
VAR
    I,J: INTEGER;
    MATRIZ: ARRAY[1..3,1..3] OF REAL;
    COMPU1, COMPU2,C1,C2, POS: INTEGER;
    ascore1,bscore2,score1,score2,opcion:integer;
 
(*PROCEDIMIENTO QUE DA MUESTRA ERROR CUANDO ESTA OCUPADA LA CASILLA*)
         PROCEDURE ERROR;
          BEGIN
               TEXTCOLOR(WHITE);
               GOTOXY(27,22);write('                                    ');
               GOTOXY(27,22);
               TEXTCOLOR(LIGHTRED);
               WRITE('CASILLA OCUPADA, INTENTA DE NUEVO');
               TEXTCOLOR(WHITE);
          END;
 
(*PROCEDIMIENTO PARA MOSTRAR EL MENU PRINCIPAL*)
PROCEDURE CASILLAS;
            BEGIN
                 gotoxy(04,02);write('compu1:=X');
                 gotoxy(15,02);write('compu2:=O');
                 TEXTCOLOR(14);
                 GOTOXY(11,10); WRITE('ÚÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄ¿                             ');
                 GOTOXY(11,11); WRITE('³         ³          ³         ³');
                 GOTOXY(11,12); WRITE('³         ³          ³         ³');
                 GOTOXY(11,13); WRITE('ÃÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄ´');
                 GOTOXY(11,14); WRITE('³         ³          ³         ³');
                 GOTOXY(11,15); WRITE('³         ³          ³         ³');
                 GOTOXY(11,16); WRITE('³         ³          ³         ³');
                 GOTOXY(11,17); WRITE('ÃÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄ´');
                 GOTOXY(11,18); WRITE('³         ³          ³         ³');
                 GOTOXY(11,19); WRITE('³         ³          ³         ³');
                 GOTOXY(11,20); WRITE('ÀÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÙ');
                 TEXTCOLOR(LIGHTGRAY);
            END;
 
 
procedure puntos;
          begin
               textcolor(20);
               gotoxy(06,04);write('compu1: ',ascore1);
               gotoxy(30,04);write('compu2: ',bscore2);
          end;
 
   procedure pscore1;
          begin
               score1:=0;
               ascore1:=score1+100;
          end;
 
 procedure pscore2;
          begin
               score2:=0;
               bscore2:=score2+100;
          end;
 
 procedure jugamos(xj, yj : integer);
 var
    cual, nu : integer;
    tecla : char;
    sal : boolean;
 begin
    randomize; {jeneramos semilla}
    cual := 0;
    sal := false;
    repeat
      cual := random(2);
    until cual in[1,2];
    repeat
    if cual = 1 then
    begin
    gotoxy(45,14);write('Juegas TU [o] Pulsa Barra Espacio');
    end;
    if cual = 2 then
    begin
    gotoxy(45,14);write('Juegas El [x] Pulsa Barra Espacio');
    end;
    tecla := readkey;
    TEXTCOLOR(WHITE);
    GOTOXY(27,22);write('                                    ');
    nu := random(10);
   case nu of
  1 : begin
      if matriz[1,1] = 0 then
      begin
      if cual = 1 then
      begin
      pscore1;
      matriz[1,1] := ascore1;
      gotoxy(16,12);write('o');
      cual := 2;
      end
    else
       begin
       pscore2;
       matriz[1,1] := bscore2;
       gotoxy(16,12);write('x');
       cual := 1;
       end;
      end
  else
     ERROR;
   end;
  2 : begin
      if matriz[1,2] = 0 then
      begin
      if cual = 1 then
      begin
       pscore1;
       matriz[1,2] := ascore1;
       gotoxy(26,12);write('o');
      cual := 2;
      end
    else
       begin
       pscore2;
       matriz[1,2] := bscore2;
       gotoxy(26,12);write('x');
       cual := 1;
       end;
       end
     else
       ERROR;
       end;
  3 : begin
      if matriz[1,3] = 0 then
      begin
      if cual = 1 then
      begin
      pscore1;
      matriz[1,3] := ascore1;
      gotoxy(36,12);write('o');
      cual := 2;
      end
    else
       begin
       pscore2;
       matriz[1,3] := bscore2;
       gotoxy(36,12);write('x');
       cual := 1;
       end;
      end
    else
       ERROR;
      end;
  4 : begin
       if matriz[2,1] = 0 then
       begin
       if cual = 1 then
       begin
       pscore1;
       matriz[2,1] := ascore1;
       gotoxy(16,15);write('o');
       cual := 2;
      end
    else
       begin
       pscore2;
       matriz[2,1] := bscore2;
       gotoxy(16,15);write('x');
       cual := 1;
       end;
       end
     else
        ERROR;
       end;
  5 : begin
       if matriz[2,2] = 0 then
       begin
       if cual = 1 then
       begin
       pscore1;
       matriz[2,2] := ascore1;
       gotoxy(26,15);write('o');
       cual := 2;
      end
    else
       begin
       pscore2;
       matriz[2,2] := bscore2;
       gotoxy(26,15);write('x');
       cual := 1;
       end;
       end
    else
      ERROR;
       end;
  6 : begin
       if matriz[2,3] = 0 then
       begin
       if cual = 1 then
       begin
       pscore1;
       matriz[2,3] := ascore1;
       gotoxy(36,15);write('o');
       cual := 2;
      end
    else
       begin
       pscore2;
       matriz[2,3] := bscore2;
       gotoxy(36,15);write('x');
       cual := 1;
       end;
       end
     else
        ERROR;
       end;
  7 : begin
       if matriz[3,1] = 0 then
       begin
         if cual = 1 then
         begin
         pscore1;
         matriz[3,1] := ascore1;
         gotoxy(16,19);write('o');
         cual := 2;
      end
    else
       begin
       pscore2;
       matriz[3,1] := bscore2;
       gotoxy(16,19);write('x');
       cual := 1;
       end;
      end
      else
        ERROR;
         end;
  8 : begin
        if matriz[3,2] = 0 then
        begin
        if cual = 1 then
        begin
        pscore1;
        matriz[3,2] := ascore1;
        gotoxy(26,19);write('o');
      cual := 2;
      end
    else
       begin
       pscore2;
       matriz[3,2] := bscore2;
       gotoxy(26,19);write('x');
       cual := 1;
       end;
      end
     else
        ERROR;
        end;
  9 : begin
        if matriz[3,3] = 0 then
        begin
        if cual = 1 then
        begin
        pscore1;
        matriz[3,3] := ascore1;
        gotoxy(36,19);write('o');
        cual := 2;
      end
    else
       begin
       pscore2;
       matriz[3,3] := bscore2;
       gotoxy(36,19);write('x');
       cual := 1;
       end;
      end
      else
         ERROR;
        end;
   end;
    until tecla = #27;
 end;
 
 
 
          procedure menu;
          begin
               opcion:=1;
               gotoxy(55,10);write('1.volver a jugar');
               gotoxy(55,11);write('2.salir');
               gotoxy(55,12);write('Tecla [ESC] Termina');
               read(opcion);
               if (opcion>=1) and (opcion<=2) then begin
                  case opcion of
                       1: begin
                               (*se vuelve a iniciar el juego*)
                               jugamos(26,15);
                          end;
                       end;
                  end
               else begin
                    gotoxy(55,12);write('opcion incorrecta');
                    readkey;
                    end;
          end;
 
 
(*PROGRAMA PRINCIPAL*)
BEGIN
     CLRSCR;
     puntos;
     CASILLAS;(*LLAMA AL PROCEDIMIENTO DEL CUADRO*)
     repeat
           menu;
     until opcion=2;
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

Problema con el juego del gato en pascal

Publicado por pamela gomez (17 intervenciones) el 09/05/2012 06:29:53
muchas gracias ramon le agradesco su ayuda me sirvio d mucho.!!!!
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