コード例 #1
0
        // Discard redo stack if item is added to move history
        public void AddItem(HistoryItem newItem)
        {
            Future = new Stack <HistoryItem>();

            Past.Push(newItem);
            CurrItem = Past.Peek();
        }
コード例 #2
0
        public void Undo()
        {
            int currTurn   = CurrItem.Turn;
            int targetTurn = currTurn - 2;

            while (Past.Count > 0 && currTurn != targetTurn)
            {
                Future.Push(Past.Pop());

                if (Past.Count <= 0)
                {
                    currTurn = 1;
                }
                else
                {
                    CurrItem = Past.Peek();
                    currTurn = CurrItem.Turn;
                }
            }

            // check if can revert
            //if (Past.Count > 2)
            //{
            //    Future.Push(Past.Pop());
            //    Future.Push(Past.Pop());

            //    CurrItem = Past.Peek();
            //}
        }
コード例 #3
0
        public void Redo()
        {
            int currTurn   = CurrItem.Turn;
            int targetTurn = currTurn + 2;

            while (Future.Count > 0 && currTurn != targetTurn)
            {
                Past.Push(Future.Pop());

                CurrItem = Past.Peek();
                currTurn = CurrItem.Turn;
            }

            // check if can redo
            //if (Future.Count > 1)
            //{
            //    Past.Push(Future.Pop());
            //    Past.Push(Future.Pop());

            //    CurrItem = Past.Peek();
            //}
        }