c# - 需要有关 StackOverflowException 错误的帮助:请求的操作导致堆栈溢出
问题描述
我正在尝试制作一个迷你密码游戏以在课程中学习 c#,当我尝试让游戏读取密码时,我不断收到此错误。这是我需要摆脱的代码吗?或者也许添加?如果这有助于我使用统一作为我的引擎。谢谢
// Game state
int level;
enum Screen { MainMenu, Password, Win };
Screen currentScreen;
string password;
// Use this for initialization
void Start()
{
ShowMainMenu();
}
void ShowMainMenu()
{
currentScreen = Screen.MainMenu;
Terminal.ClearScreen();
Terminal.WriteLine("What would you like to hack into?");
Terminal.WriteLine("Press 1 for the local library");
Terminal.WriteLine("Press 2 for the police station");
Terminal.WriteLine("Enter your selection:");
}
void OnUserInput(string input)
{
if (input == "menu")
{
ShowMainMenu();
}
else if (currentScreen == Screen.MainMenu)
{
Runmainmenu(input);
}
else if (currentScreen == Screen.Password)
{
Checkpassword(input);
}
}
void CheckPassword(string input)
{
if (input == password)
{
checkpassword(input);
Terminal.WriteLine("Sorry, wrong password!");
}
else
{
Terminal.WriteLine("WELL DONE!");
}
}
private void checkpassword(string input)
{
Checkpassword(input);
}
private void Runmainmenu(string input)
{
{
if (input == "1")
{
level = 1;
password = "book";
StartGame();
}
if (input == "2")
{
level = 2;
password = "handcuffs";
StartGame();
}
else if (input == "007")
{
Terminal.WriteLine("Please select a level Mr Bond!");
}
else
{
}
}
}
void StartGame()
{
currentScreen = Screen.Password;
Terminal.WriteLine("You have chosen level " + level);
Terminal.WriteLine("Please enter your password: ");
}
void Checkpassword(string input)
{
checkpassword(input);
}
private void runmainmenu(string input)
{
runmainmenu(input);
}
string GetDebuggerDisplay()
{
return ToString();
}
解决方案
你给自己造成了一个无限循环,这会导致这个错误。
void Checkpassword(string input)
{
checkpassword(input);
}
private void checkpassword(string input)
{
Checkpassword(input);
}
推荐阅读
- angular - 如何更改角度自定义元素的网址
- apache - Apache mod_jk 负载均衡问题
- oracle - 甲骨文 11g CQN。一个记录更新的两个不同的 ROWID
- visual-studio - 我无法找到我的应用程序的位置下拉菜单(自动完成)。下面给出代码
- c# - 需要一些关于结合两个类的帮助
- c# - Selenium C# 在输入之前将光标设置为输入的结尾
- r - 如何在 R 中具有多个标题行的 flextable 中设置标题标签?
- encoding - 在 DataWeave mule 4 中编码重音字母
- git - SourceTree - 在 Unstaged 文件部分标记为“丢失”的文件 - 无法摆脱它们
- php - 为什么我的数据库仍然显示 2147483647 错误?