I am just getting started learning to make games. I have created a simple text-based game where the user can walk around between rooms and interact with the objects in each room. However, I feel like my approach has led to a pile of bad spaghetti code. I'm not sure what a good way to structure a game like this would be.
My approach was to have one class with a method for each room and all the objects and interactions that could be done in that room. For example, this is the method for the study:
public static void Study()
{
bool studyexited = false;
while (!studyexited) {
string usercommand = Console.ReadLine ();
usercommand.ToLower ();
switch (usercommand) {
case "turn left":
GameEventText.StudyLeft ();
break;
case "turn right":
GameEventText.StudyRight ();
break;
case "go forward":
Notes firstsetofclues = new Notes ("First Note");
GameEventText.StudyFront ();
string firststudycommand = Console.ReadLine ();
firststudycommand.ToLower ();
if (firststudycommand == "read note") {
firstsetofclues.Firstnotereading ();
}
Console.WriteLine ("Picking up this note would prove valuable");
string secondstudycommand = Console.ReadLine ();
secondstudycommand.ToLower ();
if (secondstudycommand == "pick up note") {
if (MainClass.PlayerInventory.AddItem (firstsetofclues))
{
Console.WriteLine ("The note has been added to your inventory");
} else {
Console.WriteLine ("Your inventory is full");
}
MainClass.PlayerInventory.Inventorydisplay ();
}
}
}
}
I don't feel like this is an approach that will scale; that is, I can't really write functions like this for every room. I believe that using files in some way would be a good strategy to avoid the "hard coding" that I'm currently doing. But I am not sure how I can achieve that?