コード例 #1
0
        public void GetMementoShouldReturnDifferentInstanceOfMatrix()
        {
            var memory = new FieldMemory(filledMatrix);
            var savedMatrix = memory.GetMemento();

            Assert.AreNotSame(filledMatrix, savedMatrix);
        }
コード例 #2
0
        /// <summary>
        /// Method which manages saving field.
        /// </summary>
        /// <param name="gameField">The field to be saved.</param>
        public void Save(IMemorable gameField)
        {
            if (ObjectValidator.IsGameObjectNull(gameField))
            {
                throw new ArgumentNullException(GameFieldNullErrorMessage);
            }

            this.Memory = gameField.SaveField();
        }
コード例 #3
0
        public void GetMementoShouldReturnNonEmptyMatrixWhenSuchPassed()
        {
            var memory = new FieldMemory(filledMatrix);
            var savedMatrix = memory.GetMemento();

            var expectedResult = true;
            for (int i = 0; i < savedMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < savedMatrix.GetLength(1); j++)
                {
                    if (savedMatrix[i, i] == null)
                    {
                        expectedResult = false;
                    }
                }
            }

            Assert.IsTrue(expectedResult);
        }
コード例 #4
0
        public FieldMemory SaveField()
        {
            var fieldCopy = (Balloon[,])this.fieldMatrix.Clone();
            var memento = new FieldMemory(fieldCopy);

            return memento;
        }
コード例 #5
0
 public void RestoreField(FieldMemory memento)
 {
     this.fieldMatrix = memento.GetMemento();
 }