Building a GPT-Powered Text Adventure in Python
AI and Horror go hand in hand for half the population, so I decided to put them together for my college project. It led me to build an eerie, yet simple, sound-layered, AI-driven text adventure in Python where a gothic narrator (powered by GPT-3.5) guides you through a haunted Witch's Hut. This was my first real project integrating OpenAI, sound design with pygame, and game logic with branching paths and inventory-based endings. Here's how I built it, and why I think projects like this are one of the best ways to learn AI dev skills. In a Nutshell Premise: You enter a mysterious, seemingly abandoned Witch's Hut. Your only hope of survival is to collect six cursed items hidden throughout her home before descending into the cellar for a final encounter. The twist? Every room is described dynamically with GPT-3.5, and the ending is written by the AI based on the items you collected. Core Features: AI-generated room descriptions using GPT Gothic AI-crafted ending narration Real-time sound effects using pygame Looping ambient dungeon audio Inventory system and item-gated boss ASCII map with movement options How I Built It GPT-Powered Room Descriptions I used OpenAI's chat.completions API to act as a spooky narrator. Each time you enter a room, GPT generates a unique description based on: The room name Items in the room What's in your inventory To reduce token usage and lag, I cache the descriptions the first time you enter a room. Gothic AI-Generated Endings Once you defeat the Witch (only if you have all six items), GPT crafts a short, eerie epilogue that reflects your journey and the tools you used. Sound Design with Pygame I layered ambient audio with real-time SFX: Looping ambience: Dungeon rumble starts the moment you enter the game. Footsteps: A separate .wav plays every time the player moves, without stopping the ambient loop. Text-Based Movement & Inventory The player types commands like move, get item, and map. Rooms are connected in a simple north-south-east-west layout, and item pickups are required to win. Each room can only be looted once-and you must gather all six before entering the cellar for the final boss. ASCII Map I created a simple visual representation of the Witch's Hut that highlights your current location. This helps players stay oriented without a GUI. What I Learned How to call and format GPT responses via OpenAI's API Managing .env files and secrets with GitHub .gitignore How to cache dynamic AI content for performance That AI + audio = powerful atmosphere, even in a terminal game What's Next Adding GPT-generated events (like mini puzzles or taunts) Turning the game into a web version with Flask or Streamlit Letting GPT generate new rooms for harder difficulty Try It or Fork It Here's the full game repo on GitHub: https://github.com/DynaKong/txt-based-game.git Feel free to clone, remix, or build on it-and let me know if you do! I'd love to see what weirdness others bring to the table. Final Thoughts This game taught me how AI can do more than answer questions; it can create vibes. It can build mood and story, one room at a time. I learned more in this one project than in any tutorial. If you're a student or beginner, start weird. Start creatively, start small, but start.

AI and Horror go hand in hand for half the population, so I decided to put them together for my college project. It led me to build an eerie, yet simple, sound-layered, AI-driven text adventure in Python where a gothic narrator (powered by GPT-3.5) guides you through a haunted Witch's Hut. This was my first real project integrating OpenAI, sound design with pygame, and game logic with branching paths and inventory-based endings. Here's how I built it, and why I think projects like this are one of the best ways to learn AI dev skills.
In a Nutshell
Premise:
You enter a mysterious, seemingly abandoned Witch's Hut. Your only hope of survival is to collect six cursed items hidden throughout her home before descending into the cellar for a final encounter. The twist? Every room is described dynamically with GPT-3.5, and the ending is written by the AI based on the items you collected.
Core Features:
AI-generated room descriptions using GPT
Gothic AI-crafted ending narration
Real-time sound effects using pygame
Looping ambient dungeon audio
Inventory system and item-gated boss
ASCII map with movement options
How I Built It
GPT-Powered Room Descriptions
I used OpenAI's chat.completions API to act as a spooky narrator. Each time you enter a room, GPT generates a unique description based on:
The room name
Items in the room
What's in your inventory
To reduce token usage and lag, I cache the descriptions the first time you enter a room.
Gothic AI-Generated Endings
Once you defeat the Witch (only if you have all six items), GPT crafts a short, eerie epilogue that reflects your journey and the tools you used.
Sound Design with Pygame
I layered ambient audio with real-time SFX:
Looping ambience: Dungeon rumble starts the moment you enter the game.
Footsteps: A separate .wav plays every time the player moves, without stopping the ambient loop.
Text-Based Movement & Inventory
The player types commands like move, get item, and map. Rooms are connected in a simple north-south-east-west layout, and item pickups are required to win. Each room can only be looted once-and you must gather all six before entering the cellar for the final boss.
ASCII Map
I created a simple visual representation of the Witch's Hut that highlights your current location. This helps players stay oriented without a GUI.
What I Learned
How to call and format GPT responses via OpenAI's API
Managing .env files and secrets with GitHub .gitignore
How to cache dynamic AI content for performance
That AI + audio = powerful atmosphere, even in a terminal game
What's Next
Adding GPT-generated events (like mini puzzles or taunts)
Turning the game into a web version with Flask or Streamlit
Letting GPT generate new rooms for harder difficulty
Try It or Fork It
Here's the full game repo on GitHub: https://github.com/DynaKong/txt-based-game.git
Feel free to clone, remix, or build on it-and let me know if you do! I'd love to see what weirdness others bring to the table.
Final Thoughts
This game taught me how AI can do more than answer questions; it can create vibes. It can build mood and story, one room at a time. I learned more in this one project than in any tutorial. If you're a student or beginner, start weird. Start creatively, start small, but start.