C# 如何存储第二个到最后一个值的值以与新值进行比较
我有这个密码C# 如何存储第二个到最后一个值的值以与新值进行比较,c#,android,unity3d,C#,Android,Unity3d,我有这个密码 string[,] table = new string[104, 15]; int xIndex = -1; int yIndex = 0; string newPrevious = "placeholder"; //P = BLUE, B = RED, T = GREEN string[] strData = {"P ,B ,P ,P B,B ,P ,B ,T ,P ,P "}; //conditions string
string[,] table = new string[104, 15];
int xIndex = -1;
int yIndex = 0;
string newPrevious = "placeholder";
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P ,B ,P ,P B,B ,P ,B ,T ,P ,P "};
//conditions
string[] scoreBoard = new string[]
{"P ", "B ", "T ",
"P B","B P" };
string OriginalData = "";
void Start(){
StartCoroutine ("Win_Log");
}
IEnumerator Win_Log(){
yield return new WaitForEndOfFrame ();
for (int i = 0; i < strData.Length; i++) {
OriginalData += strData [i];
OriginalData += ",";
}
string[] newNewData = OriginalData.Split (',');
string result = "";
foreach (string newStrData in newNewData) {
Debug.Log ("This is the data : " + newStrData);
GameObject o = Instantiate (prefab_gameobject) as GameObject;
o.transform.SetParent (pos_big_road);
o.transform.localScale = Vector3.one;
img = (RawImage)o.GetComponent<RawImage> ();
//check the length so that it won't throw an exception
if (newStrData.Length > 1) {
//get only the first letter of the value P,B,T
result = newStrData.Substring (0, 1);
}
else {
result = "";
}
#region BIG ROAD
if(table.GetLength(0) < xIndex){
break;
}
if (result.Equals (newPrevious) || result.Equals("T") && yIndex < table.GetLength (1)) {
yIndex += 1;
table [xIndex, yIndex] = result;
}
else if(newPrevious.Equals("T") && yIndex < table.GetLength (1)){
yIndex += 1;
table [xIndex, yIndex] = result;
}
else
{
xIndex += 1;
yIndex = 0;
table [xIndex, yIndex] = result;
}
newPrevious = result ;
o.transform.localPosition = new Vector3 (xIndex * 93, yIndex * -93, 0f);
BLUE,BLUE
必须在下一行,因为它不等于newPrevious
变量,这意味着我所说的红色
高于绿色
值。因此,您一定对这一点感到困惑,但是绿色
值更像是被忽略,我所说的忽略是这样的
现在在最后一列有一个值
蓝色,蓝色,绿色,红色,红色
它的价值是什么
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P ,B ,P ,P B,B ,P ,B ,T ,P ,P "};
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P ,B ,P ,P B,B ,P ,P ,T ,B ,B "};
如图所示,RED,RED
必须位于下一行,因为它不等于newPrevious
变量,我指的是绿色
值上方的蓝色
现在我想要的是我无法实现的:
这里我无法实现的是将newPrevious
的值放入一个变量,它将在GREEN
之前存储该值,以便我可以将其与新的newPrevious
值进行比较
例如,上面的图片具有以下值:
红,绿,蓝,蓝
我想保存红色
值,这样我可以将其与蓝色
值进行比较,这样我就可以用xIndex
而不是yIndex
编辑
预期的第一个图像输出必须为
第二个图像的预期输出必须是这样的
取另一个变量“previous”。将其设置为newPrevious的值,就像您现在所做的那样,并在下一次迭代中检查它是否已更改
替换这个
newPrevious = result ;
用这个
if(!result.Equals("T"))
newPrevious = result ;
此代码的问题是所有的
红色
和蓝色
值现在都只在X轴上。现在,当您希望更改行(更新y轴)时,它不会跟随if-else
语句中的my code,在if语句中使用previous的值对不起,我不太明白,我很抱歉。你能给我看第一张图像的预期输出吗..我会帮助你更好,然后我会编辑我的问题并给你看预期的输出