Sto appena iniziando a imparare a creare giochi. Ho creato un semplice gioco basato sul testo in cui l'utente può passeggiare tra le stanze e interagire con gli oggetti in ogni stanza. Tuttavia, sento che il mio approccio ha portato a un mucchio di cattivi codici di spaghetti. Non sono sicuro di quale sarebbe un buon modo per strutturare un gioco come questo.
Il mio approccio era di avere una classe con un metodo per ogni stanza e tutti gli oggetti e le interazioni che si potevano fare in quella stanza. Ad esempio, questo è il metodo per lo studio:
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 ();
}
}
}
}
Non mi sembra che questo sia un approccio che scalerà; cioè, non posso davvero scrivere funzioni come questa per ogni stanza. Credo che usare i file in qualche modo sarebbe una buona strategia per evitare la "codifica" che sto attualmente facendo. Ma non sono sicuro di come ci riesco?