Pascal/Turbo Pascal - Juego de LA VIEJA en Pascal

 
Vista:
sin imagen de perfil

Juego de LA VIEJA en Pascal

Publicado por Programador (3 intervenciones) el 24/08/2015 19:09:51
Buenas ¿como están? estoy haciendo el juego de ''La vieja'' como hago algo personal simplemente para aprender un poco mas de Pascal.. Y quería saber porque al llamar a la función Ganador en PLAY no me imprime el mensaje, se supone que si encuentra XXX debería decir ''Ganaron las X'' y si encuentra OOO deberia decir ''Ganaron las O'' pero el programa nunca lo dice, podrían ayudarme?

Yo coloque esto:
1
2
If (Ganador(M))then
Writeln('El ganador es la',S);


El código es el siguiente:


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
Program LaVieja;
Uses crt;
Const
  Fila=3; Equis='X';
  Columna=3;  Cero='O';
  Vacio='_';
Type
  Matriz= Array[1..fila,1..columna] of Char;
Var
M: Matriz; S,Nombre: String; F:Text; Cedula:Integer;
 
Procedure llenarmatriz (Var M: Matriz);
Var I,J: Integer;
 
Begin
For I:= 1 to fila do
 Begin
     For J:= 1 to columna do
      Begin
      M[I,J]:=vacio;
      end;
     Writeln;
 End;
End;
 
Procedure mostrarmatriz (Var M: Matriz);
Var I,J: Integer;
 
Begin
For I:= 1 to fila do
 Begin
     For J:= 1 to columna do
      Begin
      Write(M[I,J],' ');
      end;
 Writeln;
 End;
End;
 
Function Ganador (Var M:Matriz):Boolean;
  Var S:String; I,J:Integer; Ganar:Boolean;
 
Begin
Ganar:=False;
  For I:= 1 to fila do
  Begin
   For J:= 1 to columna do
     Begin
     {Horizontal}
       If ((M[I,J]='X') and (M[I,J+1]='X') and (M[I,J+2]='X')) then
       Begin
       Ganar:=True;
       S:='X';
       Break;
       End
       else
       If ((M[I,J]='O') and (M[I,J+1]='O') and (M[I,J+2]='O')) then
       Begin
       Ganar:=True;
       S:='O';
       Break;
       End
       else
       {Vertical}
       If ((M[I,J]='X') and (M[I+1,J]='X') and (M[I+2,J]='X')) then
        Begin
       Ganar:=True;
       S:='X';
       Break;
       End
       else
       If ((M[I,J]='O') and (M[I+1,J]='O') and (M[I+2,J]='O')) then
        Begin
       Ganar:=True;
       S:='O';
       Break;
       End
       else
       {Diagonal}
       If ((M[I,J]='X') and (M[I+1,J+2]='X') and (M[I+3,J+3]='X')) then
        Begin
       Ganar:=True;
       S:='X';
       Break;
       End
       else
       If ((M[I,J]='O') and (M[I+1,J+2]='O') and (M[I+3,J+3]='O')) then
        Begin
       Ganar:=True;
       S:='O';
       Break;
       End;
     End;
 
  End;
Ganador:=Ganar;
End;
 
Procedure Play (Var M: Matriz);
Var F,C,K:Integer; Turno: Boolean; S:String;
 
Begin
Turno:=True; K:=0;
 
    While (K<9) do
     Begin
        If (Turno) then
        Begin
          Writeln('Jugador 1');
          readln(F,C);
          M[F,C]:=Equis;
        end
       else
        Begin
          Writeln('Jugador 2');
          readln (F,C);
          M[F,C]:=Cero;
        End;
     K:=K+1;
     mostrarmatriz(M);
     Turno:= Not(Turno);
    end;
    If (Ganador(M))then
    Writeln('El ganador es la',S);
End;
 
Begin
Clrscr;
Writeln ('Bienvenido al juego de la vieja');
{Write ('Nombre del jugador 1: '); Readln(Nombre);
Write ('Cedula del jugador 1: '); Readln(Cedula);
Assign(F,'C:\Users\Usuario\Desktop\Lavieja.txt');
Rewrite(F);
Write('Nombre 1: ',Nombre,' Cedula 1: ',Cedula);
Close(F);}
LlenarMatriz(M);
MostrarMatriz (M);
Play (M);
readln;
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

Juego de LA VIEJA en Pascal

