public void ShouldThrowArgumentException_SetInvalidMatrixSize()
 {
     try
     {
         PuzzleField testField = new PuzzleField(-1);
     }
     catch (ArgumentException ex)
     {
         Assert.AreEqual("The matrix size must be a positive integer", ex.Message);
         throw;
     }
 }
 public void ShouldBeEqual_FillPuzzleBodyMethodTest()
 {
     PuzzleField testField = new PuzzleField(3);
     List<Cell> expectedBody=new List<Cell>();
     Cell firstCell=new Cell();
     firstCell.Content = 1;
     firstCell.Row = 0;
     firstCell.Col = 0;
     Cell secondCell=new Cell();
     secondCell.Content = 2;
     secondCell.Row = 0;
     secondCell.Col = 1;
     Cell thirdCell=new Cell();
     thirdCell.Content = 3;
     thirdCell.Row = 0;
     thirdCell.Col = 2;
     Cell fourthCell=new Cell();
     fourthCell.Content = 4;
     fourthCell.Row = 1;
     fourthCell.Col = 0;
     Cell fifthCell=new Cell();
     fifthCell.Content = 5;
     fifthCell.Row = 1;
     fifthCell.Col = 1;
     Cell sixthCell=new Cell();
     sixthCell.Content = 6;
     sixthCell.Row = 1;
     sixthCell.Col = 2;
     Cell seventhCell=new Cell();
     seventhCell.Content = 7;
     seventhCell.Row = 2;
     seventhCell.Col = 0;
     Cell eigthCell=new Cell();
     eigthCell.Content = 8;
     eigthCell.Row = 2;
     eigthCell.Col = 1;
     Cell ninthCell=new Cell();
     ninthCell.Content = 0;
     ninthCell.Row = 2;
     ninthCell.Col = 2;
     expectedBody.Add(firstCell);
     expectedBody.Add(secondCell);
     expectedBody.Add(thirdCell);
     expectedBody.Add(fourthCell);
     expectedBody.Add(fifthCell);
     expectedBody.Add(sixthCell);
     expectedBody.Add(seventhCell);
     expectedBody.Add(eigthCell);
     expectedBody.Add(ninthCell);
     Assert.AreEqual(expectedBody[6].Content, testField.Body[6].Content);
 }
        /// <summary>
        /// This method render the game field in console.
        /// </summary>
        /// <param name="puzzleField">Array containing field values.</param>
        public static void PrintTheGameField(PuzzleField puzzleField)
        {
            Console.WriteLine(" -------------");

            for (int row = 0; row < puzzleField.MatrixSize; row++)
            {
                Console.Write("| ");

                for (int col = 0; col < puzzleField.MatrixSize; col++)
                {
                    int currentCelNumber = (puzzleField.MatrixSize * row) + col;
                    puzzleField.Body[currentCelNumber].Print();
                }

                Console.WriteLine("|");
            }

            Console.WriteLine(" -------------");
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method make a single instance of PuzzleField.
        /// </summary>
        /// <param name="size">The size of PuzzleField.</param>
        /// <returns>Returns single instance of PuzzleField.</returns>
        public static PuzzleField GetInstance(int size)  // implementation of Singleton design pattern
        {
            if (instance == null)
            {
                lock (mutex) // lock the object because of possible two threads requests
                {
                    if (instance == null)
                    {
                        instance = new PuzzleField(size);
                    }
                }
            }

            return instance;
        }
 /// <summary>
 /// Constructor of PuzzleFieldManager.
 /// </summary>
 /// <param name="field">The Current PuzzleField for manage.</param>
 public PuzzleFieldManager(PuzzleField field)
 {
     this.Field = field;
 }