This repository contains the final version of a Python text-based adventure game that uses an XML file to drive game content. It was created to help students in CSE 20 (and other beginner Python courses) learn how to combine Python logic with external data using XML.
If you're a student learning Python, this README will walk you through how to write your own version of this game step-by-step using the concepts you're learning in class.
By building this game yourself, you will practice:
- Reading structured data using
xml.etree.ElementTree - Writing Python functions and organizing code in modules
- Validating user input using
try/except - Looping through prompts and managing game state with variables
- Structuring a program to use external data (XML) instead of hardcoding content
- Using the terminal to run Python programs with arguments
This game is a choose-your-own-adventure style story. Players are presented with story prompts and must choose between two options. Each choice leads to a different outcome defined in an XML file. The game keeps track of the player’s name, score, and remaining lives.
main.py: The main program file that starts the game.AdventureGame.py: The game engine that loads and processes the XML, handles gameplay, and manages score and lives.prompts.xml: An external XML file that defines all story prompts and choices.README.md: Instructions (this file).starter/: A folder with empty template files you can use to start building your own version.
You should try to write the code yourself before looking at the full version in this repo.
Create a folder with three empty files:
main.pyAdventureGame.pyprompts.xml
- Make sure all 3 files (
main.py,AdventureGame.py, andprompts.xml) are in the same folder. - Open a terminal and navigate to that folder.
- Run the game with:
python3 main.py prompts.xml