Исключение переполнения стека при перемещении методов в другие классы
Привет,
Я работаю над игрой на C# в консольном приложении. Я попытался переместить свои "команды", которые вы можете использовать, в отдельные файлы классов, и теперь они вызывают ошибку StackOverflow. Грубый.
У меня есть 4 файла: Program. cs(обрабатывает игровой цикл и ввод и обработку методов), BasicCommands(содержит 5 методов для команд), SpeechCommands (то же самое, что и Basic, за исключением специально для речевых строк) и Character (конструктор символов/объект для персонажа игрока и NPC).
namespace DigitalLove { public class Program { public List<string> validWords = new List<string> { "look", "move", "check status", "hallway", "dance room", "bathroom", "punch bowl", "talk", "the scrawny boy", "the tall boy", "the girl", "take", "cup of punch", "the blond boy", "Rock", "Blues", "Forte", "Roll" }; public List<string> TalkingResponse = new List<string> { "uh...hi.", "of course not.", "yes", "no", "just here to have a good time.", "looking for people", }; public string[] Locations = { "Dance Room", "Bathroom", "Hallway", "Punch Bowl" }; public string Location, response, PlayerName, HeldItem; public Character Rockman; public Character Blues; public Character Forte; public Character Roll; public Character Player; public bool HoldingItem; SpeechCommands Command = new SpeechCommands(); BasicCommands Basic = new BasicCommands(); static void Main(string[] args) { Program Game = new Program(); Game.Game(); } public void Game() { //Game title here Console.WriteLine("Press enter to begin!"); Console.ReadKey(); Console.Clear(); Console.WriteLine("What is your name?"); PlayerName = Console.ReadLine(); while (PlayerName == "") { Console.WriteLine("Please enter a name!"); PlayerName = Console.ReadLine(); } Console.WriteLine("Thank you, " + PlayerName + ". Good luck!"); Console.WriteLine("Press enter to continue. . ."); Console.ReadKey(); Console.Clear(); Location = Locations[0]; Rockman = new Character(); Blues = new Character(); Forte = new Character(); Roll = new Character(); Player = new Character(); //Player definitons Player.CharacterName = PlayerName; Player.Location = Location; //Rockman definitons Rockman.CharacterName = "Rock"; Rockman.Location = Locations[0]; Rockman.MetTrigger = false; //Blues definitions Blues.CharacterName = "Blues"; Blues.Location = Locations[0]; Blues.MetTrigger = false; //Forte definitions Forte.CharacterName = "Forte"; Forte.Location = Locations[1]; Forte.MetTrigger = false; //Roll definitons Roll.CharacterName = "Roll"; Roll.Location = Locations[3]; Roll.MetTrigger = false; Console.WriteLine("You stand near the edge of the dance, shying away from everyone else who seems to be having a very good time." + "\n" + "You would love to join, but no one has approached you yet! You feel awkward trying to approach anyone, despite the numerous amount of people in the same position."); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Command List: Look, Move, Check Status"); Console.ResetColor(); GetInput(); } public string GetInput() { var Test = true; while (Test) { response = Console.ReadLine().ToLower(); if (validWords.Contains(response)) { Test = false; ProcessInput(response); } else { Console.WriteLine("I'm sorry, I do not understand."); } } return response; } public void ProcessInput(string response) { switch (response) { case "look": Basic.LookCommand(); break; case "move": Basic.MoveCommand(); break; case "Move": Basic.MoveCommand(); break; case "check status": Basic.CheckStatus(); break; case "hallway": Basic.MoveCommand(); break; case "dance room": Basic.MoveCommand(); break; case "bathroom": Basic.MoveCommand(); break; case "punch bowl": Basic.MoveCommand(); break; case "talk": Basic.TalkCommand(); break; case "the scrawny boy": Basic.TalkCommand(); break; case "the tall boy": Basic.TalkCommand(); break; case "the girl": Basic.TalkCommand(); break; case "take": Basic.TakeCommand(); break; case "cup of punch": Basic.TakeCommand(); break; case "the blond boy": Basic.TalkCommand(); break; } } public string GetTalkInput() { var Test = true; while (Test) { response = Console.ReadLine().ToLower(); if (TalkingResponse.Contains(response)) { Test = false; ProcessTalkInput(response); } else { Console.WriteLine("I'm sorry, I do not understand."); } } return response; } public void ProcessTalkInput(string response) { switch (response) { case "uh...hi.": Basic.TalkCommand(); break; case "of course not.": Basic.TalkCommand(); break; case "yes": Basic.TalkCommand(); break; case "no": Basic.TalkCommand(); break; } } } }
Где происходит исключение? Почему это происходит? Я мало что знаю об исключении переполнения стека. Стек вызовов в Visual Studio говорит только "внешний код".
Что я уже пробовал:
Я попытался сократить количество раз, когда я вызываю методы в других ответах.
Dave Kreskowiak
Обычно вы получаете Stackoverflow, когда у вас есть метод, постоянно вызывающий себя без какого-либо способа выхода из него, или есть набор методов, которые образуют цикл вызова без какого-либо способа выхода из него.