Example #1
0
        public void NewTurn()
        {
            TurnTransaction turn = this.EndCurrentTurn();

            this.previousTurns.Push(turn);
            this.StartTurn(new TurnTransaction());
        }
Example #2
0
        private TurnTransaction EndCurrentTurn()
        {
            this.currentTurn.UndoQueue = this._UndoQueue;
            this.currentTurn.RedoQueue = this._RedoQueue;
            TurnTransaction turn = this.currentTurn;

            this.currentTurn = null;
            return(turn);
        }
Example #3
0
        private void StartTurn(TurnTransaction turn)
        {
            this.currentTurn = turn;
            this._UndoQueue  = turn.UndoQueue;

            // Only reset Redoqueue if we're restoring a turn that already has one, otherwise we're just undoing over turn boundaries
            if (turn.RedoQueue.Count > 0)
            {
                this._RedoQueue = turn.RedoQueue;
            }
        }
Example #4
0
        public void BackupOneTurn()
        {
            if (this.previousTurns.Count > 0)
            {
                while (this._UndoQueue.Count > 0)
                {
                    ICommand command = _UndoQueue.Pop();
                    command.Undo();
                    this._RedoQueue.Push(command);
                }

                TurnTransaction turn = this.EndCurrentTurn();
                this.futureTurns.Push(turn);
                this.StartTurn(this.previousTurns.Pop());
            }
        }
Example #5
0
        public void ForwardOneTurn()
        {
            Debug.Assert(this.HasFutureTurns);
            while (this._RedoQueue.Count > 0)
            {
                ICommand command = _RedoQueue.Pop();
                command.Do();
                this._UndoQueue.Push(command);
            }

            this.EndCurrentTurn();
            TurnTransaction turn = this.futureTurns.Pop();

            this.StartTurn(turn);
            while (this._RedoQueue.Count > 0)
            {
                ICommand command = this._RedoQueue.Pop();
                command.Do();
                this._UndoQueue.Push(command);
            }
        }