top of page

A.I. Prompt Engineering: Text-Based RPG Design and intro to simple graphics: Pong

Updated: Mar 3


[Note: this is not a blog post; it's for a class to easily access materials on one webpage!]




Decision-based RPG game:




Prompt used to create that game:


"Make a text-based RPG game about a hero with a gender neutral name saving a princess from a castle with a dragon. Allow the player to make decisions about how to navigate the castle (e.g., go up to the first floor, go to the basement, etc). Have a few random encounters, approximately one for every three player moves, and keep track of the player's health and the enemies' health. Have the "boss fight" in the top right tower right before saving the princess be a dragon. Give the option to slay the dragon or tame the dragon (if you tame it, you ride off with the princess on the dragon, the good ending). If you kill the dragon, you save the princess, the mediocre ending. If you die, bad ending. Making this slightly more creative to be interesting for 4th graders playing it as a pure text-based RPG. And make the game capable of running by simply copying and pasting your code into online-ide.com. Thanks, Claude!"


Note: this code didn't run on online-ide like the prompt asked it to. Why didn't it work? What did I forget to say in the prompt?









-------- EVERYTHING BELOW THIS LINE IS FROM EARLIER CLASSES ---------------------

----------------------------------------------------------------------------------------------------------------


For example, the following PROMPT was placed into Chat-GPT:


" Make a text-based pokemon-like rpg game. Keep track of hit points, move lists, susceptibility to types (for example: ice type is weaker against fire type), and give the player choices on which pokemon to choose and what moves to use. Do Pikachu, Charmander, Squirtle, Bulbasaur, and Evee and let them have three moves each. Make the objective of the game to cause the enemy pokemon to faint in each encounter. Let 3 different random encounters occur before a "final boss fight" with three battles in a row. When a pokemon wins, let them regain their health. Player wins when boss fight is completed successfully. Make this code run in Python on online-ide.com "


And then Chat-GPT produced the following code:


import random


# ---------- Type effectiveness ----------

TYPE_EFFECTIVENESS = {

("Fire", "Grass"): 2.0,

("Fire", "Water"): 0.5,

("Water", "Fire"): 2.0,

("Water", "Grass"): 0.5,

("Grass", "Water"): 2.0,

("Grass", "Fire"): 0.5,

("Electric", "Water"): 2.0,

("Electric", "Grass"): 0.5,

}


# ---------- Pokemon data ----------

POKEMON_DB = {

"Pikachu": {

"type": "Electric",

"max_hp": 100,

"moves": [("Thunder Shock", "Electric", 25),

("Quick Attack", "Normal", 20),

("Spark", "Electric", 30)]

},

"Charmander": {

"type": "Fire",

"max_hp": 110,

"moves": [("Ember", "Fire", 25),

("Scratch", "Normal", 20),

("Flame Burst", "Fire", 30)]

},

"Squirtle": {

"type": "Water",

"max_hp": 120,

"moves": [("Water Gun", "Water", 25),

("Tackle", "Normal", 20),

("Bubble Beam", "Water", 30)]

},

"Bulbasaur": {

"type": "Grass",

"max_hp": 115,

"moves": [("Vine Whip", "Grass", 25),

("Tackle", "Normal", 20),

("Razor Leaf", "Grass", 30)]

},

"Evee": {

"type": "Normal",

"max_hp": 125,

"moves": [("Quick Attack", "Normal", 25),

("Bite", "Normal", 30),

("Headbutt", "Normal", 28)]

}

}


# ---------- Helper functions ----------

def type_multiplier(move_type, defender_type):

return TYPE_EFFECTIVENESS.get((move_type, defender_type), 1.0)


def create_pokemon(name):

data = POKEMON_DB[name]

return {

"name": name,

"type": data["type"],

"max_hp": data["max_hp"],

"hp": data["max_hp"],

"moves": data["moves"]

}


def choose_move(pokemon):

print("\nChoose a move:")

for i, move in enumerate(pokemon["moves"], 1):

print(f"{i}. {move[0]} ({move[1]}, {move[2]} dmg)")

while True:

choice = input("> ")

if choice.isdigit() and 1 <= int(choice) <= 3:

return pokemon["moves"][int(choice) - 1]

print("Invalid choice.")


def battle(player, enemy):

print(f"\nA wild {enemy['name']} appeared!")

while player["hp"] > 0 and enemy["hp"] > 0:

print(f"\n{player['name']} HP: {player['hp']} | {enemy['name']} HP: {enemy['hp']}")


move = choose_move(player)

mult = type_multiplier(move[1], enemy["type"])

damage = int(move[2] * mult)

enemy["hp"] -= damage

print(f"{player['name']} used {move[0]}!")

if mult > 1:

print("It's super effective!")

elif mult < 1:

print("It's not very effective...")

print(f"It dealt {damage} damage!")


if enemy["hp"] <= 0:

print(f"{enemy['name']} fainted!")

return True


enemy_move = random.choice(enemy["moves"])

mult = type_multiplier(enemy_move[1], player["type"])

damage = int(enemy_move[2] * mult)

player["hp"] -= damage

print(f"{enemy['name']} used {enemy_move[0]} and dealt {damage} damage!")


return False


# ---------- Game start ----------

print("Welcome to the Text Pokémon RPG!\n")

print("Choose your Pokémon:")

for name in POKEMON_DB:

print("-", name)


while True:

choice = input("> ")

if choice in POKEMON_DB:

player = create_pokemon(choice)

break

print("Invalid Pokémon.")


print(f"\nYou chose {player['name']}!")


# ---------- Random encounters ----------

enemies = list(POKEMON_DB.keys())

enemies.remove(player["name"])


for encounter in range(1, 4):

print(f"\n--- Encounter {encounter} ---")

enemy = create_pokemon(random.choice(enemies))

if not battle(player, enemy):

print("You were defeated... Game over.")

exit()

player["hp"] = player["max_hp"]

print(f"{player['name']} recovered to full health!")


# ---------- Final Boss ----------

print("\n=== FINAL BOSS FIGHT ===")

boss_team = random.sample(enemies, 3)


for i, boss_name in enumerate(boss_team, 1):

print(f"\nBoss Battle {i}!")

boss = create_pokemon(boss_name)

boss["max_hp"] += 30

boss["hp"] = boss["max_hp"]

if not battle(player, boss):

print("The boss defeated you... Game over.")

exit()

player["hp"] = player["max_hp"]

print(f"{player['name']} recovered to full health!")


print("\n🏆 CONGRATULATIONS! 🏆")

print("You defeated the final boss and won the game!")



PONG GAME:


Comments


bottom of page