def __parse_room(self, room_tag): """ Parses a (single) room xml tag. Args: room_tag: The room xml tag to parse Returns: A python Tuple containing: a pysud.rooms object a python list """ room_description = None room_name = room_tag.get('name') room_id = room_tag.get('id') room_transitions = None for element in room_tag.getchildren(): if element.tag == 'description': room_description = element.text elif element.tag == 'transitions': # self.print_transitions(element, room_id) room_transitions = self.__parse_transition(element, room_id) else: pass # invalid tag found room = pysud.Room(room_name, room_description, room_id) return tuple(room, room_transitions)
def build_rooms_dict(self): """ Parses a rooms json. Returns: A dictionary containing all found rooms, indexed by room id. """ rooms_dict = dict() for room_json in self.rooms_json_file: # rooms found in json must be converted to pysud Room objects: room = pysud.Room(room_json['name'], room_json['description'], room_json['id']) rooms_dict[room.get_id()] = room return rooms_dict
def gamescript(): print('pysud minidemo items ...') juego = pysud.Game("MiniDemoTester") r1 = pysud.Room( room_name = "Pequeña habitación", room_description = "Esta pequeña habitación de unos 4m cuadrados tiene una cama en un rincón, un escritorio junto a ella y una mesa cuadrada en el centro. También hay un armario empotrado y una cajonera junto a la puerta. \n Un cuadro en un muro lee: 'Los nuevos comandos son agarrar ITEM, usar ITEM, usar ITEM1 con ITEM2, combinar ITEM1 ITEM2, mirar ITEM (de tu inventario), i o inventario (para ver tus cosas), stats para ver donde has estado, puntos para ver tu puntaje, save, load'." ) # agregando items a la habitación: t = Termo("termo", "Es un termo Lumilagro, me recuerda a Victor Hugo...") m = Mate("mate", "Un mate de lata.") cel = Telefono() r1.add_item(t) r1.add_item(m) r1.add_item(cel) # agregando eventos locales a la habitación: r1.add_local_event(MirarCajonera(["mirar cajonera", "examinar cajonera"])) # agregando eventos globales: juego.add_global_event(CebarUnMate(t, m)) juego.set_user_defined_variable('visto_cajonera', False) # comenzando: juego.add_rooms([r1]) juego.pc.move_to_room(r1) gm = gameMgr.GameManager(juego) gm.run_game()
) game.iom.show_message("Así termina la historia de " + game.pc.get_name() + " con un puntaje de:") game.iom.show_score() game.quit_game() else: game.iom.show_message("Te está faltando algo... ¿pero qué será?") if __name__ == '__main__': # 1 - Inicializaciones: NOMBRE_USUARIO = input('Ingrese nombre de personaje:') JUEGO = pysud.Game(NOMBRE_USUARIO) # 2 - Habitaciones: R1 = pysud.Room( 'Calle', 'Estas en la puerta de tu viejo departamento. En la calle esta cayendo el sol y no ves personas por ningún lado, todo está en absoluto silencio... hacia el norte está la plaza del barrio...', "1") R2 = pysud.Room( 'Casa', 'Tu humilde departamento ha visto mejores épocas, eso es por supuesto antes de que vivieras en él, mucho antes. Es pequeño y has acumulado ropa sucia y basura por doquier. Tantas telarañas en las ventanas te impiden ver con claridad lo que sucede en la calle. Has dejado la puerta del baño abierta...', "2") R3 = pysud.Room( 'Baño', 'El baño lo tienes a tono con la decoración del resto de tu hogar: mugriento a más no poder. Bajo el lavamanos se encuentra un pequeño botiquín y detras tuyo está la habitación principal (y única) de tu departamento...', "3") R4 = pysud.Room( 'Plaza', 'La plaza está desierta; tiene un camino que la atraviesa por el centro de norte a sur y en medio de este ves a un hombre tirado, boca abajo. Hacia el sur está la calle que conduce a tu hogar, y en la otra dirección el único puesto de comida del parque.', "4") R5 = pysud.Room( 'Puesto de comida',
if lighter and bomb: game.pc.increase_score(1) game.iom.show_message("You light the bandages with the lighter and after opening the door you throw your homemade bomb at that strange creature, which escapes running awkwardly a short distance to fall to writhe in pain, you are not sure that it is actually dead, but at least you do not feel helpless .") game.iom.show_message("And so, the story of " + game.pc.get_name() + " ends. Her score was:") game.iom.show_score() game.quit_game() else: game.iom.show_message("You may be missed out something...") if __name__ == '__main__': # 1 - initializations: PLAYER_NAME = input ('Enter your character name:') GAME = pysud.Game(PLAYER_NAME) # 2 - rooms definitions: R1 = pysud.Room('Street', 'You stand by the doorstep of your old apartment. In the street the sun is falling and you don\'t see people anywhere, everything is absolutely silent... far to the north is the won square...', "1") R2 = pysud.Room('Home', 'Your humble apartment has seen better times, that is of course before you lived in it, much earlier. It is small and you have accumulated dirty clothes and garbage everywhere. So many cobwebs in the windows prevent you from seeing clearly what is happening on the street. You left the bathroom door opened, again...', "2") R3 = pysud.Room('Bathroom', 'The bathroom decoration is in tune with the rest of your home: gross. Under the sink there\'s a small medicine cabinet and behind you is the main and only bedroom of your apartment...', "3") R4 = pysud.Room('Park', 'The square is deserted. It has a path that crosses it through the center from north to south and in the middle of it you see a men lying down. To the south is the street that leads to your home, and in the other direction the only food stand in the park.', "4") R5 = pysud.Room('Foodstand', 'At the food stand the tables have been thrown to the floor as if serious disturbances had taken place, there are some blood stains on the floor, and especially near the door that leads where the food is prepared. It is ajar. You hear strange noises coming from inside...', "5") # 3 - rooms transicions -connect rooms-: R1.add_transition(['go home', 'enter home'], R2) R2.add_transition(['go outside', 'leave'], R1) R2.add_transition(['go to bathroom', 'enter bathroom'], R3) R3.add_transition(['go to living room', 'go back', 'back', 'go home'], R2) R1.add_transition(['go to park', 'north', 'n'], R4) R4.add_transition(['south', 'go to street', 's'], R1) R4.add_transition(['north', 'n', 'follow road', 'go to stand'], R5) R5.add_transition(['s', 'park', 'south'], R4) # 4 - local events and related variables: GAME.set_user_defined_variable('cabinet_opened', False)