コード例 #1
0
        internal void HandleUndo()
        {
            bool canUndo = gameEngine.CheckCanUndo();

            if (canUndo)
            {
                string   code = gameEngine.GetUndoCode();
                string[] moveDetailStructArray = code.Split(',');

                MoveDetailStruct moveDetailStruct = new MoveDetailStruct()
                {
                    EmptyCellTag         = int.Parse(moveDetailStructArray[0]),
                    ButtonClickedTag     = int.Parse(moveDetailStructArray[1]),
                    ButtonClickedContent = moveDetailStructArray[2],
                };

                gameEngine.UpdateArray(moveDetailStruct);

                Button emptyCellButton = GetButtonWithTag(moveDetailStruct.EmptyCellTag);
                Button button          = GetButtonWithTag(moveDetailStruct.ButtonClickedTag);

                SwapContents(emptyCellButton, button);

                gameEngine.AddRedo(code);
            }
        }
コード例 #2
0
        internal void HandleClickEvent(Button buttonClicked)
        {
            Button emptyCell = GetButtonWithString(string.Empty);

            MoveDetailStruct moveDetailStruct = GetMoveDetailStruct(buttonClicked, emptyCell);

            bool valideMove = gameEngine.CheckMove(moveDetailStruct);

            if (!valideMove)
            {
                return;
            }

            CheckIfTimerIsEnabled();

            gameEngine.UpdateArray(moveDetailStruct);

            gameEngine.AddToUndo(moveDetailStruct);
            gameEngine.ClearRedoStack();

            SwapContents(emptyCell, buttonClicked);

            HandleEndGame();
        }
コード例 #3
0
        internal bool CheckMove(MoveDetailStruct moveDetailStruct)
        {
            if (moveDetailStruct.ButtonClickedContent == string.Empty)
            {
                return(false);
            }

            if (moveDetailStruct.ButtonClickedTag == 2 && moveDetailStruct.EmptyCellTag == 3 || moveDetailStruct.ButtonClickedTag == 3 && moveDetailStruct.EmptyCellTag == 2)
            {
                return(false);
            }

            if (moveDetailStruct.ButtonClickedTag == 5 && moveDetailStruct.EmptyCellTag == 6 || moveDetailStruct.ButtonClickedTag == 6 && moveDetailStruct.EmptyCellTag == 5)
            {
                return(false);
            }

            if (Math.Abs(moveDetailStruct.EmptyCellTag - moveDetailStruct.ButtonClickedTag) == 3 || Math.Abs(moveDetailStruct.EmptyCellTag - moveDetailStruct.ButtonClickedTag) == 1)
            {
                return(true);
            }

            return(false);
        }
コード例 #4
0
        internal void AddToUndoStack(MoveDetailStruct moveDetailStruct)
        {
            string code = moveDetailStruct.ButtonClickedTag.ToString() + "," + moveDetailStruct.EmptyCellTag.ToString() + "," + moveDetailStruct.ButtonClickedContent;

            UndoStack.Push(code);
        }
コード例 #5
0
 internal void AddToUndo(MoveDetailStruct moveDetailStruct)
 {
     History.AddToUndoStack(moveDetailStruct);
 }
コード例 #6
0
 internal void UpdateArray(MoveDetailStruct moveDetailStruct)
 {
     ArrayOfRandomIntegers[moveDetailStruct.EmptyCellTag]     = int.Parse(moveDetailStruct.ButtonClickedContent);
     ArrayOfRandomIntegers[moveDetailStruct.ButtonClickedTag] = 0;
 }