Beispiel #1
0
void tratarSolicitudRecurso(char* data) {

	personaje_recurso_t* personaje;
	int respuesta;

	personaje = personajeRecurso_deserializer(data);
	log_info(logFile, "Personaje %c solicito recurso %c.",
			personaje->idPersonaje, personaje->idRecurso);
	if (personajeEnCaja(personaje->idPersonaje, personaje->idRecurso)) {
		respuesta = darRecursoPersonaje(listaPersonajes, listaRecursos,
				personaje->idPersonaje, personaje->idRecurso, logFile);
	} else {
		log_error(logFile, "acceso incorrecto a caja de recurso: %s",
				personaje->idRecurso);
	}
	if (respuesta) {
		log_info(logFile, "Se le asigno el recurso: %c, al personaje: %c",
				personaje->idRecurso, personaje->idPersonaje);
		notificacionDarRecurso(personaje->idPersonaje);
		dibujar();
	} else {
		log_info(logFile, "Se bloqueo el personaje: %c, al pedir el recruso %c",
				personaje->idPersonaje, personaje->idRecurso);
		notificacionBloqueo(personaje->idPersonaje);
	}
}
Beispiel #2
0
void main(){
	int n_caballos,caballo,xcab,ycab;
   int posiciones[25]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
   bool final = false;


  	printf("Introduzca el numero de caballos (max 25): ");
   scanf ("%d",&n_caballos);
   clrscr();
   while (final == false){
      // Se selecciona al azar el caballo que avanzara
		caballo = random(n_caballos)+1;

      // Se modifica el valor del caballo elegido
      posiciones[caballo]++;

      xcab = posiciones[caballo];

      dibujar(xcab,caballo);

   	if(posiciones[caballo] == 60){
      	final = true;
         gotoxy(25,20);
         printf ("EL CABALLO GANADOR ES EL: %d", caballo);
   	}

   }
Beispiel #3
0
void main()
{
  int n;
  char sino;
  char fuera, contorno, dentro;

  sino = 's';
  while(sino == 's')
  {
    clrscr();

    printf("\n Ingresa un numero impar: ");
     scanf("%d", &n);

    if((n % 2) == 0) printf("\n Ingresaste un numero par");

    else
    {
      printf("\nPara dibujar una figura ingresa lo siguiente\n");
      printf("\nCENTRO CONTORNO FUERA");
      printf("\nIngresa 3 caracteres:");
      scanf("%s %s %s", &dentro, &contorno, &fuera);

      dibujar(n, fuera, contorno, dentro);

    }//else
    textcolor(WHITE);
    printf("\n\n Deseas ejecutar el programa de nuevo(s/n) ");
     scanf("%s", &sino);

  }//while(sino == 's')

}//void main()
Beispiel #4
0
int main(void) {
	fd_set bagMaster, bagEscucha;
	int sockfd, sockfdMax = plataformaSockfd, nbytes;
	int notifyfd;

	listaRecursos = list_create();
	listaPersonajes = list_create();
	listaEnemigos = list_create();

	mutexDibujables = malloc(sizeof(pthread_mutex_t));
	pthread_mutex_init(mutexDibujables, NULL );

	configObj = inicializarCongiuracionNivel();
	inicializarLog();
	inicializarInterfazGrafica();
	inicializarConfiguracionCajas();
	dibujar();
	inicializarConexionPlataforma();
	crearHiloEnemigo();
	crearHiloDeadLock();

	notifyfd = getNotifyFileDescriptor();
	FD_ZERO(&bagMaster);
	FD_ZERO(&bagEscucha);
	FD_SET(plataformaSockfd, &bagMaster);
	FD_SET(notifyfd, &bagMaster);

	if (notifyfd > sockfdMax) {
		sockfdMax = notifyfd;
	}

	while (1) {

		bagEscucha = bagMaster;

		select(sockfdMax + 1, &bagEscucha, NULL, NULL, NULL );

		for (sockfd = 0; sockfd < sockfdMax + 1; sockfd++) {
			if (FD_ISSET(sockfd,&bagEscucha)) {
				if (sockfd == plataformaSockfd) {
					nbytes = atenderMensajePlanificador(plataformaSockfd);
				} else if (sockfd == notifyfd) {
					tratarModificacionAlgoritmo(notifyfd);
				}
			}
		}

		if (nbytes <= 0) {
			log_error(logFile,
					"Finalizacion por que se perdio la conexion con plataforma");
			break;
		}
	}

	nivel_gui_terminar();
	return EXIT_SUCCESS;
}
Beispiel #5
0
void tratarNuevoPersonaje(char* data) {
	char pId;

	pId = data[0];
	log_info(logFile, "Creando Personaje %c", pId);
	CrearPersonaje(listaPersonajes, pId, 0, 0, 1, orden);
	orden++;
	dibujar();
}
////////////////////////////////////////////////////PROGRAMA PRINCIPAL////////////////////////////////////////////////////
int main (){
	nivelTerminado=false;
	huboCambios=false;

	listaDeEnemigos = list_create();
	items = list_create(); // CREO LA LISTA DE ITEMS
	listaPersonajesRecursos = list_create(); //CREO LA LISTA DE PERSONAJES CON SUS RECURSOS
	config = config_create(RUTA); //CREO LA RUTA PARA EL ARCHIVO DE CONFIGURACION

	pthread_mutex_init(&mutex_mensajes, NULL );
	pthread_mutex_init(&mutex_listas, NULL );
	pthread_mutex_init(&mutex_log, NULL );
	pthread_mutex_init(&mx_lista_items,NULL);

	leerArchivoConfiguracion(); //TAMBIEN CONFIGURA LA LISTA DE RECURSOS POR NIVEL
	dibujar();

	crearHiloInotify(hiloInotify);


	socketDeEscucha=handshakeConPlataforma();


	 //SE CREA UN SOCKET NIVEL-PLATAFORMA DONDE RECIBE LOS MENSAJES POSTERIORMENTE


	if (crearLosEnemigos){

		pthread_mutex_lock(&mutex_log);
		log_info(logger,"Se levantaron los enemigos");
		pthread_mutex_unlock(&mutex_log);

		crearHilosEnemigos();
	}
	if(activarInterbloqueo){
		crearHiloInterbloqueo();
	}

	while(1){
		if(socketDeEscucha!=-1){
			mensajesConPlataforma(socketDeEscucha); //ACA ESCUCHO TODOS LOS MENSAJES EXCEPTO HANDSHAKE

		}else{
			pthread_mutex_lock(&mutex_log);
			log_info(logger, "Hubo un error al leer el socket y el programa finalizara su ejecucion");
			pthread_mutex_unlock(&mutex_log);

			eliminarEstructuras();
			break;
		}

	}


	return true;
}
Beispiel #7
0
void tratarMovimiento(char* data) {
	char pId;
	coordenada_t* pCoordenada;
	int offset = sizeof(char);

	pId = data[0];
	pCoordenada = coordenadas_deserializer(data + offset);

	MoverPersonaje(listaPersonajes, pId, pCoordenada->ejeX, pCoordenada->ejeY,
			logFile);

	dibujar();

	free(pCoordenada);
}
int main() {

	srand( (unsigned)time( NULL ) ); // init Rand() function

	bintree<char> arbol=construir_char(5);

	bintree<int> arbol3=construir_int(5,0);

	bintree<string> arbol2=pasar_a_string(arbol3);

	CrearVentana(640,480,"bintreedraw");

	dibujar(arbol2.root(),320,20,0);

	click();

}
Beispiel #9
0
int atenderMensajePlanificador(int sockfd) {
	header_t h;
	t_list* asignados;
	int nbytes = validarRecive(sockfd, &h);
	if (nbytes) {
		char* data = malloc(h.length);
		switch (h.type) {
		case NOTIFICAR_DATOS_PERSONAJE:
			nbytes = recv(sockfd, data, h.length, MSG_WAITALL);
			tratarNuevoPersonaje(data);
			break;
		case UBICACION_CAJA:
			nbytes = recv(sockfd, data, h.length, MSG_WAITALL);
			tratarSolicitudUbicacionCaja(data);
			break;
		case NOTIFICACION_MOVIMIENTO:
			nbytes = recv(sockfd, data, h.length, MSG_WAITALL);
			tratarMovimiento(data);
			break;
		case SOLICITAR_RECURSO:
			nbytes = recv(sockfd, data, h.length, MSG_WAITALL);
			tratarSolicitudRecurso(data);
			break;
		case PERSONAJE_FINALIZO:
			nbytes = recv(sockfd, data, h.length, MSG_WAITALL);
			tratarFinalizacionPersonaje(data);
			break;
		case NOTIFICACION_RECURSOS_ASIGNADOS:
//			nbytes = recv(sockfd, data, h.length, MSG_WAITALL);
			asignados = esperarRecursosAsignados(h);
			actualizarEstado(asignados);
			list_destroy(asignados);
			dibujar();
			break;
		default:
			log_error(logFile,
					"Protocolo invalido (%d) para comunicarse con el nivel",
					h.type);
			break;
		}
		free(data);
	}
	return nbytes;
}
Beispiel #10
0
void main()
{
  int n;
  char sino;

  sino = 's';
  while(sino == 's')
  {
    clrscr();
    printf("\n Ingresa un numero: ");
     scanf("%d", &n);

    dibujar(n);

    printf("\n\n Deseas ejecutar el programa de nuevo(s/n) ");
     scanf("%s", &sino);

  }//while(sino == 's')

}//void main()
Beispiel #11
0
void main()
{
  int n;
  char sino;

  sino = 's';
  while(sino == 's')
  {
    clrscr();
    printf("\n Ingresa un numero impar: ");
     scanf("%d", &n);

    if((n % 2) == 0) printf("\n Ingresaste un numero par");

    else dibujar(n);

    printf("\n\n Deseas ejecutar el programa de nuevo(s/n) ");
     scanf("%s", &sino);

  }//while(sino == 's')

}//void main()
Beispiel #12
0
void enemigo(int idEnemigo) {
	t_list* bufferMovimiento = list_create();
	coordenada_t* posicion = malloc(sizeof(coordenada_t));
	agregarEnemigo(idEnemigo, posicion);
	int usegundos = (configObj->sleepEnemigos * 1000);
	int sec = div(usegundos, 1000000).quot; // para sleep
	int usec = div(usegundos, 1000000).rem; // para usleep
	log_trace(logFile, "Retardo enemigo segundos: %d, micro: %d", sec, usec);

	while (1) {

		sleep(sec);
		usleep(usec);

		cazarPersonajes(bufferMovimiento, posicion, idEnemigo);
		moverEnemigo(listaEnemigos, idEnemigo, posicion->ejeX, posicion->ejeY);

		dibujar();

		log_trace(logFile, "Enemigo: %d,se movio a posicion (%d, %d) ",
				idEnemigo, posicion->ejeX, posicion->ejeY);
	}

}
Beispiel #13
0
void Graph::notificado()
{
    dibujar();
}
Beispiel #14
0
void tElipse::dibujarCPS(TCanvas *canvas){
        dibujar(canvas);
        canvas->Brush->Color = color;
        canvas->Brush->Style = bsSolid;
        canvas->Rectangle(Xini-5,Yini-5,Xini+5,Yini+5);
}
Beispiel #15
0
int main ( int argc, char** argv )
{
    //Seleccion de la figura
    int seleccion = 1;
    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }
    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    //Crea una ventana nueva
    SDL_Surface* screen = SDL_SetVideoMode(largo,ancho, 16,
                                           SDL_HWSURFACE|SDL_DOUBLEBUF);
    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
    // carga de imagenes y cuadros para las imagenes
    SDL_Surface* cuadro = IMG_Load("rect.png");
    SDL_Surface* Scuadro = IMG_Load("selectedrect.png");
    if (!cuadro)
    {
        printf("Unable to load cuadro: %s\n", SDL_GetError());
        return 1;
    }
    SDL_Rect rectCuadro;
    rectCuadro.h = 100;
    rectCuadro.w = 100;
    rectCuadro.x = 100;
    rectCuadro.y = 300;


    SDL_Surface* circulo = IMG_Load("circle.png");
    SDL_Surface* Scirculo = IMG_Load("selectedcircle.png");
    if (!cuadro)
    {
        printf("Unable to load circulo: %s\n", SDL_GetError());
        return 1;
    }
    SDL_Rect rectCirculo;
    rectCirculo.x = 320-50 ;
    rectCirculo.y = 50;

    SDL_Surface* triangulo = IMG_Load("triangle.png");
    SDL_Surface* Striangulo = IMG_Load("selectedtriangle.png");
    if (!cuadro)
    {
        printf("Unable to load triangulo: %s\n", SDL_GetError());
        return 1;
    }
    SDL_Rect rectTriangulo;
    rectTriangulo.x = 400 ;
    rectTriangulo.y = 300;
    SDL_Rect *RectTurno = &rectCuadro;
    SDL_Surface *SurfaceTurno = Scuadro;
    SDL_Surface *dos = circulo;
    SDL_Rect rdos =rectCirculo;
    SDL_Surface *tres = triangulo;
    SDL_Rect rtres = rectTriangulo;
    //Bucle principal
    bool done = false;
    while (!done)
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // Verificacion de eventos
            switch (event.type)
            {
                //Sale si la vetana se cierra, de lo contrario no hara caso
            case SDL_QUIT:
                done = true;
                break;
                // Eventos del teclado
            case SDL_KEYDOWN:
                {
                    //Sale si la tecla scape es presionada
                    switch(event.key.keysym.sym)
                    {
                            case SDLK_ESCAPE:
                                done = true;
                            break;
                            case SDLK_UP:
                                moverY(&(RectTurno->y),-desplazamiento);
                            break;
                            case SDLK_DOWN:
                                moverY(&(RectTurno->y),+desplazamiento);
                            break;
                            case SDLK_LEFT:
                                moverX(&(RectTurno->x),-desplazamiento);
                            break;
                            case SDLK_RIGHT:
                                moverX(&(RectTurno->x),+desplazamiento);
                            break;
                            case SDLK_TAB:

                                seleccion = ((seleccion+1) % 3)+1;
                                switch(seleccion)
                                    {
                                        case 1:
                                            RectTurno = &rectCuadro;
                                            SurfaceTurno = Scuadro;
                                            dos = circulo;
                                            rdos = rectCirculo;
                                            tres = triangulo;
                                            rtres = rectTriangulo;
                                        break;
                                        case 2:
                                            RectTurno = &rectCirculo;
                                            SurfaceTurno = Scirculo;
                                            dos = triangulo;
                                            rdos = rectTriangulo;
                                            tres = cuadro;
                                            rtres = rectCuadro;
                                        break;
                                        case 3:
                                            RectTurno = &rectTriangulo;
                                            SurfaceTurno = Striangulo;
                                            dos = cuadro;
                                            rdos = rectCuadro;
                                            tres = circulo;
                                            rtres = rectCirculo;
                                        break;
                                    }
                                dibujar(screen,SurfaceTurno,RectTurno);
                                SDL_Flip(screen);
                            break;
                            default:
                            break;
                    }

                }//Fin delSDL_Keydown
            } // Fin el switch

        } //Fin del procesamiento de mensajes
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
        dibujar(screen,tres,&rtres);
        dibujar(screen,dos,&rdos);
        RectTurno->w = RectTurno->h =100;//El blit surface corta el cuadro.

        dibujar(screen,SurfaceTurno,RectTurno);
        SDL_Flip(screen);
    } // end main loop
    return 0;
}