コード例 #1
0
ファイル: PlayerSaveData.cs プロジェクト: ashlam/PixelLove
    internal void ConvertAnswerToText()
    {
        maxColumns = MainGame.maxColumns;
        maxRows    = MainGame.maxRows;
        List <string> xxx     = new List <string>();
        StringBuilder sb      = new StringBuilder();
        bool          isFirst = true;

        for (int row = 1; row < maxRows + 1; row++)
        {
            for (int col = 1; col < maxColumns + 1; col++)
            {
                int        tempId = MainGame.ConvertToGridID(col, row, maxColumns);
                AnswerData ad     = MainGame.GetPuzzleAnswerByGridID(tempId);
                if (null == ad)
                {
                    Debug.LogError("save error!");
                    return;
                }
                int v = -1;
                if (ad.isBlocked)
                {
                    v = 2;
                }
                else
                {
                    v = ad.currentAnswer ? 1 : 0;
                }
                if (isFirst)
                {
                    isFirst = false;
                    sb.Append(v.ToString());
                }
                else
                {
                    sb.Append("," + v.ToString());
                }
            }
        }
        answerText = sb.ToString();
    }
コード例 #2
0
    static List <int> GetGrayClueIndexes(int fixedRowOrColIndex, bool isFixedRow, List <ColorableClueNumber> scaningClues, bool isAsc)
    {
        List <int> result           = new List <int>();
        int        lastValue        = -1;
        int        chainedCount     = 0;
        int        selectClueIndex  = isAsc ? 0 : scaningClues.Count - 1;
        int        maxRowOrColIndex = (isFixedRow ? (MainGame.maxColumns + 1) : (MainGame.maxRows + 1));

        for (
            int tempColOrRowIndex = isAsc ? 1 : maxRowOrColIndex - 1;
            isAsc ? (tempColOrRowIndex < maxRowOrColIndex) : (tempColOrRowIndex >= 1);
            tempColOrRowIndex = isAsc ? tempColOrRowIndex + 1 : tempColOrRowIndex - 1)
        {
            int gridId = -1;
            if (isFixedRow)
            {
                gridId = MainGame.ConvertToGridID(tempColOrRowIndex, fixedRowOrColIndex, MainGame.maxColumns);
            }
            else
            {
                gridId = MainGame.ConvertToGridID(fixedRowOrColIndex, tempColOrRowIndex, MainGame.maxColumns);
            }

            if (myPuzzleAnswers.ContainsKey(gridId))
            {
                if (isAsc ? (selectClueIndex > scaningClues.Count - 1) : (selectClueIndex < 0))
                {
                    break;
                }

                AnswerData ad = myPuzzleAnswers[gridId];
                //Debug.Log(string.Format("AD id={0},isAnswered={1},isBlocked={2}", gridId, ad.currentAnswer, ad.isBlocked));
                if (ad.currentAnswer)
                {
                    chainedCount++;
                    if ((isAsc && tempColOrRowIndex == (maxRowOrColIndex - 1)) || (!isAsc && tempColOrRowIndex == 1))
                    {
                        if (chainedCount == scaningClues[selectClueIndex].number)
                        {
                            result.Add(selectClueIndex);
                        }
                        else
                        {
                        }
                    }
                }
                else if (ad.isBlocked)
                {
                    if (lastValue == 1)
                    {
                        if (chainedCount == scaningClues[selectClueIndex].number)
                        {
                            result.Add(selectClueIndex);
                        }

                        chainedCount    = 0;
                        selectClueIndex = isAsc ? selectClueIndex + 1 : selectClueIndex - 1;
                    }
                }
                else if (!ad.currentAnswer)
                {
                    if (lastValue == 1 && (chainedCount == scaningClues[selectClueIndex].number))
                    {
                        result.Add(selectClueIndex);
                        selectClueIndex = isAsc ? selectClueIndex + 1 : selectClueIndex - 1;
                        chainedCount    = 0;
                    }
                    break;
                }
                lastValue = (ad.isBlocked) ? 2 : ad.currentAnswer ? 1 : 0;
            }
        }

        return(result);
    }
