[英]Restrict from moving to X axis (C# Unity)
我有这个例子数据
数据:P,B,B,T,P
所以它将像这样输出
但是我发生的是
我在这里想要的是,每条领带都不得增加到X轴。 我如何获得?
到目前为止,这是我尝试过的方法:
string[] scoreboardWinner = new string[]
{
"P ","B ","T ",
"BP ","B P","B B","BB ",
"PB ","P B","P P","PP ",
"TP ","TB ","T P","T B",
"TTT",
"BBP","BPB","BPP","BBB",
"PPB","PBP","PBB","PPP"
};
private void XandYaxis() {
string[,] table = new string[104, 6];
string newPreviousValue = "placeholder";
int xIndex = -1;
int yIndex = 0;
if (gametable_no == 1)
{
for (int i = 0; i < list.Count; i++)
{
newString[0] += list[i].r;
}
string[] newChars = newString[0].Split(',');
if (table.GetLength(0) < xIndex)
{
break;
}
if (result.Equals(newPreviousValue) && yIndex < table.GetLength(1) - 1)
{
yIndex += 1;
table[xIndex, yIndex] = result;
}
else
{
xIndex += 1;
yIndex = 0;
table[xIndex, yIndex] = result;
}
}
}
我还尝试将if if语句放入
if (result.Equals(newPreviousValue) && yIndex < table.GetLength(1) - 1)
{
string newResult = scoreboardWinner[2];
if (previousValue.Contains(newResult))
{
yIndex += 1;
table[xIndex, yIndex] = result;
}
}
}
但这没有用。
顺便说一句, scoreboardWinner[2]
=“ T”; 这是TIE
当前位于同一列上的非几何条件是result.Equals(newPreviousValue)
,其显示为“新结果与先前的结果相同”。
您希望条件为“新结果与先前的结果相同,或者结果为TIE”。
通过替换来修改您的条件以反映这一点
result.Equals(newPreviousValue)
与
(result.Equals(newPreviousValue) || result == "T ")
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.