Original Post
Hey everyone! This is my first post here on gamedev but I've been perusing the forums for about a month now. Basically the language I chose to start learning is C#. I'm using VS2005 and currently working on my first text adventure. My question is pretty basic and pertains to the actual way one would design a basic text adventure in C#. I know this isn't coded right but basically my thought process is the Main function passes the current location id to the enter function which then passes it to the location function where all the room data is stored. The location function will check the id against the ids that have been defined to determine the room variable name and then pass that back to the enter function. Then the enter function can display the room name and description once it knows the variable name of the room the player is currently in. This is very basic and eventually I plan to have the room data stored in a txt file a function will read from and not hardcoded into the program. But for the purpose of simplicity I'm trying to get this to work first. If anyone has any ideas on how I can do this or knows of a better way to implement this concept your suggestions will be much appreciated. Thanks! EDIT: Added comments in code.
using System;
class Program
{
// basic structure for a room
struct room
{
public int id;
public string name;
public string desc;
}
// function that will display room name and description
static void enter(int pos)
{
location(loc);
Console.WriteLine(loc.name);
Console.WriteLine(loc.desc);
}
// function that checks current location and passes
// variable name to enter function
static string location(int pos)
{
string loc = "start";
room start;
start.id = 01;
start.name = "Starting Location";
start.desc = "This the the first room.";
return loc;
}
static void Main()
{
enter(start.id);
}
}