Can you design an Adventure or Zork like game, ChatGPT?


Can you design a simple, 10 room command-line game in the style of Adventure or Zork?


I can certainly provide you with an outline for a simple command-line game in the style of Adventure or Zork. Here is a basic structure that you can use:

  1. Create a class called “Room” that has the following attributes: name, description, and exits (a dictionary where the keys are the names of the exits and the values are the rooms they lead to).
  2. Create 10 instances of the Room class, each with its own unique name, description, and exits.
  3. Create a variable called “current_room” that starts at the first room.
  4. Create a game loop that: a. Prints the name and description of the current room b. Prints the exits of the current room c. Asks the user for a command (e.g. “go north”) d. Based on the command, update the current_room variable to the room the user wants to move to e. If the command is “quit”, end the game loop
  5. As you move forward, you can add more functionality like picking up items, using them in a room, adding puzzles and so on.

Here is an example of how the code might look like:

[ChatGPT failed to give me all 10 rooms for the example (not shown) so I asked for more…]


Can you add the last 7 rooms, but change them all to be in the style of a medieval castle?


Sure! Here’s an example of how you could create 7 more rooms for a medieval castle:

Kind of cool that ChatGPT first explained HOW to write an adventure-like REPL (read, eval, print loop) type command line game.

Does this python work? Let me check?

NOPE! That doesn’t even come close. Notice how the kitchen expects that the living and dining rooms already exist. They don’t. But, I wanted to see if it *could* work, so I tweaked and tweaked and this is Python code (below) that works.

We have to initialize all the rooms first, and then assign the exits later. Also, the first three rooms had no knowledge of the next seven, so I had to add a link from the living room to the throne room.

Anyway, it was an interesting experiment.

class Room:
    def __init__(self, name, description): = name
        self.description = description

kitchen = Room("Kitchen", "You are in a well-lit kitchen. There is a stove and a refrigerator here.")
living_room = Room("Living Room", "You are in a cozy living room. There is a fireplace and a sofa here.")
dining_room = Room("Dining Room", "You are in a formal dining room. There is a table and several chairs here.")
throne_room = Room("Throne Room", "You are in a grand throne room. A golden throne sits at the end of the room, and tapestries line the walls.")
armory = Room("Armory", "You are in a spacious armory. Swords, shields, and armor line the walls.")
courtyard = Room("Courtyard", "You are in a serene courtyard. A fountain bubbles in the center, and a stable for the castle's horses is nearby.")
dungeon = Room("Dungeon", "You are in a dimly lit dungeon. Iron bars line the walls, and the sound of dripping water echoes through the halls.")
secret_passage = Room("Secret Passage", "You are in a narrow secret passage. Cobwebs line the walls, and a musty smell fills the air.")
treasure_room = Room("Treasure Room", "You are in a grand treasure room. Gold, jewels, and precious artifacts line the walls.")

kitchen.exits        = {"north": living_room, "east": dining_room}
living_room.exits    = {"south": kitchen, "west": dining_room}
dining_room.exits    = {"west": kitchen, "east": living_room, "south": throne_room}
throne_room.exits    = {"west": dining_room, "south": armory, "north": dining_room}
armory.exits         = {"north": throne_room, "west": courtyard}
courtyard.exits      = {"east": armory, "south": dungeon}
dungeon.exits        = {"north": courtyard, "west": secret_passage}
secret_passage.exits = {"east": dungeon, "south": treasure_room}
treasure_room.exits  = {"north": secret_passage}

current_room = kitchen

while True:
    print("Exits:", ", ".join(current_room.exits))
    command = input("> ").split()
    if command[0] == "go":
        if command[1] in current_room.exits:
            current_room = current_room.exits[command[1]]
            print("You can't go that way.")
    elif command[0] == "quit":
        print("I don't understand that command.")

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s