Beispiel #1
0
    //    internal static void ChangeMyAnswer(int id, bool isColored)
    internal static void ChangeMyAnswer(int id, GridFlag operationState)
    {
        //throw new System.NotImplementedException();
        AnswerData tempAnswer = myPuzzleAnswers[id];

        if (null != tempAnswer)
        {
            currentGameState = GameState.IsPuzzled;//设定此时状态为‘正在游戏’
            if (operatingGridFlag == GridFlag.Negation)
            {
                tempAnswer.isBlocked = true;
            }
            else
            {
                if (CheckIsNegationState() && operationState == GridFlag.White)
                {
                    tempAnswer.isBlocked = false;
                }
                else if (!CheckIsNegationState() && !tempAnswer.isBlocked)
                {
                    bool isColored = operationState == GridFlag.White ? false : true;
                    tempAnswer.currentAnswer = isColored;

                    if (tempAnswer.isBlocked)
                    {
                        Debug.LogError(string.Format("something wrong with ad {0}", id));
                    }
                }
                if (tempAnswer.currentAnswer == tempAnswer.standardAnswer)
                {
                    TryToInvokeGameWinEvent();
                }
            }
        }
    }
Beispiel #2
0
    internal static void RestartGame()
    {
        //throw new System.NotImplementedException();
        couldControl = true;

        foreach (int id in myPuzzleAnswers.Keys)
        {
            myPuzzleAnswers[id].isBlocked     = false;
            myPuzzleAnswers[id].currentAnswer = false;
        }

        SavingDataManager.CreateInstance().ClearCurrentLevel();
        if (currentChequer != null)
        {
            currentChequer.RefreshOperatableGrids();
        }
        if (null != topLayerCamera)
        {
            topLayerCamera.HideTopWindow();
        }
        operatingGridFlag     = GridFlag.White;
        currentOperationState = OperationState.Pen;
        currentGameState      = GameState.IsPuzzled;

        Application.LoadLevel(GameConstants.MainSceneName);
    }
Beispiel #3
0
    internal void RefreshByAnswer()
    {
        GridFlag   gf = GridFlag.None;
        AnswerData ad = MainGame.GetPuzzleAnswerByGridID(this.ID);

        gf             = ad.isBlocked ? GridFlag.Negation : (ad.currentAnswer ? GridFlag.Black : GridFlag.White);
        operationState = gf;
        //Debug.Log(string.Format("id={0},gridFlag={1}", ID, operationState.ToString()));
        DisplayNewColor();
    }
Beispiel #4
0
    //internal static bool isNegationOperation = false;

    internal static bool CheckCouldModifyGridFlag(GridFlag opState)
    {
        bool result = true;

        if (CheckIsNegationState()) //如果当前是画x状态,那么x不会影响black
        {
            result = (opState != GridFlag.Black);
        }
        else //如果当前不是画x状态,那么black不会影响x
        {
            result = (opState != GridFlag.Negation);
        }

        return(result);
    }
Beispiel #5
0
    internal void ConvertTextToAnswer()
    {
        Debug.Log("load text is: " + answerText);
        string[] texts = answerText.Split(',');
        Dictionary <int, int> tempAnswers = new Dictionary <int, int>();
        int tempId = 1;

        foreach (string s in texts)
        {
            if (string.IsNullOrEmpty(s.Trim()))
            {
                continue;
            }
            try
            {
                int value = System.Convert.ToInt32(s);
                tempAnswers.Add(tempId, value);
                tempId++;
            }
            catch
            {
                Debug.LogError("FormatException: " + s + " in " + tempId);
            }
        }

        foreach (int id in tempAnswers.Keys)
        {
            GridFlag gf = GridFlag.None;
            switch (tempAnswers[id])
            {
            case 1:
                gf = GridFlag.Black;
                break;

            case 2:
                gf = GridFlag.Negation;
                break;

            default:
                gf = GridFlag.White;
                break;
            }
            MainGame.SetOperationState(gf);
            MainGame.ChangeMyAnswer(id, gf);
            MainGame.SetOperationState(GridFlag.None);
        }
    }
