私は非常に混乱しています。これはコーディング/スクリプト作成の2番目のプロジェクトであり、選手が複数の選択肢を選択する方法を理解できません。ループは2番目または3番目の質問の後に続き、私は間違っていると思っているだけのコード行をスキップし続けます。C#複数の質問をループで尋ねる
static void Main(string[] args)
{
Random rng = new Random();
int stuff = 0;
bool gameGo = true;
string yourAnswer = "";
string choice1 = "";
string choice2 = "";
string choice3 = "";
string choice4 = "";
int healthPoints = 100;
int deathNumber = rng.Next(0, 10);
deathNumber = deathNumber = 0;
int stabbed = rng.Next(1, 4);
string name = "";
int trap = rng.Next(1, 5);
int arrow = rng.Next(7, 14);
int menu = 0;
int potion = rng.Next(1, 10);
int flyHealth = rng.Next(5, 10);
int flyAttack = rng.Next(3, 5);
int tribeAttack = rng.Next(80, 100);
int playersSword = rng.Next (3, 5);
while(true)
{
break;
}
while (gameGo || stuff == 1)
{
Console.Write("You have ");
Console.Write(healthPoints);
Console.Write(", health points left");
Console.Write(" \nIf your health points drops to ");
Console.Write(deathNumber);
Console.Write(", you will DIE!");
Console.WriteLine("\nWell now that that's out of the way, excuse me for being so rude but,\nmay i have your name? Please hit enter after to continue.");
name = Console.ReadLine();
Console.Clear();
if (name == "Dustin")
{
Console.Write("You have");
Console.Write(healthPoints);
Console.Write(", health points left");
Console.WriteLine("\nI am so proud of you for figuring out your name, {0}", name);
Console.WriteLine("Shall we move on to the story?\n Hit Enter to continue.");
Console.ReadLine();
menu = 2;
}
else if (name != "Dustin")
{
healthPoints -= stabbed;
Console.Clear();
Console.WriteLine("Seriously you cant figure out your name, how dumb are you?");
}
if (menu == 2)
{
Console.WriteLine("You see a cave in the distance.");
Console.WriteLine(" You have to make a choice.");
Console.WriteLine("Do you go in to explore or do you pass on by?");
Console.WriteLine("a) Do you go in\nOr B) do you pass by?");
choice1 = Console.ReadLine();
}
if (choice1 == "a")
{
Console.WriteLine("You enter a dark cave with no idea where to go but you found a sword.");
Console.WriteLine("The sword can do 1-5 damage.\n This is your only defense.");
Console.Write("\nTap enter once to continue");
Console.ReadLine();
menu = 3;
Console.Clear();
}
if (choice1 == "b")
{
Console.WriteLine("What, are you scared of the dark?");
healthPoints -= stabbed;
Console.WriteLine("A masked man stabbed you for not going in the cave and says");
Console.Write("you now have,");
Console.Write(healthPoints);
Console.Write(" health points left");
Console.WriteLine("Hit enter to continue.");
Console.ReadLine();
menu = 4;
continue;
}
{
while (menu == 3)
{
Console.WriteLine("You wander further in the cave and look around");
Console.WriteLine("You see a torch on the wall");
Console.WriteLine("You have another choice.\nDo you a) Light the torch \n or b) Leave it unlit");
choice2 = Console.ReadLine();
Console.Clear();
}
if (choice2 == "a")
{
Console.WriteLine("Well done my good sir, you have brought light to this wretched cave.");
Console.WriteLine("You move along slowly and encounter a giant fly.");
Console.Clear();
menu = 5;
}
if (choice2 == "b")
{
Console.WriteLine("What do you enjoy being in the dark?");
healthPoints -= stabbed;
Console.WriteLine("A masked man snuck up on you and stabbed you in the dark");
Console.Write("you now have,");
Console.Write(healthPoints);
Console.Write(" health points left");
Console.ReadLine();
Console.WriteLine("You move along slowly in the dark and encounter a giant fly.");
Console.ReadLine();
Console.Clear();
menu = 6;
}
}
{
while (menu == 4)
{
Console.WriteLine("You chose to keep walking along and not go into the cave.");
Console.WriteLine("You stumble across a large valley.");
Console.WriteLine("Time for another choice.");
Console.WriteLine("Do you a) Climb down the valley hoping for cool treasure?\nOR b) Keep walking along?");
choice3 = Console.ReadLine();
Console.Clear();
}
if (choice3 == "a")
{
Console.WriteLine("You decided to go into the valley");
Console.WriteLine("Little did you know there was a trap that got sprung as you climbed down");
healthPoints -= trap;
Console.Clear();
menu = 7;
}
if (choice3 == "b")
{
Console.WriteLine("How much more boring can you get, do you ever go on real adventures.");
Console.WriteLine("as you are walking along a stray arrow comes out of no where and strikes you in the leg.");
healthPoints -= arrow;
Console.Clear();
menu = 8;
}
}
{
while (menu == 5)
{
//giant fly fight
Console.Write("The giant fly swoops in to attack");
flyAttack -= healthPoints;
Console.WriteLine("The fly does {0} damage to your health", flyAttack);
Console.Write("You now have,");
Console.Write(healthPoints);
Console.Write(" health.");
Console.WriteLine("You attack back, with your sword you found");
playersSword -= flyHealth;
Console.WriteLine("You did {0} damage to the flys health points.", playersSword);
menu = 9;
}
while (menu == 6)
{
Console.Write("The giant fly swoops in to attack");
flyAttack -= healthPoints;
Console.WriteLine("The fly does {0} damage to your health", flyAttack);
Console.Write("You now have,");
Console.Write(healthPoints);
Console.Write(" health.");
Console.WriteLine("You attack back, with your sword you found");
playersSword -= flyHealth;
Console.WriteLine("You did {0} damage to the flys health points.", playersSword);
menu = 9;
}
while (menu == 7)
{
Console.WriteLine("You reach the bottom and come across a tribe of people.");
Console.WriteLine("This tribe has never seen another human before.");
Console.WriteLine("Hit enter to continue.");
Console.ReadLine();
Console.Clear();
Console.WriteLine("You hesitate for a bit wondering what to do. \nWhen all of a sudden the tribe attacks.");
healthPoints -= tribeAttack;
Console.Write("You have ");
Console.Write(healthPoints);
Console.Write(", health points left");
}
if (menu == 8)
{
//kept walking
}
if (menu == 9)
{
サイトのツアー中に見た[MCVE]トピックをもう一度読んで、リンクされたガイダンスに従って質問を編集してください。 "最小限"の部分に十分注意してください。 –
また、デバッガに慣れていない場合は、デバッガの使い方を学ぶ時間を取ってください。 Visual Studioに組み込まれたデバッガは、非常に簡単で直感的に使用できます。デバッガでコードを1行ずつ進めることで、このタイプの質問に自分で答えることができます。 –
もう一度お世話になりましたが、デバッガは何も選択しません –