Skip to content

Instantly share code, notes, and snippets.

@mrnebbi
Created October 31, 2016 14:15
Show Gist options
  • Save mrnebbi/cc97c4db194f80e4917182d54bef7168 to your computer and use it in GitHub Desktop.
Save mrnebbi/cc97c4db194f80e4917182d54bef7168 to your computer and use it in GitHub Desktop.

Text adventure game overview

World is described in a text file, or multiple text files. A global area for usable actions is described in the file, how a an action affects your characters health, movements, etc. e.g. drink drinks, eat food, etc.

If user types eat and there is no food in their bag, or current room then “no food is available” can be displayed.

Contents of the room, other people, usable items, directions you can go are all described in the file for each room you enter.

e.g.

1: {
	name: “Dungeon”,
	locked: false,
	enter: {
		first: “It’s dark here, you hear the occasional clinking of chains, and can smell the sweat and fear in the air like a thick fog. This seems to be a dungeon of some kind.”,
		low-health: “You’re in the dungeon. You’re not exactly in good shape, I’d stay clear of guards if I were you.”		
	},
	exits: {
		2: “A stairway leading to who knows where?”,
		6: “A large cell door.”,
		7: “An open window. A strange thing to find in a dungeon, but it looks like a small drop.”
	},
	items: {
		sandwich: {
			description: “A sandwich. Looks like cheese and pickle. Also looks like it's a little old.”,
			item: 5
		},
		wine: {
			description: “The wine smelled a little like vinegar, but jailers can’t be choosers.”,
			item: 21
		},
		keys: {
			description: “A large bunch of large keys, to fit some large key holes. Probably carried by a large jailer.”,
			item: 12
		}
	}
},
6: {
	name: “Cell”,
	locked: true,
	enter: {
		first: “It's a jail cell. It's empty.”
…

Items are described per room, allowing you to provide descriptions that refer to things with some context. The item has an ID to provide all of the properties and how to describe the item later. This is also used to add items to your bag, and to provide a multiple item count. E.g. character may have 5 stale sandwiches. They all behave the same way, so only one item number is stored with a quantity of five.

Items: {
	4: {
		type: food,
		description: [“It's a rather tasty looking cheese and pickle sandwich.”,"A deconstructed sandwich of smoked cheese and fresh pickle, that has been cunningly reconstructed between two pieces of bread… It's a sandwich."],
		health: 40,
		done: "That was good."
	},
	5: {
		type: food,
		description: “The sandwich looks like it’s seen better days.”,
		health: 20,
		done: "Well it filled a hole, but it tasted a little off.",
		temporary: {
			type: turn,
			health: -2,
			recurring: true,
			duration: 5
			done: {
				msg: “You’re feeling a lot better now. That’s the last time you eat three day old pickle.”
			}
		}
	},
	12: {
		type: key,
		description: “A large bunch of large keys, to fit some large key holes. Probably carried by a large jailer.”,
		opens: [3,6,8]
	},
	21: {
		type: drink,
		description: [“The wine smelled a little like vinegar.”,"To say the wine was inviting would be a lie.","It's the kind of wine you'd choose not to put in your cooking."],
		health: 10,
		done: ["*hic* Delicious!", "Whoa, that was some strong wine. Feeling a little wobbly now."],
		temporary: {
			type: time,
			stealth: -5,
			duration: 5000,
			done: {
				msg: “You’ve sobered up a bit now. That was some strong wine.”,
				stealth: 5
			}
		}
	}
}

Certain items will change your characters properties. Eating an item with a health increase will obviously increase your health. Items may poison you though. These items add an entry to a temporary events list, either as a timed event (e.g. health increases every second for 1 minute), or a turn based event (e.g. character loses 5 health every turn for 6 turns).

Turn based events can be described as recurring meaning they happen again every turn until the duration of turns is finished.

The temporary event list is checked and events performed E.g. dropping the characters health by 5 every turn, and showing a message when the item is finished and removed from the list.

@gavbarnett
Copy link

Maybe we need base 'elements' for all items.
I.e. you can deconstruct a sandwich down to cheese but you can't deconstruct cheese any further so it must be a base element. But you do get different kinds of cheese so we need element variants too.

@gavbarnett
Copy link

We basically need to implement a set of UML /SysML logic here.
X is a component of Y (cheese is part of a sandwich)
Z is a type of (instance of) Y (Cheese and pickle sandwich is a type of sandwich)
Y must have 2x W and can have 1x X (sandwiches need two birds of bread and can have cheese)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment