 , pero leí en un lado que c++ hace lo mismo pero pasando internamente "this", y aun así me sucede esto.
 , pero leí en un lado que c++ hace lo mismo pero pasando internamente "this", y aun así me sucede esto.esto me hace pensar que tal vez, debí quedarme con python
 
 ¿alguna recomendacion para evitar esto(si entendieron)?

uso DEV C++/MinGW
 , pero leí en un lado que c++ hace lo mismo pero pasando internamente "this", y aun así me sucede esto.
 , pero leí en un lado que c++ hace lo mismo pero pasando internamente "this", y aun así me sucede esto. 
 



 .
.// Listado: Participante.h
//
// Clase madre que proporciona una interfaz para los participantes
// que componen el juego
#ifndef _PARTICIPANTE_H_
#define _PARTICIPANTE_H_
#include <iostream>
#include <map>
#include "../recursos/CommonConstants.h"
#include <SDL/SDL.h>
class Imagen;
class Control_Animacion;
using namespace std;
class Participante {
 public:
    /*// Tipos de participantes
    enum tipo_participantes {
   TIPO_ARMA,
   TIPO_ALIEN_SIMPLE
    };*/
    // Estados posibles de los participantes
    enum estados {
   NORMAL,
   DISPARANDO
    };
    
    // Constructor
    Participante(int x, int y, int direccion = 1);
  
    // Consultoras 
    int pos_x(void);
    int pos_y(void);
    virtual void actualizar(void) = 0;
    void dibujar(SDL_Surface *pantalla);
    virtual ~Participante();
    
    estados estado_actual(void) {return estado;};
    
 protected:
    bool mover_sobre_x(int incremento);
    bool mover_sobre_y(int incremento,int rango=ALTO_VENTANA);
    Imagen *imagen;
    int x, y;
    int direccion;
    
    estados estado;
    estados estado_anterior;
    
    map<estados, Control_Animacion*> animaciones;
};
#endif
// Listado: Participante.cpp
//
// Implementacion de la clase Participante
#include <iostream>
#include "../recursos/CommonConstants.h"
#include "Participante.h"
#include "../engine/Imagen.h"
#include "../engine/Control_Animacion.h"
#include "../AtackAliens.h"
using namespace std;
Participante::Participante(int x, int y, int direccion)
{
    cout << "Participante::Participante()" << endl;
    // Inicializamos las variables
    this->direccion = 1;
    this->x = x;
    this->y = y;
}
int Participante::pos_x(void) {
    
    return x;
};
int Participante::pos_y(void) {
    return y;
};
Participante::~Participante() {
    cout << "Participante::~Participante()" << endl;
}
bool Participante::mover_sobre_x(int incremento) {
       if(this->x+incremento+this->imagen->anchura() < ANCHO_VENTANA &&this->x+incremento>0)
       {
           this->x += incremento;
           return true;
         }
         else
         return false;
    
}
bool Participante::mover_sobre_y(int incremento,int rango) {
       if(this->y+incremento+this->imagen->altura() < ALTO_VENTANA &&this->y+incremento>0&&this->y+incremento<rango)
       {
           this->y += incremento;
           return true;
         }
         else
             return false;
    
}
void Participante::dibujar(SDL_Surface *pantalla) {
        //DIBUJA EN LA NUEVA POSICION
        this->imagen->dibujar(pantalla, animaciones[estado]->cuadro(),x,y,direccion);
}
#ifndef _ALIEN_H_
#define _ALIEN_H_
#include <ctime>
#include "Participante.h"
class Alien:public Participante  {
   public:
           // Constructor
    
        Alien( int x, int y);
        void direccion_aleatoria();
   
        // Destructor
    
        ~Alien();
    
   protected:
       Uint8 velocidad;
       bool escogido_max_delay;
       int max_delay,delay;
       int dir_x,dir_y;
};
#endif
// Implementacion de la clase Alien
#include <iostream>
#include "Alien.h"
using namespace std;
// Constructor
Alien::Alien( int x, int y):
                 Participante(x,y) {
    // Inicializamos los atributos de la clase
    velocidad=2;
    estado=NORMAL;
    escogido_max_delay=false;
    delay=0;
    velocidad=2;
}
void Alien::direccion_aleatoria()
{ //REGRESA UNA DIRECCION aleatoria
       srand(time(0));
       for(int i=0;i<1+rand()%100;i++);
       int aleatorio=rand()%9;
       switch(aleatorio)
{
       case 0:
           this->dir_x=velocidad;
           this->dir_y=0;
       break;
       case 1:
           this->dir_x=0;
           this->dir_y=velocidad;
       break;
       case 2:
           this->dir_x=0;
           this->dir_y=-velocidad;
       break;
       case 3:
           this->dir_x=velocidad;
           this->dir_y=velocidad;
       break;
       case 4:
           this->dir_x=0;
           this->dir_y=0;
       break;
       case 5:
           this->dir_x=velocidad;
           this->dir_y=-velocidad;
       break;
       case 6:
           this->dir_x=-velocidad;
           this->dir_y=-velocidad;
       break;
       case 7:
           this->dir_x=-velocidad;
           this->dir_y=0;
       break;
       case 8:
           this->dir_x=-velocidad;
           this->dir_y=velocidad;
       break;
}
       
}
Alien::~Alien()
{
    cout << "Alien::~Alien()" << endl;
}
// Clase Arma
#ifndef _ALIEN_EXPLORADOR_H_
#define _ALIEN_EXPLORADOR_H_
#include "Alien.h"
class Alien_explorador:public Alien  {
 public:
    // Constructor
    Alien_explorador( int x=0, int y=0);
    void actualizar();
    void posicion_aleatoria();
    // Destructor
    ~Alien_explorador();
    
private:
        
