Introduction
“Programs must be written for people to read, and only incidentally for machines to execute.” — Harold Abelson
Welcome to my first coding project! This project signifies the beginning of my journey into programming and computational knowledge with the language of Python. As someone new to Python coding, I am excited to explore the immense potential of Python, a versatile and beginner friendly language. I will use these skills to solve problems and create meaningful programs.
Throughout this project, I aim to develop my understanding of basic programming concepts such as variables, loops, conditionals, and functions, while also nurturing curiosity, persistence, and logical thinking. I hope that this piece of work not only demonstrates my learning progress but also reflects my passion for technology and STEM in general.
As Steve Jobs once said, “Everybody in this country should learn to program a computer… because it teaches you how to think.” With that in mind, this project is my first step toward thinking like a programmer, embracing challenges, and building skills that will last my lifetime.
Explanation of Code
1. Modules
- import random → lets the game choose random numbers for attacks, healing, and enemy selection.
- import time → allows the game to pause for a short time to print text slowly and make it dramatic.
2. Functions
slow_print(text, delay=0.03)
- Prints text character by character instead of all at once.
- text → the message to display.
- delay → how long to wait between characters (default 0.03 seconds).
choose_enemy(defeated_enemies)
- Makes a list of all possible enemies with their name, HP, and attack power.
- Checks defeated_enemies to see which enemies are still available.
- Returns a random enemy if there are any left, otherwise returns a Dragon.
player_attack() / player_special()
- player_attack() → normal attack, deals 8–15 damage.
- player_special() → stronger attack, deals 20–30 damage.
enemy_attack(enemy) / enemy_special(enemy)
- Damage depends on the enemy’s attack stat.
- enemy_special() is stronger than enemy_attack().
3. Player Variables
player = {
“name”: input(“Enter your hero’s name: “)
“hp”: 100
“level”: 1
“xp”: 0
“gold”: 0
“special_cooldown”: 0
- name → player’s input
- hp → player health points. Starts at 100
- level → starts at 1, increases with XP
- xp → experience points earned from defeating enemies
- gold → currency gained from enemies
- special_cooldown → how many turns until player can use special attack again
- defeated_enemies = [] → keeps track of which enemies have already been beaten
4. Main Game Loop
- Uses while True: to keep the game running until player quits or dies
- Shows player stats and asks for an action: explore, rest, or quit
Player Actions
- Quit → stops the game.
- Rest → heals 10–25 HP (but not over 100) and reduces special cooldown by 1
- Explore → chooses an enemy and enters a combat loop
5. Combat Loop
- Continues while enemy HP > 0 and player HP > 0
- Player chooses: attack, special, or run
Player Choices
- Attack → normal damage, subtract from enemy HP
- Special → stronger attack, only if special_cooldown is 0; sets cooldown to 3 turns
- Run → 50% chance to escape
- Invalid input → asks again
Enemy Turn
- Dragon has a 30% chance to use special attack
- Otherwise, enemy does normal attack
- Damage is subtracted from player HP
- Player’s special cooldown decreases each turn if above 0
6. After Battle
- If enemy dies → gain XP and gold
- If XP ≥ level × 50 → level up, reset HP to 100
- If Dragon dies → win the game
- If player HP ≤ 0 → game over
7. Loops and Conditionals
- while True: → main game loop
- while enemy[‘hp’] > 0 and player[‘hp’] > 0: → combat loop
- if / elif / else → checks player input and enemy actions
- for char in text: → used in slow_print to print each character
8. Randomness
Run chance
random.randint(a, b) → random integer between a and b
Used for:
Player and enemy attacks
Healing
Enemy selection
This is my flowchart that describes how my program runs and works. It also includes parts of my thought process when I initially decided to create this game.

Explained in Detail
This Python program is a text-based adventure game that runs entirely in the console. It uses functions and loops to create an interactive battle system.
The player controls a hero with stats like HP, level, XP, and gold, all stored in the code. You can choose to rest, explore, or quit. Resting increases HP and decreases your special attack cooldown. Exploring triggers a random encounter with an enemy, selected from a list using the random module. Each enemy also has its own dictionary containing its name, HP, and attack power.
During battle, a while loop does the combat every turn. You can pick from three actions: attack, special, or run. Regular attacks deal random damage using random.randint(), while special attacks are stronger but it requires waiting a few turns before you can reuse it. Enemies also attack each round, and their damage is randomly calculated within a range.
When an enemy is defeated, you earn random amounts of XP and gold. If your XP exceeds a threshold (which is based on your level), you level up, your HP refills, and the game gets progressively harder. The program keeps track of all defeated enemies, and once you’ve beaten them all, you’ll face the final boss, the Dragon.
If your HP drops to zero, the game ends with a “Game Over.” Beating the Dragon prints a victory message and ends the main game loop.
Leave a Reply