Exemplo n.º 1
0
 def __load_config_settings(self, nuevo_usuario=True):
     settings_file = open(os.path.abspath(self.__main_path + "/data/config_settings.xml"))
     parser = Parser()
     elementos_configuracion = parser.find_child_element("configuration_settings",settings_file)
     for e in elementos_configuracion:
         if e.get_name() == "dialogues":
             if e.get_attribute('interrupt') == 'yes':
                 self.__interrumpir_dialogos = True
             else:
                 self.__interrumpir_dialogos = False
         elif e.get_name() == "sounds":
             if e.get_attribute('interrupt') == 'yes':
                 self.__interrumpir_sonidos_entre_turnos = True
             else:
                 self.__interrumpir_sonidos_entre_turnos = False
         elif e.get_name() == "initial_state" and nuevo_usuario:
             self.set_state(e.get_attribute('name'))
         elif e.get_name() == "initial_context":
             self.__contexto = e.get_attribute('constant')
         elif e.get_name() == "shorcuts":
             if e.get_attribute('games') == 'yes':
                 self.__atajos_juegos = True
             else:
                 self.__atajos_juegos = False
             if e.get_attribute('tutorials') == 'yes':
                 self.__atajos_tutoriales = True
             else:
                 self.__atajos_tutoriales = False
     settings_file.close()
     parser.close()
Exemplo n.º 2
0
 def __get_xml_info(self, archivo, etiqueta):
     f = open(archivo)
     p = Parser()
     elementos = p.find_child_element(etiqueta, f)
     p.close()
     f.close()
     return elementos
Exemplo n.º 3
0
 def __get_xml_info(self,archivo,etiqueta):
     f = open(archivo)
     p = Parser()
     elementos = p.find_child_element(etiqueta,f)
     p.close()
     f.close()
     return elementos
Exemplo n.º 4
0
 def __load_config_settings(self, nuevo_usuario=True):
     settings_file = open(
         os.path.abspath(self.__main_path + "/data/config_settings.xml"))
     parser = Parser()
     elementos_configuracion = parser.find_child_element(
         "configuration_settings", settings_file)
     for e in elementos_configuracion:
         if e.get_name() == "dialogues":
             if e.get_attribute('interrupt') == 'yes':
                 self.__interrumpir_dialogos = True
             else:
                 self.__interrumpir_dialogos = False
         elif e.get_name() == "sounds":
             if e.get_attribute('interrupt') == 'yes':
                 self.__interrumpir_sonidos_entre_turnos = True
             else:
                 self.__interrumpir_sonidos_entre_turnos = False
         elif e.get_name() == "initial_state" and nuevo_usuario:
             self.set_state(e.get_attribute('name'))
         elif e.get_name() == "initial_context":
             self.__contexto = e.get_attribute('constant')
         elif e.get_name() == "shorcuts":
             if e.get_attribute('games') == 'yes':
                 self.__atajos_juegos = True
             else:
                 self.__atajos_juegos = False
             if e.get_attribute('tutorials') == 'yes':
                 self.__atajos_tutoriales = True
             else:
                 self.__atajos_tutoriales = False
     settings_file.close()
     parser.close()
Exemplo n.º 5
0
 def init_game(self, nombre, con_jugadas_posibles=True, nivel=Ai.FACIL):
     parser = Parser()
     archivo_juegos = open(os.path.abspath(self.__path_archivo_juegos))
     elementos = parser.find_child_element("game_" + str(nombre),
                                           archivo_juegos)
     fichas_iniciales = []
     if len(elementos) <= 0:
         raise Exception("No se encontraron elementos para el juego: " +
                         nombre + " en el archivo xml: " +
                         self.__path_archivo_juegos)
     for e in elementos:
         if e.get_name() == 'features':
             board_dim = int(e.get_attribute('board'))
             if e.get_attribute('oponent') == "virtual":
                 #Es un juego de mesh contra Humano
                 jugador1 = Player(BLANCO, HUMANO)
                 jugador2 = Player(NEGRO, VIRTUAL)
             else:
                 #Es un juego contra la PC
                 if e.get_attribute('white') == "user":
                     jugador1 = Player(BLANCO, HUMANO)
                     jugador2 = Player(NEGRO, PC)
                 else:
                     jugador1 = Player(BLANCO, PC)
                     jugador2 = Player(NEGRO, HUMANO)
             if e.get_attribute('initiator') == "white":
                 comienza = BLANCO
             else:
                 comienza = NEGRO
         elif e.get_name() == 'piece':
             ficha = {}
             if e.get_attribute('color') == "black":
                 ficha["color"] = NEGRO
             else:
                 ficha["color"] = BLANCO
             ficha["posicion"] = (int(e.get_attribute('pos_f')),
                                  int(e.get_attribute('pos_c')))
             fichas_iniciales.append(ficha)
     tablero_logico = Board(board_dim)
     if nombre == "tutorial1":
         tablero_logico.save_initial_configuration(fichas_iniciales)
     else:
         tablero_logico.set_up(fichas_iniciales)
     self.__video.create_graphic_board(tablero_logico)
     self.juego = Game(self.__video.board,
                       jugador1,
                       jugador2,
                       con_jugadas_posibles,
                       nivel,
                       write_path=self.__write_path)
     if comienza == BLANCO:
         self.juego.set_turn(jugador1)
     else:
         self.juego.set_turn(jugador2)
     self.juego.increase_turn_number()
     if nombre == "mesh":
         self.juego.set_mesh_game(True)
         self.__usuario.set_player(jugador1)
     parser.close()
     archivo_juegos.close()
