Ayuda con un problemita de arreglo
Publicado por Kira (2 intervenciones) el 20/06/2014 22:32:16
Hola amigos, tengo una consulta, estoy haciendo una interfaz para un menú de un juego que me pidieron la para la facu. Tengo un problema, cuando pruebo el programa para ver si funciona el cambio de opciones en el menu me tira un error cuando cambio de la opcion 1 (JUGAR) a la opcion 3 (SALIR), el arreglo de las opciones tiene una dimension de 3 espacios, sin embargo cuando llamo al procedimiento cambiarOpcion (todos sus parametros correctos) me tira un error.
NOTA: probando me di cuenta que si a opcionesTotal le resto 1 cuando llamo a cambiarOpcion, no salta error, pero no hace lo que yo quiero.
NOTA: probando me di cuenta que si a opcionesTotal le resto 1 cuando llamo a cambiarOpcion, no salta error, pero no hace lo que yo quiero.
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
program colorCrush;
uses
crt;
//CONSTANTES - INICIO
const
COLOR_ROJO = 12;
COLOR_VERDE = 10;
COLOR_AZUL = 9;
COLOR_BLANCO = 15;
COLOR_AMARILLO = 14;
COLOR_NORMAL = 7;
MAX_FILAS = 5;
MAX_COLUMNAS = 5;
MAX_OPCIONES = 3;
MAX_COLORES = 4;
MAX_ESPACIOS = 10;
STR_OPC_SELECTOR = '->';
COL_OPC_SELECTOR = COLOR_AMARILLO;
INT_NULO = -1;
STR_NULO = '¿';
CHA_BORDE = '█';
CHA_BLOQUE = '▓';
COLOR_BORDE = COLOR_AMARILLO;
TECLA_IZQUIERDA = #75;
TECLA_DERECHA = #77;
TECLA_ABAJO = #80;
TECLA_ARRIBA = #72;
TECLA_ENTER = #13;
TECLA_ESC = #27;
//CONSTANTES - FIN
//TIPOS - INICIO
type vecIntColores = array[1..MAX_COLORES] of integer;
type vecIntPuntajes = array[1..MAX_ESPACIOS] of integer;
type vecStrJugadores = array[1..MAX_ESPACIOS] of string;
type objOpciones = record
opcionNumero, opcionX, opcionY: integer;
opcionTexto: string;
end;
type matIntMapa = array[1..MAX_COLUMNAS, 1..MAX_FILAS] of integer;
//TIPOS - FIN
//PRODECIMIENTOS Y FUNCIONES - INICIO
{PROCEDIMIENTO: inicVecInteger}
procedure inicVecInteger(var vector: vecIntPuntajes; limite, datoNulo: integer);
var
i: integer;
begin
for i := 1 to limite do
vector[i] := datoNulo;
end;
{PROCEDIMIENTO: inicVecString}
procedure inicVecString(var vector: vecStrJugadores; limite: integer; datoNulo: string);
var
i: integer;
begin
for i := 1 to limite do
vector[i] := datoNulo;
end;
{PROCEDIMIENTO: inicMatInteger}
procedure inicMatInteger(var matriz: matIntMapa; limiteX, limiteY, datoNulo: integer);
var
x, y: integer;
begin
for x := 1 to limiteX do
begin
for y := 1 to limiteY do
matriz[x, y] := datoNulo;
end;
end;
{PROCEDIMIENTO: inicMatIntegerColores}
procedure inicMatIntegerColores(var matriz: matIntMapa; limiteX, limiteY: integer);
var
x, y, aux: integer;
begin
for x := 1 to limiteX do
begin
for y := 1 to limiteY do
begin
aux := Random(MAX_COLORES) + 1;
matriz[x, y] := aux;
end;
end;
end;
{FUNCION: limiteVecInteger}
function limiteVecInteger(vector: array of integer; dimension: integer): integer;
var
i, suma: integer;
begin
suma := 0;
for i := 1 to dimension do
begin
if vector[i] <> INT_NULO then
suma := suma + 1;
end;
limiteVecInteger := suma;
end;
{PROCEDIMIENTO: inicializarDatos}
procedure inicializarDatos(vecColores: vecIntColores; vecPuntajes: vecIntPuntajes; vecJugadores: vecStrJugadores; matMapa: matIntMapa);
begin
vecColores[1] := COLOR_ROJO;
vecColores[2] := COLOR_VERDE;
vecColores[3] := COLOR_AZUL;
vecColores[4] := COLOR_BLANCO;
inicVecInteger(vecPuntajes, MAX_ESPACIOS, INT_NULO);
inicVecString(vecJugadores, MAX_ESPACIOS, STR_NULO);
inicMatInteger(matMapa, MAX_COLUMNAS, MAX_FILAS, INT_NULO);
end;
{PROCEDIMIENTO: escribirConColor}
procedure escribirConColor(texto: string; color: integer);
begin
TextColor(color);
Write(texto);
TextColor(COLOR_NORMAL);
end;
{PROCEDIMIENTO: crearFila}
procedure crearFila(posicionX, posicionY, largo: integer);
var
i : integer;
begin
GotoXY(posicionX, posicionY);
for i := 1 to largo do
escribirConColor(CHA_BORDE, COLOR_BORDE);
end;
{PROCEDIMIENTO: crearColumna}
procedure crearColumna(posicionX, posicionY, alto: integer);
var
i: integer;
begin
for i := 1 to alto do
begin
GotoXY(posicionX, posicionY - 1 + i);
escribirConColor(CHA_BORDE, COLOR_BORDE);
end;
end;
{PROCEDIMIENTO: escribirMatriz}
procedure escribirMatriz(matriz: matIntMapa; posicionX, posicionY, limiteX, limiteY: integer; color: vecIntColores);
var
x, y: integer;
begin
for x := 1 to limiteX do
begin
for y := 1 to limiteY do
begin
GotoXY(posicionX - 1 + x, posicionY - 1 + y);
escribirConColor(CHA_BLOQUE, color[matriz[x, y]]);
end;
end;
end;
//
{PROCEDIMIENTO: cambiarOpcion}
procedure cambiarOpcion(objOpciones: array of objOpciones; opciones: integer; var opcionActual: integer; tecla: char);
var
i : integer;
begin
if tecla = TECLA_ARRIBA then
begin
GotoXY(objOpciones[opcionActual].opcionX - 1, objOpciones[opcionActual].opcionY);
for i := 1 to Length(STR_OPC_SELECTOR) do
Write(' ');
if opcionActual <= 1 then
begin
opcionActual := opciones;
end
else
begin
opcionActual := opcionActual - 1;
end;
GotoXY(objOpciones[opcionActual].opcionX - 1, objOpciones[opcionActual].opcionY);
escribirConColor(STR_OPC_SELECTOR, COL_OPC_SELECTOR);
Write(opcionActual);
end
else
begin
end;
end;
{PROCEDIMIENTO: procJugar}
procedure procJugar;
begin
//escribirMatriz(
end;
{PROCEDIMIENTO: procPuntajes}
procedure procPuntajes;
begin
end;
{PROCEDIMIENTO: procMenu}
procedure procMenu(matriz: matIntMapa; colores: vecIntColores);
var
i, totalOpciones: integer;
escrito, opcionesCargadas, salir: boolean;
menuOpciones: array[1..MAX_OPCIONES] of objOpciones;
opcionActual: integer;
tecla: char;
begin
escrito := false;
opcionesCargadas := false;
salir := false;
opcionActual := 1;
totalOpciones := 3;
for i := 1 to totalOpciones do
begin
menuOpciones[i].opcionNumero := i;
menuOpciones[i].opcionX := 4;
menuOpciones[i].opcionY := 5 + 2 * i;
end;
menuOpciones[1].opcionTexto := 'JUGAR';
menuOpciones[2].opcionTexto := 'PUNTAJES';
menuOpciones[3].opcionTexto := 'SALIR';
if not escrito then
begin
ClrScr();
crearColumna(1, 1, 13);
crearColumna(15, 1, 13);
crearFila(1, 1, 15);
crearFila(1, 5, 15);
crearFila(1, 13, 15);
GotoXY(3, 3);
escribirConColor('CO', COLOR_ROJO);
escribirConColor('LO', COLOR_VERDE);
escribirConColor('R C', COLOR_AZUL);
escribirConColor('RU', COLOR_BLANCO);
escribirConColor('SH', COLOR_ROJO);
for i := 1 to totalOpciones do
begin
if i = opcionActual then
begin
GotoXY(menuOpciones[i].opcionX - 1, menuOpciones[i].opcionY);
escribirConColor(STR_OPC_SELECTOR, COL_OPC_SELECTOR);
end
else
begin
GotoXY(menuOpciones[i].opcionX + 1, menuOpciones[i].opcionY);
end;
escribirConColor(menuOpciones[i].opcionTexto, COLOR_BLANCO);
end;
end;
repeat
tecla := ReadKey();
if (tecla = TECLA_ABAJO) or (tecla = TECLA_ARRIBA) then
begin
cambiarOpcion(menuOpciones, totalOpciones, opcionActual, tecla);
end
else
begin
case opcionActual of
1:
procJugar();
2:
procPuntajes();
3:
salir := true;
end;
end;
until salir = true;
end;
//PRODECIMIENTOS Y FUNCIONES - FIN
var
vecColores: vecIntColores;
vecPuntajes: vecIntPuntajes;
vecJugadores: vecStrJugadores;
matMapa: matIntMapa;
begin
HighVideo();
inicializarDatos(vecColores, vecPuntajes, vecJugadores, matMapa);
procMenu(matMapa, vecColores);
end.
Valora esta pregunta


0