コード例 #3
0
    static List <int> GetGrayClueIndexsByCurrentAnswer(int fixedRowOrColIndex, bool isFixedRow, List <ColorableClueNumber> scaningClues)
    {
        //同样的,得到id->得到currentAnswer->到达断点时,if数量匹配,then add,else break;
        //所以你要先有个id
        int        chainedCount     = 0;
        int        selectClueIndex  = 0;
        int        maxRowOrColIndex = (isFixedRow ? (MainGame.maxColumns + 1) : (MainGame.maxRows + 1));
        int        lastValue        = -1;
        List <int> result           = new List <int>();

        for (int tempColOrRowIndex = 1; tempColOrRowIndex < maxRowOrColIndex; tempColOrRowIndex++)
        {
            int gridId = -1;
            if (isFixedRow)
            {
                gridId = MainGame.ConvertToGridID(tempColOrRowIndex, fixedRowOrColIndex, MainGame.maxColumns);
            }
            else
            {
                gridId = MainGame.ConvertToGridID(fixedRowOrColIndex, tempColOrRowIndex, MainGame.maxColumns);
            }
            if (myPuzzleAnswers.ContainsKey(gridId))
            {
                AnswerData ad = myPuzzleAnswers[gridId];

                if (selectClueIndex > scaningClues.Count)
                {
                    result.Clear();
                    break;
                }

                //bool isBreaking = false;
                if (ad.currentAnswer)
                {
                    chainedCount++;
                    if (selectClueIndex >= scaningClues.Count)
                    {
                        result.Clear();
                        break;
                    }
                    else if (tempColOrRowIndex == maxRowOrColIndex - 1 && chainedCount == scaningClues[selectClueIndex].number)
                    {
                        result.Add(selectClueIndex);
                    }
                }
                else
                {
                    if (lastValue == 1)
                    {
                        if (selectClueIndex < scaningClues.Count && scaningClues[selectClueIndex].number == chainedCount)
                        {
                            //Debug.Log("add selecteIndex : " + selectClueIndex + ", current chainCount = " + chainedCount);
                            result.Add(selectClueIndex);
                            selectClueIndex++;
                            chainedCount = 0;
                        }
                        else
                        {
                            result.Clear();
                            break;
                        }
                    }
                }
                lastValue = ad.currentAnswer ? 1 : 0;
            }
        }
        if (result.Count != scaningClues.Count)
        {
            result.Clear();
        }
        return(result);
    }
コード例 #4
0
ファイル: Chequer.cs プロジェクト: ashlam/PixelLove
    private void AutoCreateClues()
    {
        //throw new System.NotImplementedException();
        if (null != originalClueSample)
        {
            int maxVerticalTextCount   = 0;
            int maxHorizontalTextCount = 0;
            //MainGame.ResetClueTextDatas ();	//clean exists clueTexts;
            Debug.Log("should clear colorTexts from mainGame");
            MainGame.ClearAllColorClueNumbers();

            #region ------------- vertical clues -------------
            //创建每一列的Clue
            for (int col = 1; col < columnCount + 1; col++)
            {
                Clue clonedClue = GameObject.Instantiate(originalClueSample) as Clue;//创建对象
                //赋根节点
                clonedClue.transform.parent = transOfClueRoot;
                //赋位置
                clonedClue.col                     = col;
                clonedClue.isHorizontal            = false;
                clonedClue.transform.localPosition = new Vector2(col, 0);
                clonedClue.name                    = "Clue(col)" + col.ToString("00");
                //赋值(文字)

                for (int tempRowIndex = 1; tempRowIndex < rowCount + 1; tempRowIndex++)
                {
                    int tempGridId = MainGame.ConvertToGridID(col, tempRowIndex, columnCount);
                    clonedClue.AddManagedGrid(tempGridId);
                }
                clonedClue.CreateClueText();
                maxVerticalTextCount = Mathf.Max(maxVerticalTextCount, clonedClue.numberList.Count);
            }


            #endregion

            #region ----------- horizontal clues -------------
            //创建每一行的Clue
            for (int row = 1; row < rowCount + 1; row++)
            {
                Clue clonedClue = GameObject.Instantiate(originalClueSample) as Clue;//创建对象
                //赋根节点
                clonedClue.transform.parent = transOfClueRoot;
                //赋位置
                clonedClue.row                     = row;
                clonedClue.isHorizontal            = true;
                clonedClue.transform.localPosition = new Vector2(0, -row);
                clonedClue.name                    = "Clue(row)" + row.ToString("00");
                //赋值(文字)
                for (int tempColumnIndex = 1; tempColumnIndex < columnCount + 1; tempColumnIndex++)
                {
                    int tempGridId = MainGame.ConvertToGridID(tempColumnIndex, row, columnCount);
                    clonedClue.AddManagedGrid(tempGridId);
                }
                clonedClue.CreateClueText();
                maxHorizontalTextCount = Mathf.Max(maxHorizontalTextCount, clonedClue.numberList.Count);
            }

            #endregion

            foreach (Clue tempClue in transOfClueRoot.GetComponentsInChildren <Clue>())
            {
                int textCount = tempClue.isHorizontal ? maxHorizontalTextCount : maxVerticalTextCount;
                tempClue.CreateBackground(textCount);
            }
        }
    }