Exemplo n.º 6
0
 def get_sound_file_name(self, categoria="", tipo="", nombre=""):
     self.__f = open(
         os.path.abspath(self.__main_path + "/data/resources.xml"))
     self.__parser = Parser()
     attrs = {'type': tipo, 'name': nombre}
     elemento = self.__parser.find_element_attribute(
         categoria, attrs, self.__f)
     if elemento.is_empty():
         raise Exception(
             "No se encontro el elemento en el archivo XML (Sounds Class)")
     self.__f.close()
     self.__parser.close()
     return os.path.abspath(self.__main_path + elemento.get_text('str'))
Exemplo n.º 7
0
 def init_game(self, nombre, con_jugadas_posibles=True, nivel=Ai.FACIL):
     parser = Parser()
     archivo_juegos = open(os.path.abspath(self.__path_archivo_juegos))
     elementos = parser.find_child_element("game_"+str(nombre),archivo_juegos)
     fichas_iniciales = []
     if len(elementos) <= 0 :
         raise Exception("No se encontraron elementos para el juego: " + nombre + " en el archivo xml: " + self.__path_archivo_juegos)
     for e in elementos:
         if e.get_name() == 'features':
             board_dim = int(e.get_attribute('board'))
             if e.get_attribute('oponent') == "virtual":
                 #Es un juego de mesh contra Humano
                 jugador1 = Player(BLANCO,HUMANO)
                 jugador2 = Player(NEGRO,VIRTUAL)
             else:
                 #Es un juego contra la PC
                 if e.get_attribute('white') == "user":
                     jugador1 = Player(BLANCO,HUMANO)
                     jugador2 = Player(NEGRO,PC)
                 else:
                     jugador1 = Player(BLANCO,PC)
                     jugador2 = Player(NEGRO,HUMANO)
             if e.get_attribute('initiator') == "white":
                 comienza = BLANCO
             else:
                 comienza = NEGRO
         elif e.get_name() == 'piece':
             ficha = {}
             if e.get_attribute('color') == "black":
                 ficha["color"] = NEGRO
             else:
                 ficha["color"] = BLANCO
             ficha["posicion"] = (int(e.get_attribute('pos_f')),int(e.get_attribute('pos_c')))
             fichas_iniciales.append(ficha)
     tablero_logico = Board(board_dim)
     if nombre == "tutorial1":
         tablero_logico.save_initial_configuration(fichas_iniciales)
     else:
         tablero_logico.set_up(fichas_iniciales)
     self.__video.create_graphic_board(tablero_logico)
     self.juego = Game(self.__video.board,jugador1,jugador2,con_jugadas_posibles,nivel,write_path=self.__write_path)
     if comienza == BLANCO:
         self.juego.set_turn(jugador1)
     else:
         self.juego.set_turn(jugador2)
     self.juego.increase_turn_number()
     if nombre == "mesh":
         self.juego.set_mesh_game(True)
         self.__usuario.set_player(jugador1)
     parser.close()
     archivo_juegos.close()
Exemplo n.º 8
0
 def save_state(self, state, main_path):
     f = open(os.path.abspath(main_path + "/data/hyperhistory.xml"))
     p = Parser()
     self.__nombre = state
     elementos = p.find_child_element(state, f)
     for e in elementos:
         if e.get_name() == 'character':
             if e.get_attribute('enable_play') == 'yes':
                 habilitado_juego = True
             else:
                 habilitado_juego = False
             if e.get_attribute('enable_dialogue') == 'yes':
                 habilitado_dialogo = True
             else:
                 habilitado_dialogo = False
             personaje = {}
             personaje['juego'] = habilitado_juego
             personaje['dialogo'] = habilitado_dialogo
             self.__personajes[e.get_attribute('id')] = personaje.copy()
         elif e.get_name() == 'room':
             if e.get_attribute('enable') == 'yes':
                 habilitada = True
             else:
                 habilitada = False
             hab = {}
             hab['habilitada'] = habilitada
             self.__habitaciones[e.get_attribute('id')] = hab.copy()
         elif e.get_name() == 'key':
             if e.get_attribute('enable') == 'yes':
                 habilitada = True
             else:
                 habilitada = False
             hab = {}
             hab['habilitada'] = habilitada
             self.__teclas[e.get_attribute('id')] = hab.copy()
         elif e.get_name() == 'precondition':
             self.__precondiciones.append(e.get_attribute('name'))
         elif e.get_name() == 'action':
             accion = {}
             accion['nombre'] = e.get_attribute('name')
             accion['consecuencia'] = e.get_attribute('consequences')
             accion['nuevo_estado'] = e.get_attribute('new_state')
             self.__acciones.append(accion.copy())
         elif e.get_name() == 'event':
             event = {}
             event['nombre'] = e.get_attribute('name')
             event['tipo'] = e.get_attribute('type')
             event['consecuencia'] = e.get_attribute('consequences')
             event['nuevo_estado'] = e.get_attribute('new_state')
             self.__eventos.append(event.copy())
