Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Python Programming › Solution for the "Text Based Game" project (IT140/COP100+)

Solution for the "Text Based Game" project (IT140/COP100+)

Posts 1–2 of 2 · Page 1 of 1
Vox
Vox
Solution for the "Text Based Game" project (IT140/COP100+)
Make sure to use this wisely. If you submit the code as-is, you won't get a passing grade. Instead, maybe remove the comments, make the code a little bit sloppier, and change the names of the rooms and items to the names of your room and items.


Pastebin (for syntax highlighting)



Code:
# Replace the room names with your own rooms
# and the items with your own items
rooms = {
 'Great Hall' : { 'South' : 'Bedroom', 'North': 'Dungeon', 'East' : 'Kitchen', 'West' : 'Library' },
 'Bedroom' : { 'North' : 'Great Hall', 'East' : 'Cellar', 'item' : 'Armor' },
 'Cellar' : { 'West' : 'Bedroom', 'item' : 'Helmet' },
 'Kitchen':{'North': 'Dining Room', 'West': 'Great Hall'},
 'Dining Room' : { 'South' : 'Kitchen', 'item' : 'Dragon' } #villain
}

boss = "Dragon"

current_room = "Great Hall"
inventory = list()

def all_items():
    items = []
    for room in rooms.values():
        if "item" in list(room.keys()):
            items.append(room["item"])
    return items
    

def directions():
    pass

def list_actions():
    for k, v in get_room().items():
        if v in inventory:
            continue
        elif k == "item":
            print("You can `get`", v)
            continue
        else:
            print("You can ` move", k, "` to go to the", v)
            
def get_room():
    return rooms[current_room]

def _win():
    print("Congratulations! You managed to defeat the boss and win!")
    quit()

def _not_win():
    print("Sorry, you are still not strong enough to fight the boss.\nTry collecting more items first.")
    return


def _handle_boss():
    items = all_items()
    items.remove(boss)
    if inventory == items:
        _win()
        return
    _not_win()
    
    

def _move(to,  *args, **kwargs):
    global current_room
    current_room = get_room()[to]

def _get_item(*args, **kwargs):
    name = get_room()["item"]
    if name in inventory:
        _error()
        return
    # special case handling for when the player
    # tries to get the boss
    if name == boss:
        _handle_boss()
        return
    
    inventory.append(name)

def _error():
    print("\n***Sorry, that is an invalid command or the argument doesn't exist.***\n")
    


def parse_cmd(cmd, *args, **kwargs):
    # Smelly Code:
    # Hardcoded inside of a function
    # non-modular
    cmds = {
        "move": _move,
        "get": _get_item
    }
    
    
    # test to see if the command is valid
    print(cmd, "in", list(cmds.keys()), "is", cmd in list(cmds.keys()))
    if not (cmd in list(cmds.keys())):
        _error()
        return
    
    # test to see if the arguments are valid for room
    if cmd == "move":
        if not (args[0] in list(get_room().keys())):
            _error()
            return
    
    cmds[cmd](*args, **kwargs)



def main():
    
    # Tell the player the directions on how to play
    directions()
    
    # main game loop
    while 1:
        # show the player what they can do
        list_actions()
        
        # get input from the player
        print("You are in the", current_room)
        parse_cmd(*input("What would you like to do?").split())
        
        
if __name__ == "__main__":
    main()
#1 · 5y ago
AR
Archangel_77
A bit improved.
Quote Originally Posted by Vox View Post
Make sure to use this wisely. If you submit the code as-is, you won't get a passing grade. Instead, maybe remove the comments, make the code a little bit sloppier, and change the names of the rooms and items to the names of your room and items.


Pastebin (for syntax highlighting)



Code:
# Replace the room names with your own rooms
# and the items with your own items
rooms = {
 'Great Hall' : { 'South' : 'Bedroom', 'North': 'Dungeon', 'East' : 'Kitchen', 'West' : 'Library' },
 'Bedroom' : { 'North' : 'Great Hall', 'East' : 'Cellar', 'item' : 'Armor' },
 'Cellar' : { 'West' : 'Bedroom', 'item' : 'Helmet' },
 'Kitchen':{'North': 'Dining Room', 'West': 'Great Hall'},
 'Dining Room' : { 'South' : 'Kitchen', 'item' : 'Dragon' } #villain
}

boss = "Dragon"

current_room = "Great Hall"
inventory = list()

def all_items():
    items = []
    for room in rooms.values():
        if "item" in list(room.keys()):
            items.append(room["item"])
    return items
    

def directions():
    pass

