dungeon.py

Created by naul

Created on May 02, 2023

1.72 KB


from player import Player
from npc import NPC
from shop import shop
import random

def generate_dungeon(floors):
    dungeon = []
    for floor in range(floors):
        dungeon.append([])
        for room in range(10):
            enemies = random.randint(0, 3)
            treasure = random.randint(0, 1)
            room = {
                "enemies": enemies,
                "treasure": treasure
            }
            dungeon[floor].append(room)
    return dungeon

def play_game():
    player = Player()
    dungeon = generate_dungeon(10)
    current_floor = 0
    
    while True:
        # display game interface
        # code to move player around dungeon using arrow keys
        current_room = dungeon[current_floor][player_position]
        if current_room["enemies"] > 0:
            enemies_defeated = battle_enemies(current_room["enemies"], player)
            if enemies_defeated:
                print("You defeated the enemies!")
            else:
                print("You were defeated.")
                break
        elif current_room["treasure"] > 0:
            treasure_added = add_treasure(current_room["treasure"], player)
            if treasure_added:
                print("You found treasure!")
            else:
                print("Your inventory is full.")
        else:
            print("This room is empty.")
        
        choice = input("What would you like to do? (talk/shop/stats/quit) ")
        
        if choice == "talk":
            npc = NPC("Bob")
            npc.join_party(player)
        elif choice == "shop":
            shop()
        elif choice == "quit":
            break
        else:
            print("Invalid choice.")            
if __name__ == "__main__":
    play_game()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.