【发布时间】:2022-01-06 11:48:57
【问题描述】:
所以我一直在尝试制作一个简单的基于文本的终端游戏来让自己更熟悉使用 c#,但我不知道如何让玩家回到开头以便他们可以解锁门,这就是我试过了。对于您即将看到的意大利面条代码,我深表歉意:
bool IsGameRunning = true;
bool hasKey = false;
if(isGameRunning == true){ Start();}
if(isGameRunning == true && Start() == "go forward" && hasKey == false){
while(true){
Middle();
if(Middle() == "go back"){
Start();
break;
}
}
}
else if(isGameRunning == true && Start() == "go left"){
while(true){
hasKey = true;
Key();
if(Key() == "go back"){
Start();
break;
}
}} else if(isGameRunning == true && Start() == "go forward" && hasKey == true){
Console.WriteLine("You tried the key...THE DOOR IS STILL LOCKED!!!");
}
//methods
static string Start(){
while(true){
Console.WriteLine("You are in a dark room, what do you do?");
string? input = Console.ReadLine();
if(input == "look around")
{
Console.WriteLine("It is too dark to look around.");}
else if(input == "go left"){
return "go left";
}
else if(input == "go forward"){
return "go forward";
} else{
Console.WriteLine($"I don't know what '{input}' means.");}
}
}
static string Middle(){
while(true){
Console.WriteLine("You decided to pick a direction and go forward.You stumbled upon a door, the door is locked.");
string? input = Console.ReadLine();
if(input == "go back"){
Console.WriteLine("You decided to return back from where you came.");
return "go back";
} else {
Console.WriteLine($"I don't know what '{input}' means.");
}
}
}
static string Key(){
while(true){
Console.WriteLine("You decided to pick a direction and go left.You found a key!");
string? input = Console.ReadLine();
if(input == "go back"){
Console.WriteLine("You decided to return back from where you came.");
return "go back";} else{
Console.WriteLine($"I don't know what '{input}' means.");
}
}
}
我不知道我在想什么。
【问题讨论】:
-
欢迎来到 Stack Overflow!在发布问题之前,请通过How to ask a good question 和How to create a minimal reproducible example。您的格式使该代码无法阅读,并且很难提供任何帮助。祝你好运!