<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dominic Klatik</title>
    <description>The latest articles on DEV Community by Dominic Klatik (@dynakong).</description>
    <link>https://dev.to/dynakong</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3038002%2F97a3049f-09b8-4748-9f54-b30901f75e46.jpeg</url>
      <title>DEV Community: Dominic Klatik</title>
      <link>https://dev.to/dynakong</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dynakong"/>
    <language>en</language>
    <item>
      <title>Building a GPT-Powered Text Adventure in Python</title>
      <dc:creator>Dominic Klatik</dc:creator>
      <pubDate>Thu, 10 Apr 2025 12:53:44 +0000</pubDate>
      <link>https://dev.to/dynakong/building-a-gpt-powered-text-adventure-in-python-ngb</link>
      <guid>https://dev.to/dynakong/building-a-gpt-powered-text-adventure-in-python-ngb</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In a Nutshell&lt;/strong&gt;&lt;br&gt;
Premise:&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;Core Features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;AI-generated room descriptions using GPT&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gothic AI-crafted ending narration&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-time sound effects using pygame&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Looping ambient dungeon audio&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inventory system and item-gated boss&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ASCII map with movement options&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How I Built It&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;GPT-Powered Room Descriptions&lt;/em&gt;&lt;br&gt;
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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The room name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Items in the room&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What's in your inventory&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To reduce token usage and lag, I cache the descriptions the first time you enter a room.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Gothic AI-Generated Endings&lt;/em&gt;&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Sound Design with Pygame&lt;/em&gt;&lt;br&gt;
I layered ambient audio with real-time SFX:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Looping ambience: Dungeon rumble starts the moment you enter the game.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Footsteps: A separate .wav plays every time the player moves, without stopping the ambient loop.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Text-Based Movement &amp;amp; Inventory&lt;/em&gt;&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;ASCII Map&lt;/em&gt;&lt;br&gt;
I created a simple visual representation of the Witch's Hut that highlights your current location. This helps players stay oriented without a GUI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How to call and format GPT responses via OpenAI's API&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Managing .env files and secrets with GitHub .gitignore&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to cache dynamic AI content for performance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;That AI + audio = powerful atmosphere, even in a terminal game&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What's Next&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Adding GPT-generated events (like mini puzzles or taunts)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Turning the game into a web version with Flask or Streamlit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Letting GPT generate new rooms for harder difficulty&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Try It or Fork It&lt;/strong&gt;&lt;br&gt;
Here's the full game repo on GitHub: &lt;a href="https://github.com/DynaKong/txt-based-game.git" rel="noopener noreferrer"&gt;https://github.com/DynaKong/txt-based-game.git&lt;/a&gt;&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Final Thoughts&lt;/em&gt;&lt;br&gt;
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.&lt;/p&gt;

</description>
      <category>python</category>
      <category>gamedev</category>
      <category>ai</category>
      <category>openai</category>
    </item>
  </channel>
</rss>
