Example #1
0
// recibe una direccion y un perro, al cual debe mover en esa dirección
// *** viene del syscall mover ***
uint game_perro_mover(perro_t *perro, direccion dir)
{
    int x, y;
    uint res = game_dir2xy(dir, &x, &y);
    int nuevo_x = perro->x + x;
    int nuevo_y = perro->y + y;
    int viejo_x = perro->x;
    int viejo_y = perro->y;

    if (res == 0 &&
        game_es_posicion_valida(nuevo_x, nuevo_y) &&
        ! game_hay_perros_de(nuevo_x, nuevo_y, perro->jugador)
    ) {
        screen_borrar_perro(perro);
        perro->x = nuevo_x;
        perro->y = nuevo_y;
        mmu_mover_perro(perro, viejo_x, viejo_y);
        screen_pintar_perro(perro);
        res = 0;
    } else {
    	res = -1;
    }

    return res;
}
Example #2
0
File: jugador.c Project: araml/OC2
// recibe un par (x, y) y un jugador, al cual debe mover en esa dirección
uint game_jugador_moverse(jugador_t *j, int x, int y) {
    int nuevo_x = j->x + x;
    int nuevo_y = j->y + y;

    // ~~~ completar ~~~
    if (!game_es_posicion_valida(nuevo_x, nuevo_y)) return 0;
    screen_borrar_jugador(j);
    j->x = nuevo_x;
    j->y = nuevo_y;
    screen_pintar_jugador(j);
    return 1; // uso todas las variables locales para que no tire warning -> error
}
Example #3
0
// recibe una direccion y un perro, al cual debe mover en esa dirección
// *** viene del syscall mover ***
uint game_perro_mover(perro_t *perro, direccion dir)
{
	int x, y;
	game_dir2xy(dir, &x, &y);
	int nuevo_x = perro->x + x;
	int nuevo_y = perro->y + y;
    //int viejo_x = perro->x;
    //int viejo_y = perro->y;
    uint cr3 = perro->cr3;

    // ~~~ completar ~~~
    //verificar si se sale del tablero
    if (!game_es_posicion_valida(nuevo_x, nuevo_y)) {
    	return NULL;
    }

	perro_t *otro_perro;
    //verificar si hay otro perro del mismo jugador ahi
    otro_perro = game_perro_hay_perro_de_jugador(perro->jugador, nuevo_x, nuevo_y);
    if ( otro_perro != NULL) {
    	//game_perro_termino(otro_perro);
    	return NULL;
    }

    jugador_t* otro_jugador;

    if (&jugadorA == perro->jugador) {
    	otro_jugador = &jugadorB;
    }

    //verificar si hay otro perro del otro jugadr ahi
    otro_perro = game_perro_hay_perro_de_jugador(otro_jugador, nuevo_x, nuevo_y);
    if ( otro_perro != NULL) {
    	//debemos matar al perro
    	//sched_remover_tarea(sched_buscar_gdtindex_tarea_desde_perro(otro_perro));
    	game_perro_termino(otro_perro);
    }
    screen_borrar_perro(perro);

    //mapeamos como lo pide el enunciado la nueva posicion visitada en modo solo lectura
 	mmu_mapear_pagina(mmu_xy2virtual(nuevo_x, nuevo_y), cr3, mmu_xy2fisica(nuevo_x, nuevo_y), 0x5);
 	// luego copiamos código y pila a la nueva posición de memoria
    mmu_copiar_pagina(0x401000, mmu_xy2virtual(nuevo_x, nuevo_y));	
    // por último mapeamos la dirección 0x401000 a la nueva dirección fisica donde el codigo copiado 
    // y la pila se alojan, con nivel de usuario, y de lectura/escritura
    mmu_mapear_pagina(0x401000, cr3, mmu_xy2fisica(nuevo_x, nuevo_y), 0x7);	
    
    perro->x = nuevo_x;
    perro->y = nuevo_y;

    return 1;
}