![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
|||
|
|||
|
duda juego c++ builder 2007
Estoy haciendo el juego de simon dice en c++ builder 2007 y tengo la siguiente duda debo dimensionar un vector y he probado de un monton de formas y no soi capaz me da un error....
Mira pongo el codigo aver si alguien sabe a q se debe el error... Lo que kiero es dimensionar las variables vector y vectorentrada El error que me sale es el siguiente: Cita:
Código:
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
int repeticiones;
int contador;
short vector;
short vectorentrada;
int i;
const short limiteinf=1;
const short limitesup=4;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
void colores_iniciales()
{
Form2->I_1->Picture=Form2->I_gris1->Picture;
Form2->I_2->Picture=Form2->I_gris2->Picture;
Form2->I_3->Picture=Form2->I_gris3->Picture;
Form2->I_4->Picture=Form2->I_gris4->Picture;
}
void aleatorio(short limiteinf,short limitesup)
{
short aleatorio=0;
Randomize();
aleatorio=Int((limitesup-limiteinf+1)*Random()+limiteinf);
}
void inicio()
{
//int i;
vector.redim(repeticiones);
vectorentrada.redim(repeticiones);
for(i=1;i<repeticiones;i++)
{
vector[i] = aleatorio(limiteinf,limitesup);
}
Form2->I_1->Enabled=false;
Form2->I_2->Enabled=false;
Form2->I_3->Enabled=false;
Form2->I_4->Enabled=false;
Form2->Juego1->Enabled=false;
Form2->Acerca1->Enabled=false;
Form2->Secuenciador->Enabled=true;
contador=1;
}
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormShow(TObject *Sender)
{
colores_iniciales();
repeticiones=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Nuevo1Click(TObject *Sender)
{
inicio();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::SecuenciadorTimer(TObject *Sender)
{
colores_iniciales();
if(contador<=repeticiones)
{
L_Contador->Caption=contador;
switch((vector[contador]))
{
case 1:
I_1->Picture=I_rojo->Picture;
break;
case 2:
I_2->Picture=I_azul->Picture;
break;
case 3:
I_3->Picture=I_Amarillo->Picture;
break;
case 4:
I_4->Picture=I_Verde->Picture;
break;
} // fin switch;
contador=contador+1;
}
else {
L_Contador->Caption="";
contador=1;
Secuenciador->Enabled=false;
I_1->Enabled=true;
I_2->Enabled=true;
I_3->Enabled=true;
I_4->Enabled=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::BorradorTimer(TObject *Sender)
{
colores_iniciales();
Borrador->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Salir1Click(TObject *Sender)
{
Form2->Close();
}
//---------------------------------------------------------------------------
Última edición por dec fecha: 06-03-2009 a las 14:55:39. Razón: Poner las etiquetas QUOTE y CODE |
|
#2
|
||||
|
||||
|
Cita:
Imagino que lo que quieres es usar el template vector asi: Código:
#include <vector> ... ... std::vector<short> Vector(repeticiones); std::vector<short> VectorEntrada(repeticiones); |
|
#3
|
|||
|
|||
|
he probado con eso que me as puesto y me sigue saliendo un error en la funcion inicio:
el otro error de dimensionar el vector ya creo q lo e solucionado xq no me salen errores Código:
void inicio()
{
//int i;
std::vector<short> Vector(repeticiones);
std::vector<short> VectorEntrada(repeticiones);
for(i=1;i<repeticiones;i++)
{
/// aki me da el error siguiente: invalid direction
vector[i] = aleatorio(limiteinf,limitesup);
}
Form2->I_1->Enabled=false;
Form2->I_2->Enabled=false;
Form2->I_3->Enabled=false;
Form2->I_4->Enabled=false;
Form2->Juego1->Enabled=false;
Form2->Acerca1->Enabled=false;
Form2->Secuenciador->Enabled=true;
contador=1;
}
Última edición por dec fecha: 06-03-2009 a las 14:54:51. Razón: Poner las etiquetas CODE |
|
#4
|
||||
|
||||
|
el template se llama vector, por eso te cambié los nombres a Vector y VectorEntrada. C y C++ son sensibles a mayúsculas, esto quiere decir que vector y Vector no es lo mismo.
...así que cambia tu variable vector a Vector y vectorentrada a VectorEntrada. Esta última no hace falta, pero la camibé por estética y congruencia sintáctica con su "hermana" ![]() Saludos. |
|
#5
|
|||
|
|||
|
weno lo e intentao pro no lo consigo me sigue saliendo el mismo error que antes....
mira voi a poner el codigo dnd me da el fallo aver si sq tngo algo mal inicializado o mal escrito o algo..... CODIGO VARIABLES #include <vcl.h> #pragma hdrstop #include <Vector> #include "Unit2.h" int repeticiones; int contador; int Vector; int i; const short limiteinf=1; const short limitesup=4; CODIGO FUNCION void inicio() { //int i; std::vector<short> Vector(repeticiones); std::vector<short> VectorEntrada(repeticiones); //vector.redim(repeticiones); //vectorentrada.redim(repeticiones); for(i=1;i<repeticiones;i++) { Vector[i]=aleatorio(limiteinf,limitesup); // En esta linea es dnd me da el siguiente error: "Not an allowed type" y "Undefined symbol 'vector'" } Form2->I_1->Enabled=false; Form2->I_2->Enabled=false; Form2->I_3->Enabled=false; Form2->I_4->Enabled=false; Form2->Juego1->Enabled=false; Form2->Acerca1->Enabled=false; Form2->Secuenciador->Enabled=true; contador=1; } |
|
#6
|
||||
|
||||
|
Código:
#include <vcl.h>
#pragma hdrstop
#include <Vector>
#include "Unit2.h"
int repeticiones;
int contador;
// int Vector; Vector no es un entero, es un template que inicializas en inicio
int i;
const short limiteinf=1;
const short limitesup=4;
CODIGO FUNCION
void inicio()
{
//int i;
std::vector<short> Vector(repeticiones);
std::vector<short> VectorEntrada(repeticiones);
//vector.redim(repeticiones); // redim no es miembro del template vector
//vectorentrada.redim(repeticiones);
for(i=1;i<repeticiones;i++)
{
Vector[i]=aleatorio(limiteinf,limitesup); // En esta linea es dnd me da el siguiente error: "Not an allowed type" y "Undefined symbol 'vector'"
// El error es porque lo declaraste antes como int
}
......
......
}
|
![]() |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| juego c++ builder | torrescrack9 | Gráficos | 2 | 27-02-2009 17:34:17 |
| juego c++ builder | torrescrack9 | C++ Builder | 1 | 26-02-2009 19:52:07 |
| instalacion de zeos lib en c++ builder 2007 | 2-D@monic | C++ Builder | 0 | 18-05-2008 06:55:52 |
| C++ Builder 2007 | rruz | Noticias | 0 | 15-05-2007 08:39:33 |
| Duda sobre como programar el juego Timbiriche | mifiar | Varios | 16 | 26-11-2005 06:06:01 |
|