def list_actions():
    for k, v in get_room().items():
        if v in inventory:
            continue
        elif k == "item":
            print("You can `get`", v)
            continue
        else:
            print("You can ` move", k, "` to go to the", v)
            
def get_room():
    return rooms[current_room]

def _win():
    print("Congratulations! You managed to defeat the boss and win!")
    quit()

def _not_win():
    print("Sorry, you are still not strong enough to fight the boss.\nTry collecting more items first.")
    return


def _handle_boss():
    items = all_items()
    items.remove(boss)
    if inventory == items:
        _win()
        return
    _not_win()
    
    

def _move(to,  *args, **kwargs):
    global current_room
    current_room = get_room()[to]

def _get_item(*args, **kwargs):
    name = get_room()["item"]
    if name in inventory:
        _error()
        return
    # special case handling for when the player
    # tries to get the boss
    if name == boss:
        _handle_boss()
        return
    
    inventory.append(name)

def _error():
    print("\n***Sorry, that is an invalid command or the argument doesn't exist.***\n")
    


def parse_cmd(cmd, *args, **kwargs):
    # Smelly Code:
    # Hardcoded inside of a function
    # non-modular
    cmds = {
        "move": _move,
        "get": _get_item
    }
    
    
    # test to see if the command is valid
    print(cmd, "in", list(cmds.keys()), "is", cmd in list(cmds.keys()))
    if not (cmd in list(cmds.keys())):
        _error()
        return
    
    # test to see if the arguments are valid for room
    if cmd == "move":
        if not (args[0] in list(get_room().keys())):
            _error()
            return
    
    cmds[cmd](*args, **kwargs)



def main():
    
    # Tell the player the directions on how to play
    directions()
    
    # main game loop
    while 1:
        # show the player what they can do
        list_actions()
        
        # get input from the player
        print("You are in the", current_room)
        parse_cmd(*input("What would you like to do?").split())
        
        
if __name__ == "__main__":
    main()
rooms = {
"Great Hall": {"South": "Bedroom", "North": "Dungeon", "East": "Kitchen", "West": "Library"},
"Bedroom": {"North": "Great Hall", "East": "Cellar", "item": "Armor"},
"Cellar": {"West": "Bedroom", "item": "Helmet"},
"Kitchen": {"North": "Dining Room", "West": "Great Hall"},
"Dining Room": {"South": "Kitchen", "item": "Dragon"}
}

boss = "Dragon"
current_room = "Great Hall"
inventory = []


def directions():
print("""
Move commands: move North, move South, move East, move West
Add items to inventory: get <item>

Collect all items before fighting the Dragon!
""")


def get_room():
return rooms[current_room]


def list_actions():
room = get_room()

for direction, place in room.items():
if direction != "item":
print(f"You can move {direction} to {place}")

if "item" in room:
item = room["item"]
if item != boss:
print(f"You can get {item}")


def move(direction):
global current_room
room = get_room()

if direction not in room:
print("You can't go that way.")
return

current_room = room[direction]
print("You moved to", current_room)

check_boss()


def get_item():
room = get_room()

if "item" not in room:
print("There is nothing here.")
return

item = room["item"]

if item == boss:
print("You cannot pick up the Dragon!")
return

inventory.append(item)
del room["item"]

print("You picked up:", item)
print("Inventory:", inventory)


def check_boss():
room = get_room()

if room.get("item") == boss:
if len(inventory) == count_items():
print("You defeated the Dragon! You win!")
quit()
else:
print("The Dragon defeated you. You needed more items.")
quit()


def count_items():
count = 0
for r in rooms.values():
if "item" in r and r["item"] != boss:
count += 1
return count


def parse_cmd(command):
parts = command.split()

if len(parts) == 0:
return

cmd = parts[0]

if cmd == "move" and len(parts) > 1:
move(parts[1])
elif cmd == "get":
get_item()
else:
print("Invalid command.")


def main():
directions()

while True:
print("\nYou are in", current_room)
list_actions()

command = input("What would you like to do? ")
parse_cmd(command)


if __name__ == "__main__":
main()
#2 · 3mo ago
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

  • Looking for exploits on a text based gameBy ZECC in Hack Requests
    1Last post 3mo ago
  • ◠◡◠ Professional/Talented Java Coders for my Advanced Text Based Adventure Game ◠◡◠By Southflyer123 in User Services
    1Last post 12y ago
  • Text-based-gamesBy tigerjr38 in Hack Requests
    0Last post 18y ago
  • Text - Based - GameBy ktalin91 in WarRock - International Hacks
    7Last post 19y ago
  • Text Based Game Hack..By Tayyab in Hack Requests
    0Last post 18y ago

Tags for this Thread

#answer sheet#code#project#project code#python#solution#source code