Пример #1
0
        /// <summary>
        /// Restore previously state of PlayField.Instance
        /// </summary>
        /// <param name="memento"></param>
        public void LoadMemento(MementoField memento)
        {
            if (memento == null)
            {
                throw new ArgumentNullException("Error: loaded memento object cannot be null!");
            }

            this.cells = this.CloneToMultiDimArray(memento.ZeroBasedPlayField, memento.FieldDimension);
        }
Пример #2
0
        public void SaveMethodCannotReturnMementoWithNullZeroBaseArray()
        {
            Playfield testField = Playfield.Instance;

            testField.SetFieldSize(5);
            testField.InitializeEmptyField();
            testField.PlaceMines();

            MementoField memento = new MementoField();

            memento = testField.SaveMemento();

            Assert.IsNotNull(memento.ZeroBasedPlayField, "Zero-based playfield backup cannot be null");
        }
Пример #3
0
        /// <summary>
        /// Returns MementoField instance that keeps the current state of the Playfield.Instance
        /// </summary>
        /// <returns></returns>
        public MementoField SaveMemento()
        {
            if (cells == null)
            {
                throw new ArgumentNullException("Error: playfiled array cannot be null (not initialized)");
            }

            MementoField memento = new MementoField();

            memento.ZeroBasedPlayField = CloneToZeroBasedArray(this.cells as Cell[, ]);

            memento.FieldDimension = this.PlayfieldSize;

            return(memento);
        }
Пример #4
0
        public void FieldDimensionsSetterThrowExeptionIfArgsIsOutOfRange()
        {
            MementoField mementoField = new MementoField();

            mementoField.FieldDimension = 11;
        }
Пример #5
0
        public void ZeroBasedPlayfieldThrowsExecptionIfSetterAcceptNull()
        {
            MementoField mementoField = new MementoField();

            mementoField.ZeroBasedPlayField = null;
        }
Пример #6
0
        /// <summary>
        /// Returns MementoField instance that keeps the current state of the Playfield.Instance
        /// </summary>
        /// <returns></returns>
        public MementoField SaveMemento()
        {
            if (cells == null)
            {
                throw new ArgumentNullException("Error: playfiled array cannot be null (not initialized)");
            }

            MementoField memento = new MementoField();

            memento.ZeroBasedPlayField = CloneToZeroBasedArray(this.cells as Cell[,]);

            memento.FieldDimension = this.PlayfieldSize;

            return memento;
        }
Пример #7
0
        /// <summary>
        /// Restore previously state of PlayField.Instance 
        /// </summary>
        /// <param name="memento"></param>
        public void LoadMemento(MementoField memento)
        {
            if (memento == null)
            {
                throw new ArgumentNullException("Error: loaded memento object cannot be null!");
            }

            this.cells = this.CloneToMultiDimArray(memento.ZeroBasedPlayField, memento.FieldDimension);
        }