我有这个密码

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);

我的问题是
c# - 如何将第二个值存储到最后一个值以与新值进行比较-LMLPHP
正如你在最后一列看到的
红,绿,蓝,蓝
它的价值是
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P  ,B  ,P  ,P B,B  ,P  ,B  ,T  ,P  ,P  "};

BLUE, BLUE必须在下一行,因为它不等于newPrevious变量,这意味着我在讨论RED值上方的GREEN。所以你必须对此感到困惑,但是GREEN值更像是被忽略,我所说的被忽略是这样的
c# - 如何将第二个值存储到最后一个值以与新值进行比较-LMLPHP
在最后一列有一个值
蓝,蓝,绿,红,红
它的价值是
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P  ,B  ,P  ,P B,B  ,P  ,P  ,T  ,B  ,B  "};

正如您在图像中看到的,RED, RED必须在下一行,因为它不等于newPrevious变量,这意味着我在谈论BLUE值上方的GREEN
现在我想要的是我无法实现的:
在这里,我无法实现的是将newPrevious的值放到一个变量中,在这个变量中,它将在GREEN之前存储该值,以便我可以将其与新的newPrevious值进行比较。
例如,上面的图片具有
红,绿,蓝,蓝
我想保存RED值,以便可以将其与BLUE值进行比较,以便可以使用xIndex而不是yIndex来增加它。
编辑
预期的第一个图像输出必须是
c# - 如何将第二个值存储到最后一个值以与新值进行比较-LMLPHP
第二个图像的预期输出必须是这样的
c# - 如何将第二个值存储到最后一个值以与新值进行比较-LMLPHP

最佳答案

取另一个变量“previous”。将其设置为newprevious的值,就像您现在所做的那样,并在下一次迭代中检查它是否已更改。
替换这个

newPrevious = result ;

带着这个
if(!result.Equals("T"))
   newPrevious = result ;

关于c# - 如何将第二个值存储到最后一个值以与新值进行比较,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50383116/

10-12 00:31
查看更多