C# 如何设置与正确路线匹配的出口条件
我似乎无法正确设置退出条件 用于移动和间隔阵列的代码C# 如何设置与正确路线匹配的出口条件,c#,console-application,C#,Console Application,我似乎无法正确设置退出条件 用于移动和间隔阵列的代码 List<string> route = new List<string>() { "Bmiddle", "Middle", "Tmiddle", "TRight", "Right", "Middle", "Left", "Bleft", "Middl
List<string> route = new List<string>() { "Bmiddle", "Middle", "Tmiddle", "TRight", "Right", "Middle", "Left", "Bleft", "Middle", "Left" };
// this is the correct way the player should follow to be able to exit
List<string> Currentroute = new List<string>();
// each time the player is at a spot it should add it to this list in order to meet the exit condition
string[,] arrayLab = new string[3, 3] { {"Tleft", "TMiddle", "TRight"}, /*0 */
{"Left", "Middle", "Right"}, /*1 */
{"Bleft", "Bmiddle", "Bright"} }; /*2 */
do
{
// here is supposed to be all the controls and spacing to make it look like the array. and the logic
}
while (Currentroute != route)
//The Current route must match the Route in order to meet this exit
}
}
我尝试了这个方法,但它只是将char的位置拼写为char,并且没有保存它我不完全理解您的意思,但我准备了一段代码来浏览列表 最后,这两个列表的所有元素都是相等的
for (int i = 0; i < route.Count; i++)
{
bool exitloop = false;
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
if (arrayLab[j, k] == route[i])
{
Currentroute.Add(arrayLab[j, k]);
exitloop = true;
break;
}
}
if (exitloop)
break;
}
}
foreach (var item in Currentroute)
{
Console.WriteLine(item);
}
for(int i=0;i
在第一个列表中,将Tmiddle更改为Tmiddle,并且不要使用while循环。我希望它有用
for (int i = 0; i < route.Count; i++)
{
bool exitloop = false;
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
if (arrayLab[j, k] == route[i])
{
Currentroute.Add(arrayLab[j, k]);
exitloop = true;
break;
}
}
if (exitloop)
break;
}
}
foreach (var item in Currentroute)
{
Console.WriteLine(item);
}