Esempio n. 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);
        }
Esempio n. 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");
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public void FieldDimensionsSetterThrowExeptionIfArgsIsOutOfRange()
        {
            MementoField mementoField = new MementoField();

            mementoField.FieldDimension = 11;
        }
Esempio n. 5
0
        public void ZeroBasedPlayfieldThrowsExecptionIfSetterAcceptNull()
        {
            MementoField mementoField = new MementoField();

            mementoField.ZeroBasedPlayField = null;
        }
Esempio n. 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;
        }
Esempio n. 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);
        }