Exemplo n.º 9
0
 def save_state(self, state, main_path):
     f = open(os.path.abspath(main_path + "/data/hyperhistory.xml"))
     p = Parser()
     self.__nombre = state
     elementos = p.find_child_element(state, f)
     for e in elementos:
         if e.get_name() == "character":
             if e.get_attribute("enable_play") == "yes":
                 habilitado_juego = True
             else:
                 habilitado_juego = False
             if e.get_attribute("enable_dialogue") == "yes":
                 habilitado_dialogo = True
             else:
                 habilitado_dialogo = False
             personaje = {}
             personaje["juego"] = habilitado_juego
             personaje["dialogo"] = habilitado_dialogo
             self.__personajes[e.get_attribute("id")] = personaje.copy()
         elif e.get_name() == "room":
             if e.get_attribute("enable") == "yes":
                 habilitada = True
             else:
                 habilitada = False
             hab = {}
             hab["habilitada"] = habilitada
             self.__habitaciones[e.get_attribute("id")] = hab.copy()
         elif e.get_name() == "key":
             if e.get_attribute("enable") == "yes":
                 habilitada = True
             else:
                 habilitada = False
             hab = {}
             hab["habilitada"] = habilitada
             self.__teclas[e.get_attribute("id")] = hab.copy()
         elif e.get_name() == "precondition":
             self.__precondiciones.append(e.get_attribute("name"))
         elif e.get_name() == "action":
             accion = {}
             accion["nombre"] = e.get_attribute("name")
             accion["consecuencia"] = e.get_attribute("consequences")
             accion["nuevo_estado"] = e.get_attribute("new_state")
             self.__acciones.append(accion.copy())
         elif e.get_name() == "event":
             event = {}
             event["nombre"] = e.get_attribute("name")
             event["tipo"] = e.get_attribute("type")
             event["consecuencia"] = e.get_attribute("consequences")
             event["nuevo_estado"] = e.get_attribute("new_state")
             self.__eventos.append(event.copy())
Exemplo n.º 10
0
class Sounds:
    def __init__(self, main_path):
        self.__main_path = main_path    
    
    def set_main_path(self, path):
        self.__main_path = path
    
    def get_sound_file_name(self, categoria="",tipo="",nombre=""):
        self.__f = open(os.path.abspath(self.__main_path + "/data/resources.xml"))
        self.__parser = Parser()
        attrs = {'type' : tipo, 'name' : nombre}
        elemento = self.__parser.find_element_attribute(categoria,attrs,self.__f)
        if elemento.is_empty():
            raise Exception("No se encontro el elemento en el archivo XML (Sounds Class)")
        self.__f.close()
        self.__parser.close()
        return os.path.abspath(self.__main_path+elemento.get_text('str'))
Exemplo n.º 11
0
 def __load_user_data(self):
     parser = Parser()
     elementos_usuario = parser.find_child_element("user_data",self.__user_data_file)
     character_relations = {}
     for e in elementos_usuario:
         if e.get_name() == "state":
             self.set_state(e.get_attribute('name'))
         elif e.get_name() == "skill_level":
             self.__nivel_de_habilidad = int(e.get_attribute('constant'))
         elif e.get_name() == "character_relation":
             character_relations[e.get_attribute('name')] = int(e.get_attribute('relation_constant'))
         elif e.get_name() == "medals":
             self.__init_medals(e.get_attributes())
         elif e.get_name() == "trophies":
             self.__init_trophies(e.get_attributes())
         elif e.get_name() == "challenges_medals":
             self.__init_challenge_medals(e.get_attributes())
     self.__init_character_relations(character_relations)
     self.__load_config_settings(nuevo_usuario=False)
     parser.close()
Exemplo n.º 12
0
 def __load_user_data(self):
     parser = Parser()
     elementos_usuario = parser.find_child_element("user_data",
                                                   self.__user_data_file)
     character_relations = {}
     for e in elementos_usuario:
         if e.get_name() == "state":
             self.set_state(e.get_attribute('name'))
         elif e.get_name() == "skill_level":
             self.__nivel_de_habilidad = int(e.get_attribute('constant'))
         elif e.get_name() == "character_relation":
             character_relations[e.get_attribute('name')] = int(
                 e.get_attribute('relation_constant'))
         elif e.get_name() == "medals":
             self.__init_medals(e.get_attributes())
         elif e.get_name() == "trophies":
             self.__init_trophies(e.get_attributes())
         elif e.get_name() == "challenges_medals":
             self.__init_challenge_medals(e.get_attributes())
     self.__init_character_relations(character_relations)
     self.__load_config_settings(nuevo_usuario=False)
     parser.close()
Exemplo n.º 13
0
 def __get_xml_info(self,archivo,etiqueta):
     f = open(archivo)
     p = Parser()
     return p.find_child_element(etiqueta,f)