Hartismere School

An outstanding coeducational secondary school & sixth form college and England's first academy

C# Text Adventure Game - Working Example

 


/*****  DEFINE ROOMS	 	*****/
Room prison_cell	= new Room( "prison cell" , "You're in a cell. There is a bed here." );
Room hallway		= new Room( "hallway" , "A long hallway." );
Room kitchen		= new Room( "kitchen" , "You're in a kitchen." );

There are three Rooms (locations).

Only items that cannot be picked up should be described in a Room

 

 

		
/*****  DEFINE NAVIGATION 	*****/
prison_cell.Out 	= hallway;
hallway.In		= prison_cell;
hallway.North		= kitchen;
kitchen.South		= hallway;

There is Navigation from the prison cell to to the hallway and from the hallway into the kitchen.

Navigation includes: North, South, East, West, Up, Down, In and Out only!

The player cannot leave the prison cell until they have found a key - but that comes later!

 

 


/*****  DEFINE THINGS		*****/
Thing book	= new Thing( "book" , "A Tale of Two Cities" , prison_cell );
Thing key	= new Thing( "key" , "A rusty old key." );

There are two Things:

The book starts off in the prison cell, but the key will remain hidden!

 

 


/*****  DEFINE ACTIONS		*****/
AddAction( "sing" , "You sing a lovely song!" );
book.AddAction( "read" , "Once upon a time... You read the rest of the book." );
kitchen.AddAction( "cook" , "You cook a lovely meal." );
hallway.LockedWith = key;
prison_cell.AddAction( "under bed" , key , "You have found a key!" );

The first Action can be performed anywhere - it's not tied to a Room or a Thing.

The second Action is tied to the book. It can only be performed with the book.

The third Action is tied to the kitchen: it can only be performed in the kitchen.

The fourth Action prevents the player from entering the hallway unless they are carrying the key.

The fifth Action reveals the key if the player looks under the bed when they're in the prison cell.

 

Launch repl.it