def search(): if not session.get("logged_in"): return login() query_string = request.args.get("query").lower() items = Item.query() result_items = [] item_ids = set() for item in items: if query_string in item.name.lower(): if not item.key.id() in item_ids: result_items.append(item) item_ids.add(item.key.id()) item_tags = Item_Tag.query(Item_Tag.tag == query_string) for item_tag in item_tags: if not item_tag.item in item_ids: item = Item.get_by_id(item_tag.item) result_items.append( item) #can append it with value "only found in the tags" item_ids.add( item.key.id() ) #dont need to append it since all unique in this second query anyways return render_template("search_results.html", result_items=result_items, query=query_string)
def process_world_map(self, world_map: Dict[Tuple, List[WorldObject]], monsters: Monsters, doors: Doors, inventory: PlayerInventory) -> None: for coord, room in world_map.items(): room_doors = list( filter(lambda elem: isinstance(elem, Door), room) ) room_monsters = list( filter(lambda elem: isinstance(elem, Monster), room) ) for monster in room_monsters: monsters._monsters[monster.monster_name] = monster for door in room_doors: item_to_open = Item(door._door_name+'_opener') monster_w_item: Monster = random.choice(room_monsters) while monster_w_item in monsters.monster_action_mapping.keys(): monster_w_item = random.choice(room_monsters) open_door_action = OpenDoorAction(door._door_name, doors) spawn_item_action = SpawnItemInInventoryAction( item_to_open, inventory ) doors._doors_lookup[door._door_name] = door inventory.item_action_mapping[item_to_open._item_name] =\ open_door_action monsters.monster_action_mapping[monster_w_item.monster_name] =\ spawn_item_action
def addItemDB(self, data): logging.info("addItemDB") with DatabaseSession(self.engine) as session: instance = Item( name = data['name'], brand = data['brand'], category = data['category'], productCode = data['productcode'] ) changelog = Changelog( mode = "ADD", user = data['user'], item_category = True, item_data = json.dumps({"productcode" : data['productcode']}) ) session.add(changelog) session.flush() session.commit() logging.debug("Wrote activity log for addItem") try: session.add(instance) session.flush() session.commit() return True except exc.IntegrityError as e: logging.error('Integrity Error Exception when addITEM : \n %s',e ) session.rollback() return False return False
def task_execute(): w = World() for current in w.populators: if not w.denizens.has_key(current.instance): denizen = Denizen(current.denizen) current.instance = denizen.id w.denizens[denizen.id] = denizen libsigma.enter_room(denizen, current.target) for current in w.placements: if not current.instance in [i.id for i in current.target.contents]: item = Item(current.item) item.quantity = current.quantity current.instance = item.id w.items[item.id] = item current.target.contents.append(item)
def view_me(): user = User.get_by_id(session["user_id"]) if request.method == "POST": return render_template("tsktsk.html") review = Review(rating=int(request.form["rating"]), reason=request.form["reason"], user=user_id, reviewer=session["user_id"], flagged=False) review.put() update_user_rating(user_id, int(request.form["rating"])) sold_offers = [] sold_items = Item.query(Item.seller_id == session["user_id"], Item.sold == True) for item in sold_items: temp_offer = Offer.query(Offer.item == item.key.id()).get() sold_offers.append(temp_offer) purchased_offers = Offer.query(Offer.confirmed == True, Offer.bidder == session["user_id"]) notifications = Notification.query( Notification.user == session["user_id"]).order(-Notification.time) return render_template("me.html", user=user, sold_offers=sold_offers, purchased_offers=purchased_offers, notifications=notifications)
def pick_monster(game_map, room_id, room_x, room_y, monster_template): name, char, colour, hits, weapon = monster_template weapon_name, weapon_char, weapon_colour, weapon_power, weapon_uses = weapon weapon_stats = Weapon(weapon_power, weapon_uses) monster_weapon = Item(game_map, room_id, room_x, room_y, weapon_name, weapon_char, weapon_colour, weapon=weapon_stats) fighter_component = Fighter(hits, left_hand=monster_weapon) ai_component = BasicMonster() monster = Actor(game_map, room_id, room_x, room_y, name, char, colour, fighter=fighter_component, ai=ai_component) return monster
def item_photo(item_id): item_id = int(item_id) item = Item.get_by_id(item_id) if not item.photo: return "error", 500 return send_file(io.BytesIO(item.photo), attachment_filename='item_photo.png', mimetype=item.photo_mimetype)
def fake_item(environment="development"): """Create fake item.""" print green("Fake items") with rw_transaction() as session: user = User.get_mock_object() item = Item.get_mock_object() item.user_uuid = user.uuid print "Inserting user {}".format(user.to_primitive()) print "Inserting item {}".format(item.to_primitive()) model_user = ModelUser(**user.to_primitive()) model_item = ModelItem(**item.to_primitive()) session.add(model_user) session.add(model_item)
def delete_item(item_id): if not session.get("logged_in"): return login() item_id = int(item_id) item = Item.get_by_id(item_id) if item.seller_id != session["user_id"]: return "oops", 500 previous_notifications = Notification.query(Notification.item == item_id) notification_body = item.name + " removed" for prev_not in previous_notifications: notification = Notification(user=prev_not.user, body=notification_body, ntype="item-removed", item=item.key.id(), item_category=item.category, noticed=False, link="/browse/" + item.category) notification.put() prev_not.key.delete() offers = Offer.query(Offer.item == item.key.id()) conversation = Conversation.query(Conversation.item == item_id).get() if conversation: messages = Message.query(Message.conversation == conversation.key.id()) for message in messages: message.key.delete() conversation.key.delete() for offer in offers: offer.key.delete() item_tags = Item_Tag.query(Item_Tag.item == item.key.id()) for item_tag in item_tags: item_tag.key.delete() item.key.delete() return "success"
def history(): if not session.get("logged_in"): return login() sold_offers = [] sold_items = Item.query(Item.seller_id == session["user_id"], Item.sold == True) for item in sold_items: temp_offer = Offer.query(Offer.item == item.key.id()).get() sold_offers.append(temp_offer) purchased_offers = Offer.query(Offer.confirmed == True, Offer.bidder == session["user_id"]) return render_template("history.html", sold_offers=sold_offers, purchased_offers=purchased_offers)
def browse(category_id): if not session.get("logged_in"): return login() items = Item.query(Item.category == category_id, Item.sold == False) for item in items: item.item_id = item.key.id() notifications = Notification.query( Notification.user == session["user_id"]).order(-Notification.time) category = Category.get_by_id(category_id) return render_template("browse.html", items=items, category=category, category_id=category_id, notifications=notifications)
def __init__(self, data, sprites): # Localização inicial do jogador self.spawn = data["player"] # Tiles do mapa self.map = data["map"] self.width, self.height = len(data["map"][0]), len(data["map"]) self.tex = 64 # Cores self.color = tuple(data["colors"]["floor"]), data["colors"]["ceil"] self.dark = data["colors"]["dark"] # Música de fundo self.music = data["music"] # Inimigos e itens self.entities = [ Enemy(pos, sprites[enemy], enemy == "boss") for enemy, pos in data["enemies"] ] + [ Item(pos, sprites["items"].sprites[item], item) for item, pos in data["items"] ]
def my_items(): if not session.get("logged_in"): return login() items = Item.query(Item.seller_id == session.get("user_id"), Item.sold == False) for item in items: item.item_id = item.key.id() notifications = Notification.query( Notification.user == session["user_id"]).order(-Notification.time) offers = Offer.query(Offer.bidder == session['user_id'], Offer.confirmed == False) return render_template("my_items.html", items=items, notifications=notifications, offers=offers)
print(VERMELHO) cls() print('Conectando ao banco de dados...') engine = create_engine('sqlite:///data.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() if session != None: time.sleep(.3) print('Acesso ao banco de dados:' + AZUL + ' OK' + RESET) time.sleep(.3) print('Inicializando tabelas...') Item.create_table() Character.create_table() time.sleep(.3) print(AZUL + 'Iniciando programa...' + RESET) time.sleep(.5) ### MENU PRINCIPAL ### while True: cls() print('\33[34mGERADOR DE ENTIDADES - versao alpha 0.1\33[0m') print(' 1. Criar nova entidade') print(' 2. Visualizar entidades') print(' 3. Editar entidade') print(' 4. Deletar entidade') print(' 0. Sair')
def place_entities_test(self, entities, number_of_enemies, number_of_items, player=None): random.seed() if player == None: player = Humanoid(int(self.width / 2), int(self.height / 2), '@', libtcod.white, 'Player', blocks=True, combat_aspect=Combatant(200, 20, 20, 15), ai=Player(), speed=20, inventory=Inventory(20)) entities.append(player) for i in range(number_of_enemies): x = random.randint(1, self.width - 1) y = random.randint(1, self.height - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster = Humanoid(x, y, 'o', libtcod.desaturated_green, 'Orc', blocks=True, combat_aspect=Combatant(100, 10, 10, 5), ai=BasicMonster()) entities.append(monster) for i in range(number_of_items): x = random.randint(1, self.width - 1) y = random.randint(1, self.height - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): if random.randint(1, 100) < 0: item = Item(x, y, '!', libtcod.violet, 'Healing Potion', item_aspect=Item_aspect(use_function=heal, amount=10)) elif random.randint(1, 100) < 70: item = Item( x, y, '=', libtcod.red, 'Fireball Scroll', item_aspect=Item_aspect( use_function=cast_fireball, targeting=True, targeting_message= 'Left-click a target tile for the fireball, or right-click to cancel.', damage=50, radius=3)) else: pass try: entities.append(item) except: pass else: i -= 1
def post_item(): if not session.get("logged_in"): return login() if request.method == "GET": fields = [] fields.append( Field(name="name", title="Name", the_type='text', identifier='name', placeholder="Item Name")) fields.append( Field(name='description', title="Description", the_type="textarea", identifier='description', placeholder='Descriptive Description', tag="textarea")) categories = Category.query() options = [] for category in categories: option = {} option["name"] = category.name option["value"] = category.categoryID options.append(option) fields.append( Field(name='category', title="Item Category", the_type="select", identifier="category", placeholder="Select Item Category", tag="select", options=options)) fields.append( Field(name='price', title="Price", the_type="number", identifier="price", placeholder="10.95", step=True)) fields.append( Field(name='file', title="Upload Photo", the_type="file", placeholder="Upload Photo", identifier="file", tag="file")) fields.append( Field(name='biddable', title="Allow offer amounts other than suggested price.", the_type="number", identifier="biddable", tag="checkbox")) title = "Post Item" form = Form(fields=fields, title=title, submit="Post") notifications = Notification.query( Notification.user == session["user_id"]).order(-Notification.time) return render_template("post_item.html", item_form=form, notifications=notifications) if request.method == "POST": name = request.form.get("name") description = request.form.get("description") category = request.form.get("category") price = float(request.form.get("price")) seller_id = session["user_id"] biddable = False if request.form.get("biddable"): biddable = True # print "nooo" # return json.dumps(request.files) file = request.files.get("file", None) # print "whaattt??" file_data = None content_type = None photo = None if file: file_data = file.read() photo = images.resize(file_data, width=500, height=500) content_type = file.content_type new_item = Item(name=name, description=description, category=category, price=price, seller_id=seller_id, seller_name=session["first_name"] + " " + session["last_name"], biddable=biddable, sold=False, best_offer=0.0, photo=photo, photo_mimetype=content_type) new_item.put() return my_items()
def offers(offer_id): if not session.get("logged_in"): return login() if request.method == "GET": return "oops", 404 offer_id = int(offer_id) offer = Offer.get_by_id(offer_id) if not offer: return page_was_not_found("Offer has been removed") item = Item.get_by_id(offer.item) if request.form["reason"] == "accept": if item.seller_id != session["user_id"]: return "uninformative error", 404 offer.accepted = True offer.put() previous_notification = Notification.query( Notification.user == offer.bidder, Notification.item == item.key.id(), Notification.ntype == "accepted-offer").get() if previous_notification: previous_notification.key.delete() notification_body = session["first_name"] + " " + session[ "last_name"] + " has accepted your offer for their " + item.name + " posting." notification = Notification(user=offer.bidder, body=notification_body, ntype="accepted-offer", item=item.key.id(), item_category=item.category, noticed=False, link="/browse_item/" + str(item.key.id())) notification.put() conversation = Conversation(user1=session["user_id"], user2=offer.bidder, subject="Arranging Sale", item=item.key.id(), item_name=item.name, read1=True, read2=True) conversation.put() return "success" if request.form["reason"] == "reject": if item.seller_id != session["user_id"]: return "uninformative error", 404 offer.accepted = True offer.put() previous_notification = Notification.query( Notification.user == offer.bidder, Notification.item == item.key.id(), Notification.ntype == "accepted-offer").get() if previous_notification: previous_notification.key.delete() notification_body = "Offer Rejected:" + item.name notification = Notification(user=offer.bidder, body=notification_body, ntype="rejected-offer", item=item.key.id(), item_category=item.category, noticed=False, link="/browse_item/" + str(item.key.id())) notification.put() return "success" if request.form["reason"] == "confirm": if item.seller_id != session["user_id"]: return "uninformative error", 404 item.sold = True item.put() offer.confirmed = True offer.put() offers = Offer.query(Offer.item == item.key.id(), Offer.bidder != offer.bidder) for temp_offer in offers: notification_body = item.name + " sold" notification = Notification(user=offer.bidder, body=notification_body, ntype="item-sold", item=item.key.id(), item_category=item.category, noticed=False, link="/browse/" + str(item.category)) notification.put() temp_offer.key.delete() conversation = Conversation.query( Conversation.item == item.key.id()).get() if conversation: conversation.key.delete() return "Offer confirmed" if request.form["reason"] == "remove": offer.key.delete() return "Offer removed" return "uninformative error", 404
def browse_item(item_id): item_id = int(item_id) if not session.get("logged_in"): return login() if request.method == "GET": item = Item.get_by_id(item_id) category_id = item.category print item.name seller = User.get_by_id(item.seller_id) previous_offer = Offer.query(Offer.bidder == session["user_id"], Offer.item == item_id).get() was_previous_offer = False if previous_offer: was_previous_offer = True fields = [] fields.append( Field( name="message", title="Message For Seller", the_type='text', identifier='message', placeholder= "A short message for the seller. Perhaps, where you can meet or payment options.", tag="textarea")) if item.biddable: fields.append( Field(name='amount', title="Offer Amount", the_type="number", identifier="amount", placeholder="10.95", step=True)) title = "Make Offer" form = Form(fields=fields, title=title) tags = Item_Tag.query(Item_Tag.item == item_id) notifications = Notification.query( Notification.user == session["user_id"]).order(-Notification.time) return render_template("browse_item.html", item=item, category_id=category_id, bid_form=form, previous_offer=previous_offer, was_previous_offer=was_previous_offer, offer=previous_offer, notifications=notifications, tags=tags) if request.method == "POST": item = Item.get_by_id(item_id) if not item or item.sold: return page_was_not_found( "Sorry but the item you tried to bid on has been removed by the seller" ) category_id = item.category seller = User.get_by_id(item.seller_id) previous_offer = Offer.query(Offer.bidder == session["user_id"], Offer.item == item_id).get() if previous_offer: previous_offer.key.delete() amount = item.price if item.biddable: amount = float(request.form["amount"]) offer = Offer(bidder=session["user_id"], item=item_id, message=request.form["message"], amount=amount, bidder_name=session["first_name"] + " " + session["last_name"], accepted=False, confirmed=False, item_name=item.name) offer.put() if item.biddable: item.update_best_offer(amount) notification_body = "Offer made on " + item.name + "for $" + str( offer.amount) notification = Notification(user=item.seller_id, body=notification_body, ntype="item-offer", item=item.key.id(), item_category=item.category, noticed=False, link="/my_items/" + str(item.key.id())) notification.put() fields = [] fields.append( Field( name="message", title="Message For Seller", the_type='text', identifier='message', placeholder= "A short message for the seller. Perhaps, where you can meet or payment options.", tag="textarea")) if item.biddable: fields.append( Field(name='amount', title="Offer Amount", the_type="number", identifier="amount", placeholder="10.95", step=True)) title = "Make Offer" form = Form(fields=fields, title=title, submit="Make Offer") tags = Item_Tag.query(Item_Tag.item == item_id) notifications = Notification.query( Notification.user == session["user_id"]).order(-Notification.time) return render_template("browse_item.html", item=item, category_id=category_id, bid_form=form, offer=offer, was_previous_offer=True, notifications=notifications, tags=tags)
def my_item(item_id): if not session.get("logged_in"): return login() item_id = int(item_id) item = Item.get_by_id(item_id) if request.method == "POST": if item.seller_id != session["user_id"]: return "Uninformative Error", 500 if request.form.get("tags"): tags = request.form["tags"].split(" ") for tag in tags: if tag == "": continue tag = tag.strip().lower() exists = Tag.get_by_id(tag) if not exists: new_tag = Tag(id=tag, name=tag) new_tag.put() exists = Item_Tag.get_by_id(str(item_id) + tag) if not exists: new_item_tag = Item_Tag(id=str(item_id) + tag, item=item_id, tag=tag) new_item_tag.put() else: item.name = request.form.get("name") item.description = request.form.get("description") item.category = request.form.get("category") item.price = float(request.form.get("price")) item.biddable = False if request.form.get("biddable"): item.biddable = True item.put() offers = Offer.query(Offer.item == item_id).order(Offer.amount) fields = [] fields.append( Field(name="name", title="Name", the_type='text', identifier='name', placeholder="Item Name", value=item.name)) fields.append( Field(name='description', title="Description", the_type="textarea", identifier='description', placeholder='Descriptive Description', tag="textarea", value=item.description)) categories = Category.query() options = [] for category in categories: option = {} option["name"] = category.name option["value"] = category.categoryID options.append(option) fields.append( Field(name='category', title="Item Category", the_type="select", identifier="category", placeholder="Select Item Category", tag="select", options=options, value=item.category)) fields.append( Field(name='price', title="Price", the_type="number", identifier="price", placeholder="10.95", step=True, value=item.price)) fields.append( Field(name='biddable', title="Allow offer amounts other than suggested price.", the_type="number", identifier="biddable", tag="checkbox", value="checked" if item.biddable else "")) fields.append( Field(name='item_id', the_type="hidden", identifier="item_id", value=item.key.id(), hidden="hidden")) title = "Edit Item" form = Form(fields=fields, title=title) fields1 = [] fields1.append( Field(name="tags", title="Tags", the_type='text', identifier='name', placeholder="Enter descriptive words seperated by spaces.")) title1 = "" submit = "Add Tag" form1 = Form(fields=fields1, title=title1, submit=submit) tags = Item_Tag.query(Item_Tag.item == item_id) notifications = Notification.query( Notification.user == session["user_id"]).order(-Notification.time) return render_template("view_my_item.html", offers=offers, item=item, notifications=notifications, item_form=form, tag_form=form1, tags=tags)
def populate(db): items = [ Item(name="Thunderfury, Blessed Blade of the Windseeker", quality=ItemQuality.LEGENDARY, icon="inv_sword_39", wowhead_id=19019), Item(name="Orb of Deception", quality=ItemQuality.RARE, icon="inv_misc_orb_02", wowhead_id=1973), Item(name="The Unstoppable Force", quality=ItemQuality.EPIC, icon="inv_hammer_13", wowhead_id=19323), Item(name="Noggenfogger Elixir", quality=ItemQuality.COMMON, icon="inv_potion_83", wowhead_id=8529), Item(name="Righteous Orb", quality=ItemQuality.UNCOMMON, icon="inv_misc_gem_pearl_03", wowhead_id=12811), Item(name="Nat Pagle's Guide to Extreme Anglin'", quality=ItemQuality.JUNK, icon="inv_misc_book_02", wowhead_id=18229), Item(name="Savory Deviate Delight", quality=ItemQuality.COMMON, icon="inv_misc_monsterhead_04", wowhead_id=6657), Item(name="Carrot on a Stick", quality=ItemQuality.UNCOMMON, icon="inv_misc_food_54", wowhead_id=11122), Item(name="Skullflame Shield", quality=ItemQuality.EPIC, icon="inv_shield_01", wowhead_id=1168), Item(name="Sulfuras, Hand of Ragnaros", quality=ItemQuality.LEGENDARY, icon="inv_hammer_unique_sulfuras", wowhead_id=17182), Item(name="Rusty Warhammer", quality=ItemQuality.JUNK, icon="inv_hammer_16", wowhead_id=1514) ] for i in items: if Item.query.filter_by(name=i.name).first() is None: db.session.add(i) db.session.commit()
def main(): tdl.set_font('terminal16x16.png', greyscale=True, altLayout=False) # Load the font from a png. tdl.set_fps(100) map_width = 20 map_height = 20 room_width = 30 room_height = 30 screen_width = room_width + 22 screen_height = room_height + 22 root_console = tdl.init(screen_width, screen_height, title='7DRL 2019') top_panel_console = tdl.Console(screen_width, 10) view_port_console = tdl.Console(room_width, room_height) bottom_panel_console = tdl.Console(screen_width, 10) message_log = MessageLog(0, 0, screen_width, 9) entities = [] game_map = GameMap(map_width, map_height) sword_stats = Weapon(2, 10) player_weapon = Item(game_map, "0x0", 0, 0, "Sword", "|", (255, 255, 255), weapon=sword_stats) player_stats = Fighter(hits=10, left_hand=player_weapon) player = Actor(game_map, "2x2", 15, 10, "Player", "@", (255, 255, 255), fighter=player_stats) entities.append(player) generate_map(game_map, entities, player) all_consoles = [ root_console, view_port_console, bottom_panel_console, top_panel_console ] fov_algorithm = "BASIC" fov_light_walls = True fov_radius = 50 fov_recompute = True game_state = GameStates.PLAYER_TURN while not tdl.event.is_window_closed(): if fov_recompute: # Compute the field of view to show changes. game_map.rooms[player.map_x][player.map_y]\ .compute_fov(player.room_x, player.room_y, fov=fov_algorithm, radius=fov_radius, light_walls=fov_light_walls, sphere=True) render_all(all_consoles, game_map, entities, player, fov_recompute, message_log) tdl.flush() clear_all(view_port_console, entities) fov_recompute = False for event in tdl.event.get(): if event.type == 'KEYUP': user_input = event break else: user_input = None if not user_input: continue action = handle_keys(user_input) move = action.get('move') exit_game = action.get('exit_game') select_hand = action.get('select_hand') drop_item = action.get('drop_item') pickup_item = action.get('pickup_item') shuffle_rooms = action.get('shuffle_rooms') player_turn_results = [] if shuffle_rooms: message = game_map.shuffle_rooms(player, entities) message_log.add_message(message) fov_recompute = True # TODO at the moment these functions are doing all the leg work and player_turn_results isn't used. Rectify. if select_hand and game_state == GameStates.PLAYER_TURN: player.fighter.selected_hand = select_hand fov_recompute = True if drop_item and game_state == GameStates.PLAYER_TURN: message = player.fighter.drop_item(game_map, entities) message_log.add_message(message) game_state = GameStates.ENEMY_TURN fov_recompute = True if pickup_item and game_state == GameStates.PLAYER_TURN: message = player.fighter.pickup_item(entities) message_log.add_message(message) game_state = GameStates.ENEMY_TURN fov_recompute = True if move and game_state == GameStates.PLAYER_TURN: dx, dy = move destination_room_x = player.room_x + dx destination_room_y = player.room_y + dy if destination_room_x < 0: dx = 0 if player.map_x - 1 < 0: player.map_x = map_width - 1 else: player.map_x -= 1 player.room_x = room_width - 1 if destination_room_x == room_width: destination_room_x -= 1 dx = 0 if player.map_x + 1 > map_width - 1: player.map_x = 0 else: player.map_x += 1 player.room_x = 0 if destination_room_y < 0: dy = 0 if player.map_y - 1 < 0: player.map_y = map_height - 1 else: player.map_y -= 1 player.room_y = room_height - 1 if destination_room_y == room_height: destination_room_y -= 1 dy = 0 if player.map_y + 1 > map_height - 1: player.map_y = 0 else: player.map_y += 1 player.room_y = 0 if game_map.rooms[player.map_x][player.map_y].walkable[ destination_room_x, destination_room_y]: target = get_blocking_entities_at_location( entities, player.map_x, player.map_y, destination_room_x, destination_room_y) if target: # Combat here attack_results = player.fighter.attack(target) player_turn_results.extend( attack_results ) # Add the result of the last turn to the list fov_recompute = True else: player.move(dx, dy) # Or just move player.set_current_room(game_map) # TODO: Bug with the new room layouts - some cause change of room to break. print("MapPos: ", player.map_x, ",", player.map_y, end=" / ") print("RoomPos: ", player.room_x, ",", player.room_y) fov_recompute = True game_state = GameStates.ENEMY_TURN # Switch over the enemy's turn. if exit_game: return True for player_turn_result in player_turn_results: message = player_turn_result.get("message") # Pull any messages dead_entity = player_turn_result.get( "dead") # Or anything that died if message: message_log.add_message( message ) # Add the message (if any) to the message log to print on screen. if dead_entity: # If anything died... if dead_entity == player: message, game_state = kill_player(dead_entity) # Game over else: message = kill_monster( dead_entity ) # Print a death message for monster, add exp message_log.add_message(message) # Print messages to screen. player_turn_results.clear() # Clear ready for next turn. if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.map_x == player.map_x and entity.map_y == player.map_y: if entity.ai: # If the entity has some intelligence (monsters, npc) enemy_turn_results = entity.ai.take_turn( player, game_map, entities) for enemy_turn_result in enemy_turn_results: # Same deal as the player turns message = enemy_turn_result.get("message") dead_entity = enemy_turn_result.get("dead") if message: message_log.add_message(message) if dead_entity: if dead_entity == player: message, game_state = kill_player( dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break enemy_turn_results.clear() if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYER_TURN