Okay, I have a goal right now to make a basic text adventure. To do this, however, I would need/want to have a switch statement that can do the following:
How would I accomplish this? Could you show me coding for this specific example:
A user is prompted for data. A switch statement checks for "look box" as one case, and "sleep" as another. The program doesn't care what order any words are in, but does care about the order of the letters.
Please explain everything in detail. I just started coding.
EDIT: Thank you for all the answers. I understand there are better, more complicated, and more useful ways of handling this, but it just isn't at my level yet.
Here's another idea:
string input = "look at the sleep box";
bool caseA = input.Contains("sleep");
bool caseB = input.Contains("look") && input.Contains("box");
int scenarioId;
if (caseA && caseB)
scenarioId = 1;
else if (caseA)
scenarioId = 2;
else if (caseB)
scenarioId = 3;
// more logic?
else
scenarioId = 0;
switch (scenarioId)
{
case 1:
Console.WriteLine("Do scenario 1");
break;
case 2:
Console.WriteLine("Do scenario 2");
break;
case 3:
Console.WriteLine("Do scenario 3");
break;
// more cases
default:
Console.WriteLine("???");
break;
}
It uses if/then/else to assess a particular scenario including potential combinations such as input like "look at the sleep box"
and then uses a switch statement to execute accordingly.