Publicado por ramon (2158 intervenciones) el 01/09/2015 00:07:40
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
{Mira esto}
 
 
function partidaok(juego : Matriz; cual : char) : boolean;
  begin
  partidaok := false;
  if (juego[1,1] = cual) and (juego[2,1] = cual) and (juego[3,1] = cual) then
  partidaok := true;
  if (juego[1,2] = cual) and (juego[2,2] = cual) and (juego[3,2] = cual) then
  partidaok := true;
  if (juego[1,3] = cual) and (juego[2,3] = cual) and (juego[3,3] = cual) then
  partidaok := true;
 
  if (juego[1,1] = cual) and (juego[1,2] = cual) and (juego[1,3] = cual) then
  partidaok := true;
  if (juego[2,1] = cual) and (juego[2,2] = cual) and (juego[2,3] = cual) then
  partidaok := true;
  if (juego[3,1] = cual) and (juego[3,2] = cual) and (juego[3,3] = cual) then
  partidaok := true;
 
  if (juego[1,1] = cual) and (juego[2,2] = cual) and (juego[3,3] = cual) then
  partidaok := true;
  if (juego[3,1] = cual) and (juego[2,2] = cual) and (juego[1,3] = cual) then
  partidaok := true;
  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

Juego de LA VIEJA en Pascal

Publicado por ramon (2158 intervenciones) el 01/09/2015 18:16:57
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
{Esto te ayudara mas espero con esto te sirva  }
 
 program lasvieja;
 uses
   crt;
 type
    tablero = array[1..3,1..3] of char;
 
 
  var
    juego : tablero;
    cont, px, py : integer;
    posx, posy : integer;
    jug : char;
    sal : boolean;
 
  procedure presentapantalla(x1, y1 : integer);
  begin
   clrscr;
   gotoxy(x1,y1 + 1);write('*Tablero*');
   gotoxy(x1,y1 + 3);write('ÚÄÂÄÂÄ¿');
   gotoxy(x1,y1 + 4);write('³ ³ ³ ³');
   gotoxy(x1,y1 + 5);write('ÃÄÅÄÅÄ´');
   gotoxy(x1,y1 + 6);write('³ ³ ³ ³');
   gotoxy(x1,y1 + 7);write('ÃÄÅÄÅÄ´');
   gotoxy(x1,y1 + 8);write('³ ³ ³ ³');
   gotoxy(x1,y1 + 9);write('ÀÄÁÄÁÄÙ');
  end;
 
  procedure ponentablero(xp, yp : integer; cual : char);
  begin
    case xp of
  1 : px := 31;
  2 : px := 33;
  3 : px := 35;
    end;
    case yp of
  1 : py := 7;
  2 : py := 9;
  3 : py := 11;
    end;
  gotoxy(px,py);write(cual);
 end;
 
  procedure entasposiciones(c : char);
  var
    t : char;
    xx, yy : integer;
   begin
      gotoxy(20,13);write('Juega El Jugador = ',c);
      gotoxy(20,14);write('Posicion X : ');
      gotoxy(33,14);
      repeat
         t := readkey;
      until t in['1','2','3'];
      gotoxy(33,14);write(t);
      xx := ord(t) - 48;
      t := '0';
      gotoxy(20,15);write('Posicion Y : ');
      gotoxy(33,15);
      repeat
          t := readkey;
      until t in['1','2','3'];
      gotoxy(33,15);write(t);
      yy := ord(t) - 48;
      ponentablero(xx,yy,c);
      juego[xx,yy] := c;
      gotoxy(20,14);clreol;
      gotoxy(20,15);clreol;
      gotoxy(20,13);clreol;
   end;
 
   function completo(j : char) : boolean;
   begin
      completo := false;
      if (juego[1,1] = j) and (juego[2,1] = j) and (juego[3,1] = j) then
      completo := true
   else
      if (juego[1,2] = j) and (juego[2,2] = j) and (juego[3,2] = j) then
      completo := true
   else
      if (juego[1,3] = j) and (juego[2,3] = j) and (juego[3,3] = j) then
      completo := true
   else
      if (juego[1,1] = j) and (juego[1,2] = j) and (juego[1,3] = j) then
      completo := true
   else
      if (juego[2,1] = j) and (juego[2,2] = j) and (juego[2,3] = j) then
      completo := true
   else
      if (juego[3,1] = j) and (juego[3,2] = j) and (juego[3,3] = j) then
      completo := true
   else
      if (juego[1,1] = j) and (juego[2,2] = j) and (juego[3,3] = j) then
      completo := true
   else
      if (juego[3,1] = j) and (juego[2,2] = j) and (juego[1,3] = j) then
      completo := true;
   end;
 
  begin
      posx := 30;
      posy := 3;
      jug := 'X';
      presentapantalla(posx,posy);
      sal := false;
      cont := 1;
     repeat
      entasposiciones(jug);
      if completo(jug) then
      begin
         gotoxy(10,17);write('Gano El Jugador : ',jug);
         sal := true;
         break;
      end;
      if sal <> true then
      begin
         if jug = 'X' then
         jug := 'O'
       else
         jug := 'X';
         cont := cont + 1;
      end;
      until (sal = true) or (cont > 6);
      readkey;
  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