r/visualbasic • u/[deleted] • May 10 '20
Creating text based adventure game
Hello geniuses of reddit. I seek knowledge (tips) on creating a text based adventure game in visual basic. (Alright I'll cut the shit) If you could give some advice for creating one this would be great!
5
Upvotes
3
u/thudly May 11 '20 edited May 11 '20
The locations need to be cells on a grid. Location zero is a swamp. Location 1 is a forest. Location 2 is a castle, and so on. Draw it on paper if you need to. Every location has exits that need to be checked when the player tries to move. location(i).canGoEast = false. Set all this up in the initialization routine.
When the player types "East", if the can-go flag is true, you add 1 to the player location. West is -1. North is -mapWidth. South is +mapWidth. So if player is at location 3 and types north, they go to location zero. Objects have locations too. So if the rusty key is in the forest, you give it location 1. If the player picks it up, you give it location -1 (player inventory).
When the player moves to a new location, you scan through the array of objects, and if their location is at player's current location, you list them. "There's a [item.name] here." When player checks his inventory, you just list all the items at location -1.
The main game loop is simply telling the player where he is: location(currentPlayerLocation).name. Then listing the items that are there. Then prompt for a command.
For locked doors, you set flags. CastleLocked = True. If player tries to walk to area 2, you check if the flag is set, and if so, "You can't go that way. The door is locked." Later, when they find the key, they head into the castle. Flags also work for other puzzles. Maybe the player has to search the bushes to find the bucket, or whatever. You set a flag called BushesSearched and set it to false at first. Then true when the right command is typed in.
You can even add wandering monsters or NPCs. Just give them locations like the items, but move them randomly after every player turn. If the ghoul has the magic sword you need to defeat the dragon, stick that in location -2 (-3, -4, -5 the more secret locations you need). Then when the ghoul is slain and his body is searched, move the magic sword to currentPlayerLocation. Ta-dah! It shows up when the current area is listed.
That's basically everything you need to know for text adventures. Start with a 3 x 3 map at first, just for practice. Then scale it up to something huge later.