Beispiel #6
0
    // Update is called once per frame
    void Update()
    {
        if (MainGame.couldControl)
        {
            #region --------------- old --------------
            if (Input.GetMouseButtonDown(0))
            {
                if (CheckIsInGridRange())
                {
                    if (!MainGame.CheckIsContinousOperation() && MainGame.CheckCouldModifyGridFlag(operationState)) //没有连续操作/没有进行任何操作
                    {
                        operationState = MainGame.GetNextGridFlag(operationState);                                  //得到当前格的反操作(黑变白,白变黑,x变白,白变x)
                        MainGame.StartContinousOpeartion(operationState);                                           //画
                        shouldChangeColor = true;
                        //Debug.Log(string.Format("{0} - {1}", ID, operationState.ToString()));
                    }
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                if (MainGame.CheckIsContinousOperation())
                {
                    MainGame.StopContinuousOperation();
                }
            }
            else if (Input.GetMouseButton(0))
            {
                if (CheckIsInGridRange())
                {
                    if (MainGame.CheckIsContinousOperation())
                    {
                        GridFlag gameOperationState = MainGame.GetContinousGridFlag();
                        if (operationState != gameOperationState)
                        {
                            operationState    = MainGame.GetNextGridFlag(operationState);
                            shouldChangeColor = true;
                        }
                    }
                }
            }

            #endregion
        }
        SetAndDisplayNewColor();
    }
Beispiel #7
0
    internal static GridFlag GetNextGridFlag(GridFlag opState)
    {
        GridFlag result = GridFlag.None;

        switch (opState)
        {
        case GridFlag.Black:
            result = CheckIsNegationState() ? GridFlag.Black : GridFlag.White;
            break;

        case GridFlag.Negation:
            result = CheckIsNegationState() ? GridFlag.White : GridFlag.Negation;
            break;

        case GridFlag.White:
            result = CheckIsNegationState() ? GridFlag.Negation : GridFlag.Black;
            break;

        default:
            result = opState;
            break;
        }
        return(result);
    }
Beispiel #8
0
 public void AddFlag(int x, int y, GridFlag flag)
 {
     GridData[x, y] |= (int)flag;
 }
Beispiel #9
0
 public void ClearFlag(int x, int y, GridFlag flag)
 {
     GridData[x, y] &= ~(int)flag;            //清除标记
 }
Beispiel #10
0
    public Dictionary<int, int> SpecialBlock = new Dictionary<int, int>();      //关卡开始特殊块

    public bool CheckFlag(int x, int y, GridFlag flag)
    {
        if ((GridData[x, y] & (int)flag) > 0)
        {
            return true;
        }
        return false;
    }
Beispiel #11
0
	private bool checkAndAddAdjacentPawnList(PawnType checkType, List<Pawn> adjacentPawnList) {
		if (adjacentPawnList.Count >= ADJACENT_COUNT_TO_ELIMINATE) {

			// set grid flag
			AdjacentPawnList preCollectedAdjacentList = null;

			foreach (Pawn pawnInAdjacent in adjacentPawnList) {
				GridFlag gridFlag = _gridFlags[(int)checkType, pawnInAdjacent.gridIndex];
				if (gridFlag.adjacentPawnList != null) {
					preCollectedAdjacentList = gridFlag.adjacentPawnList;
					break;
				}
			}
			
			if (preCollectedAdjacentList != null) {
				// merge adjacent list available
				HashSet<AdjacentPawnList> differentAdjacentLists = new HashSet<AdjacentPawnList>();

				foreach (Pawn pawnInAdjacent in adjacentPawnList) {
					GridFlag gridFlag = _gridFlags[(int)checkType, pawnInAdjacent.gridIndex];
					if (gridFlag.adjacentPawnList != null) {
						if (gridFlag.adjacentPawnList != preCollectedAdjacentList) {
							mergeAdjacentPawnList(checkType, preCollectedAdjacentList, gridFlag.adjacentPawnList.finalList);
							differentAdjacentLists.Add(gridFlag.adjacentPawnList);
						}
					} else {
						_gridFlags[(int)checkType, pawnInAdjacent.gridIndex].adjacentPawnList = preCollectedAdjacentList;
						preCollectedAdjacentList.finalList.Add(pawnInAdjacent);
						differentAdjacentLists.Add(null);
					}
				}

				foreach (AdjacentPawnList list in differentAdjacentLists) {
					if (list != null) {
						preCollectedAdjacentList.mergedLists.AddRange(list.mergedLists);
					} else {
						preCollectedAdjacentList.mergedLists.Add(adjacentPawnList);
					}
					 
					if (list != null && list.maxPawnInListBeforeMerge > preCollectedAdjacentList.maxPawnInListBeforeMerge) {
						preCollectedAdjacentList.maxPawnInListBeforeMerge = list.maxPawnInListBeforeMerge;
					}
				}

				preCollectedAdjacentList.removeOverlappedMergedLists();

				if (adjacentPawnList.Count > preCollectedAdjacentList.maxPawnInListBeforeMerge) {
					preCollectedAdjacentList.maxPawnInListBeforeMerge = adjacentPawnList.Count;
				}

				Debug.Log ("update eliminate list:" + preCollectedAdjacentList.ToString());
			} else {
				AdjacentPawnList newAdjacentList = new AdjacentPawnList();
				newAdjacentList.finalList.AddRange(adjacentPawnList);
				newAdjacentList.maxPawnInListBeforeMerge = adjacentPawnList.Count;
				newAdjacentList.mergedLists.Add(adjacentPawnList);

				foreach (Pawn pawnInAdjacent in adjacentPawnList) {
					_gridFlags[(int)checkType, pawnInAdjacent.gridIndex].adjacentPawnList = newAdjacentList;
				}
				
				Debug.Log ("add eliminate list:" + newAdjacentList.ToString());
				_pawnListToEliminate.Add(newAdjacentList);
			}

			return true;
		}

		return false;
	}
Beispiel #12
0
 internal static void StopContinuousOperation()
 {
     //throw new System.NotImplementedException();
     operatingGridFlag = GridFlag.None;
 }
Beispiel #13
0
 internal static void SetOperationState(GridFlag operationFlag)
 {
     operatingGridFlag = operationFlag;
 }
Beispiel #14
0
 internal static void StartContinousOpeartion(GridFlag gridOpeationState)
 {
     //throw new System.NotImplementedException();
     operatingGridFlag = gridOpeationState;
 }