Pascal/Turbo Pascal - Ayuda Comparacion matriz

 
Vista:
sin imagen de perfil

Ayuda Comparacion matriz

Publicado por Manuel (4 intervenciones) el 27/06/2015 07:12:46
Necesito de su ayuda en este programa parecido al candy crush, tengo un problema con el procedure cascada que solo pude hacerlo para que comparara 3 numeros, pero necesito que pueda comparar mas de 3 y no se como hacerlo :(, una ayudita porfa.


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
Program pocket;
uses crt;
var candy:array[1..20,1..9] of byte;
	fil, col,cont, x, y,puntaje, fila, columna ,vida, figura : byte;
Procedure limpiar_matriz;
begin
	For y:= 1 To 20 Do
		For x:= 1 To 9 Do
			candy[y,x] := 0;
end;
Procedure llenado_matriz;
begin
	For y:= 1 To 20 Do
	begin
		For x:= 1 To 9 Do
                begin
		figura:= random(6)+1;
                candy[y,x]:= figura;
                if (x>1) and (candy[y,x] = candy[y,x-1]) and (candy[y,x] = candy[y,x-2]) then
                   begin
                   figura:= random(6)+1;
		   candy[y,x]:= figura;
                   end
                   else
                    candy[y,x]:= figura;
                end;
	end;
end;
Procedure mostrar_matriz;
Begin
     Clrscr;
     For y:= 1 To 20 Do
     begin
         For x:= 1 TO 9 Do
         begin
            Case candy[y,x] Of
               1:textcolor(magenta);
               2:TextColor(green);
               3:TextColor(yellow);
               4:TextColor(red);
               5:TextColor(brown);
               6:TextColor(blue);
               0:textcolor(black);
               end;
               Write(candy[y,x]:3);
            end;
               writeln;
         end;
 
End;
Procedure Bajada;
begin
     if fil > 1 then
     repeat
           begin
             candy[fil,col]:= candy[fil-1,col];
             candy[fil-1,col]:= 0;
             fil:=fil-1;
           end;
     until fil= 1;
     if candy[1,col]= 0 then
        candy[1,col]:= random(6)+1
     else
         candy[1,col]:= random(6)+1;
end;
Procedure cascada; <-------Este procedure es solo para comparar 3 numeros en la matriz y no se como hacerlo para
                                                 que compare mas, aca necesito ayuda :/.
begin
     begin
          if fil > 1 then
          repeat
           begin
             candy[fil,col]:= candy[fil-1,col];
             candy[fil-1,col]:= 0;
             candy[fil,col+1]:= candy[fil-1,col+1];
             candy[fil-1,col+1]:= 0;
             candy[fil,col+2]:= candy[fil-1,col+2];
             candy[fil-1,col+2]:= 0;
             fil:=fil-1;
           end;
           until fil= 1;
           if candy[1,col]= 0 then
           begin
           candy[1,col]:= random(6)+1;
           candy[1,col+1]:= random(6)+1;
           candy[1,col+2]:= random(6)+1;
           end
           else
           candy[1,col]:= random(6)+1;
           candy[1,col+1]:= random(6)+1;
           candy[1,col+2]:= random(6)+1;
     end;
end;
Procedure Eliminar_linea;
begin
     For fil := 1 To 20 Do
     begin
         For col:= 1 To 9 Do
         begin
             If (col< 8) and (candy[fil,col] = candy[fil,col+1]) and (candy[fil,col] = candy[fil,col+2]) THEN
             begin
                  puntaje:=puntaje+(candy[fil,col]*3);
                  candy[fil,col]:=0;
                  candy[fil,col+1]:=0;
                  candy[fil,col+2]:=0;
                  cascada;
             end;
         end;
     end;
end;
begin
     textbackground(white);
	clrscr;
               randomize;
 
		limpiar_matriz;
		llenado_matriz;
		mostrar_matriz;
		        puntaje:= 0;
                vida:= 2;
                textcolor(black);
                while vida <> 0 do
                begin
                     writeln('ingrese cordenada de filas para eliminar: ');
                     readln(fil);
                     writeln('ingrese cordenada de columnas para eliminar: ');
                     readln(col);
                     candy[fil,col]:= 0;
                     Bajada;
                     eliminar_linea;
                     vida:= vida -1;
                     mostrar_matriz;
               end;
               writeln(puntaje);
		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

Ayuda Comparacion matriz

Publicado por ramon (2158 intervenciones) el 27/06/2015 22:26:17
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
{A ver si ayuda}
 
 program candy_crush;
 uses
    crt;
  type
     candy = array[1..9,1..20] of byte;
     caracteres = array[1..6] of char;
 
   var
     cand : candy;
     carac : caracteres;
     posx, posy, x, y, i, t : integer;
     car : byte;
 
   procedure limpia;
   begin
      fillchar(cand,sizeof(cand),0);
      fillchar(carac,sizeof(carac),'0');
   end;
 
  procedure rellenacandy;
  begin
     for i := 1 to 6 do
       carac[i] := chr(i);
     for y := 1 to 20 do
       for x := 1 to 9 do
       begin
          t := random(5) + 1;
          cand[x,y] := ord(carac[t]);
       end;
  end;
 
  procedure presentacandy(cx, cy : integer);
  var
     u, d : integer;
  begin
     TextBackground(7);
     for u := 1 to (11 * 2) do
       for d := 1 to 22 do
       begin
       gotoxy((cx - 2) + u,(cy - 1) + d);write(' ');
       end;
     for y := 1 to 20 do
       for x := 1 to 9 do
       begin
       case cand[x,y] of
   1 : textcolor(14);
   2 : textcolor(15);
   3 : textcolor(4);
   4 : textcolor(3);
   5 : textcolor(1);
   6 : textcolor(7);
     end;
        if cand[x,y] > 0 then
        begin
        gotoxy(cx + (x * 2),cy + y);write(cand[x,y]);
        end
     else
        begin
         textcolor(0);
         gotoxy(cx + (x * 2),cy + y);write(' ');
        end;
        textcolor(15);
       end;
  end;
 
  procedure compara_derecha(ll,ii : integer; m : byte);
  var
     jj, g : integer;
     ss : byte;
  begin
     for jj := ll + 1 to 9 do
     if cand[jj,ii] = m then
     begin
        for g := ii downto 2 do
        cand[jj,g] := cand[jj,g - 1];
        ss := random(5) + 1;
        cand[jj,g - 1] := ss;
     end
  else
      begin
        break;
      end;
  end;
 
  procedure compara_izquierda(ll,ii : integer; m : byte);
  var
     jj, g : integer;
     ss : byte;
  begin
     for jj := ll - 1 downto 1 do
     if cand[jj,ii] = m then
     begin
        for g := ii downto 2 do
        cand[jj,g] := cand[jj,g - 1];
        ss := random(5) + 1;
        cand[jj,g - 1] := ss;
     end
   else
      begin
        break;
      end;
  end;
 
  procedure compara_abajo(ll,ii : integer; m : byte);
  var
     jj, g : integer;
     ss : byte;
    begin
       for jj := ii to 20 do
       if cand[ll,jj] = m then
       begin
       for g := ii downto 2 do
        cand[ll,jj] := cand[ll,jj - 1];
        ss := random(5) + 1;
        cand[ll,jj - 1] := ss;
       end
    else
       begin
         break;
       end;
    end;
 
   procedure compara_arriva(ll,ii : integer; m : byte);
  var
     jj, g : integer;
     ss : byte;
    begin
       for jj := ii downto 1 do
       if cand[ll,jj] = m then
       begin
       for g := ii downto 2 do
        cand[ll,jj] := cand[ll,jj - 1];
        ss := random(5) + 1;
        cand[ll,jj - 1] := ss;
       end
    else
       begin
         break;
       end;
    end;
 
 
 
  procedure entrada_cordenadas(var corx, cory : integer);
  begin
     TextBackground(0);
     gotoxy(19,24);write('                                         ');
     gotoxy(19,24);write(' Entre cordenada X : ');
     gotoxy(40,24);readln(corx);
     gotoxy(19,24);clreol;
     gotoxy(19,24);write(' Entre cordenada Y : ');
     gotoxy(40,24);readln(cory);
     gotoxy(19,24);clreol;
  end;
 
 
   begin
      clrscr;
      randomize;
      limpia;
      rellenacandy;
      presentacandy(20,2);
      entrada_cordenadas(posx, posy);
      car := cand[posx,posy];
      compara_derecha(posx,posy,car);
      compara_izquierda(posx,posy,car);
      compara_abajo(posx,posy,car);
 
      presentacandy(20,2);
      readkey;
      TextBackground(0);
      clrscr;
   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