У меня есть консольное приложение, которое просит пользователя выбрать один из трех вариантов и при необходимости открыть инвентарь. Однако вместо того, чтобы проверить, являются ли какие-либо другие условия истинными, ложь, консоль просто линейно считывает условия и ждет, пока первое не будет выполнено. Так, например, в приведенном ниже коде он запускает первый бит текста, представляет параметры, а затем ожидает, пока пользователь введет «инвентарь», не рассматривая другие параметры. Что происходит? Почему это происходит? и как мне заставить консоль пройти и проверить, были ли выполнены все условия?
Вот код
using System;
using System.IO;
namespace Feed_de_monky
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
string one = "";
string two = "";
string inventory = "inventory";
int storyint = 0;
TextReader input = Console.In;
TextWriter output = Console.Out;
int options = 0;
if (storyint == 0)
{
Console.WriteLine("You are in a dark Jungle. You look into the darkness of the trees and see the silhouette of a tiger standing in front of you down the way.");
Console.WriteLine("");
Console.WriteLine("turn and run");
Console.WriteLine("pounce on tiger");
Console.WriteLine("climb a tree.");
options++;
if (input.ReadLine() == inventory)
{
output.WriteLine(one);
output.WriteLine(two);
return;
}
else if(input.ReadLine() == "turn and run" && options == 1)
{
output.WriteLine("");
output.WriteLine("The tiger chases you through the darkness. You never had a chance.");
Console.Write("Press any key to continue...");
Console.ReadKey(true);
}
else if(input.ReadLine() == "pounce on tiger" && options == 1)
{
output.WriteLine("");
output.WriteLine("The tiger is caught by surprise. You overwhelm the beast and he dies of shock and surprise on the spot");
one = "tiger skin";
output.WriteLine("TIGER SKIN ADDED TO YOUR INVENTORY");
storyint++;
options++;
}
else if(input.ReadLine() == "climb a tree" && options == 1)
{
output.WriteLine("");
output.WriteLine("You climb the tree. But while you sit on the branches believing yourself to be safe, the tiger jumps through the air and bites your head clean off. You never had a chance.");
Console.Write("Press any key to continue...");
Console.ReadKey(true);
}
Console.Write("Press any key to continue...");
Console.ReadKey(true);
}
}
}
}