コード例 #1
0
        public void TestBoardToString2()
        {
            Board board = new Board(1, 1, 1);
            StringBuilder expected = new StringBuilder();
            expected.Append("    0 \n");
            expected.Append("   ___\n");
            expected.Append("0 | ? |\n");
            expected.Append("   ___\n");

            Assert.AreEqual(expected.ToString(), board.ToString(), "Board string is wrong!");
        }
コード例 #2
0
        public void TestBoardToString1()
        {
            Board board = new Board(5, 10, 10);
            StringBuilder expected = new StringBuilder();
            expected.Append("    0 1 2 3 4 5 6 7 8 9 \n");
            expected.Append("   _____________________\n");
            expected.Append("0 | ? ? ? ? ? ? ? ? ? ? |\n");
            expected.Append("1 | ? ? ? ? ? ? ? ? ? ? |\n");
            expected.Append("2 | ? ? ? ? ? ? ? ? ? ? |\n");
            expected.Append("3 | ? ? ? ? ? ? ? ? ? ? |\n");
            expected.Append("4 | ? ? ? ? ? ? ? ? ? ? |\n");
            expected.Append("   _____________________\n");

            Assert.AreEqual(expected.ToString(), board.ToString(), "Board string is wrong!");
        }
コード例 #3
0
        public void TestBoardToString3()
        {
            int rows = 1;
            int columns = 1;

            Field[,] fixedFields = new Field[rows, columns];
            fixedFields[0, 0] = new Field();
            fixedFields[0, 0].Status = FieldStatus.Opened;
            fixedFields[0, 0].Value = 5;

            Board board = new Board(rows, columns, 1);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            StringBuilder str = new StringBuilder();
            str.Append("    0 \n");
            str.Append("   ___\n");
            str.Append("0 | 5 |\n");
            str.Append("   ___\n");

            string expected = str.ToString();
            string actual = board.ToString();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board string is {0}, but must be {1}!", actual, expected));
        }
コード例 #4
0
        public void TestBoardToString5()
        {
            int rows = 5;
            int columns = 10;

            Field[,] fixedFields = new Field[rows, columns];
            int counter = 1;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    fixedFields[i, j] = new Field();
                    fixedFields[i, j].Status = FieldStatus.Opened;
                    fixedFields[i, j].Value = counter;
                    counter++;
                    if (counter == 9)
                    {
                        counter = 1;
                    }
                }
            }

            Board board = new Board(rows, columns, 10);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            StringBuilder str = new StringBuilder();
            str.Append("    0 1 2 3 4 5 6 7 8 9 \n");
            str.Append("   _____________________\n");
            str.Append("0 | 1 2 3 4 5 6 7 8 1 2 |\n");
            str.Append("1 | 3 4 5 6 7 8 1 2 3 4 |\n");
            str.Append("2 | 5 6 7 8 1 2 3 4 5 6 |\n");
            str.Append("3 | 7 8 1 2 3 4 5 6 7 8 |\n");
            str.Append("4 | 1 2 3 4 5 6 7 8 1 2 |\n");
            str.Append("   _____________________\n");

            string expected = str.ToString();
            string actual = board.ToString();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board string is {0}, but must be {1}!", actual, expected));
        }
コード例 #5
0
        public void TestBoardToString4()
        {
            int rows = 5;
            int columns = 10;

            Field[,] fixedFields = new Field[rows, columns];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    fixedFields[i, j] = new Field();
                }
            }

            fixedFields[0, 0].Status = FieldStatus.Opened;
            fixedFields[0, 0].Value = 1;
            fixedFields[1, 1].Status = FieldStatus.Opened;
            fixedFields[1, 1].Value = 2;
            fixedFields[2, 2].Status = FieldStatus.Opened;
            fixedFields[2, 2].Value = 3;
            fixedFields[3, 3].Status = FieldStatus.Opened;
            fixedFields[3, 3].Value = 4;
            fixedFields[4, 4].Status = FieldStatus.Opened;
            fixedFields[4, 4].Value = 5;

            Board board = new Board(rows, columns, 10);

            Type type = typeof(Board);
            var fieldValue = type.GetField("fields", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(board, fixedFields);

            StringBuilder str = new StringBuilder();
            str.Append("    0 1 2 3 4 5 6 7 8 9 \n");
            str.Append("   _____________________\n");
            str.Append("0 | 1 ? ? ? ? ? ? ? ? ? |\n");
            str.Append("1 | ? 2 ? ? ? ? ? ? ? ? |\n");
            str.Append("2 | ? ? 3 ? ? ? ? ? ? ? |\n");
            str.Append("3 | ? ? ? 4 ? ? ? ? ? ? |\n");
            str.Append("4 | ? ? ? ? 5 ? ? ? ? ? |\n");
            str.Append("   _____________________\n");

            string expected = str.ToString();
            string actual = board.ToString();

            Assert.AreEqual(
                expected,
                actual,
                string.Format("The board string is {0}, but must be {1}!", actual, expected));
        }
コード例 #6
0
 /// <summary>
 /// Draws the game board on the console.
 /// </summary>
 /// <param name="board">The board to draw.</param>
 public void DrawBoard(Board board)
 {
     Console.Write(board.ToString());
 }