    // Estados del alien
    // Para la implementacion del autómata
    void estado_normal();
    void estado_disparando();
    
};
#endif
// Implementacion de la clase Personaje
#include <iostream>
#include "../engine/Control_Animacion.h"
#include "../recursos/CommonConstants.h"
#include "../recursos/referencias.h"
#include <ctime>
#include "Alien_explorador.h"
using namespace std;
// Constructor
Alien_explorador::Alien_explorador(int x, int y):
               Alien(x, y) 
{
  cout <<"Alien_explorador::Alien_explorador"<<endl;
    // Asociamos al personaje las animaciones
    // segun la rejilla que cargamos para controlarlo
    this->imagen=galeria->imagen(Galeria::ALIEN_SIMPLE);
    if(!x&&!y)
       posicion_aleatoria();
    direccion_aleatoria();
    animaciones[NORMAL] = new Control_Animacion("0,1,2,3,4,5,6,7,8,9,10,11",5);
    animaciones[DISPARANDO] = new Control_Animacion("3", 6);
    //this->imagen = imagen_alien_simple;
}
void Alien_explorador::posicion_aleatoria()
{
     srand(time(NULL));
      for(int i=0;i<1+rand()%100;i++);
       this->x=1+rand()%ANCHO_VENTANA-imagen->anchura();
       this->y=1+rand()%ALTO_VENTANA/4*3;
     
}
                           
void Alien_explorador::actualizar(void) {
    // Si no estamos en el mismo estado 
    if(this->estado != this->estado_anterior) {
   
   // Comenzamos la animacion y guardamos el estado
   animaciones[estado]->reiniciar();
   this->estado_anterior = this->estado; 
    }
    // Implementacion del automata
    // Segun sea el estado
    switch(this->estado) {
     case NORMAL:
        estado_normal();
        break;
    
     case DISPARANDO:
        estado_disparando();
        break;
     default:
        cerr << "Estado no disponible" << endl;
    break;
    }
    
}
void Alien_explorador::estado_disparando(void) {
    // CONTROLA AL PERSONAJE MIENTRAS DISPARA
    
  /*  teclas = SDL_GetKeyState(NULL);
    
    if(teclas[this->TECLA_DERECHA])
            mover_sobre_x(5);
    
    if(teclas[this->TECLA_IZQUIERDA])
            mover_sobre_x(-5);
    
            
    if(animaciones[estado]->avanzar())
      estado = NORMAL;*/
}
void Alien_explorador::estado_normal(void) {
    // SI EL USUARIO TIENE PRESIONADO TECLA DE MOVIMIENTO DEBEMOS MOVER EL PERSONAJE
    this->delay++;
   if (!this->escogido_max_delay)
   {
        srand(time(0));
        this->max_delay=int(1+rand()%5)*100;
        this->escogido_max_delay=true;
        this->delay=0;
    }
        
   
    bool puede_x=mover_sobre_x(this->dir_x);
    bool puede_y=mover_sobre_y(this->dir_y,ALTO_VENTANA/4*3);
    if(!puede_x||!puede_y)
        direccion_aleatoria();
        
    this->animaciones[estado]->avanzar();
    
    if(this->delay>this->max_delay)
    {
         this->delay=0;
         this->escogido_max_delay=false;
         direccion_aleatoria();
     }
         
         
    
}
Alien_explorador::~Alien_explorador()
{
    cout << "Alien_explorador::~Alien_explorador()" << endl;
 
}
 
  " .
 " . :
 :
 la culpa es de
 la culpa es de srand()jeje
 :
 :#include <cstdlib>
#include <iostream>
using namespace std;
class Monster{
public:
Monster(){
srand(time(0));
x=rand()%5;
y=rand()%5;
};
int x,y;
};
int main(int argc, char *argv[])
{
Monster prueba[2];
cout << "Datos:\n";
cout<<"Monstruo 1:\n"<<"x,y="<<prueba[0].x<<","<<prueba[0].y<<endl;
cout<<"Monstruo 2:\n"<<"x,y="<<prueba[1].x<<","<<prueba[1].y<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}

Volver a Sobre lenguajes de programación
Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados