[英]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.