Exemple #1
0
        private static void DrawBoard(bool mock = false)
        {
            battleBoard   = game.GetBattleBoard();
            personalBoard = game.GetPersonalBoard();

            if (personalBoard == null)
            {
                personalBoard = new ShipCell[1, 1];
            }

            int height = battleBoard.GetUpperBound(0) + 1;
            int width  = battleBoard.GetUpperBound(1) + 1;

            Console.Write(LINE_INDENT + "  ");
            for (int colIndex = 0; colIndex < width; colIndex++)
            {
                Console.Write($" {(char)('A' + colIndex)}  ");
            }
            Console.Write(LINE_INDENT + "  ");
            for (int colIndex = 0; colIndex < width; colIndex++)
            {
                Console.Write($" {(char)('A' + colIndex)}  ");
            }
            Console.WriteLine();
            Console.Write(LINE_INDENT + " " + CROSS_POINT);
            firstCellRow = Console.CursorTop + 1;
            firstCellCol = Console.CursorLeft + ROW_SEP.Length / 2;
            for (int colIndex = 0; colIndex < width; colIndex++)
            {
                Console.Write(ROW_SEP + CROSS_POINT);
            }
            lastCellCol = Console.CursorLeft - ROW_SEP.Length / 2 - 2;
            Console.Write(LINE_INDENT + " " + CROSS_POINT);
            for (int colIndex = 0; colIndex < width; colIndex++)
            {
                Console.Write(ROW_SEP + CROSS_POINT);
            }
            Console.WriteLine();
            for (int rowIndex = 0; rowIndex < height; rowIndex++)
            {
                for (int colIndex = 0; colIndex < LINE_INDENT.Length - $"{rowIndex + 1}".Length + 1; colIndex++)
                {
                    Console.Write(LINE_INDENT[0]);
                }
                Console.Write($"{rowIndex + 1}{COL_SEP}");
                for (int colIndex = 0; colIndex < width; colIndex++)
                {
                    Console.Write($" {(mock ? MOCK_CHAR : CellString(battleBoard[rowIndex, colIndex]))} {COL_SEP}");
                }
                for (int colIndex = 0; colIndex < LINE_INDENT.Length - $"{rowIndex + 1}".Length + 1; colIndex++)
                {
                    Console.Write(LINE_INDENT[0]);
                }
                Console.Write($"{rowIndex + 1}{COL_SEP}");
                for (int colIndex = 0; colIndex < width; colIndex++)
                {
                    Console.Write($" {(mock ? MOCK_CHAR : CellString(personalBoard[rowIndex, colIndex]?.State ?? new ShipCell().State))} {COL_SEP}");
                }
                Console.WriteLine();
                Console.Write(LINE_INDENT + " " + CROSS_POINT);
                for (int colIndex = 0; colIndex < width; colIndex++)
                {
                    Console.Write(ROW_SEP + CROSS_POINT);
                }
                Console.Write(LINE_INDENT + " " + CROSS_POINT);
                for (int colIndex = 0; colIndex < width; colIndex++)
                {
                    Console.Write(ROW_SEP + CROSS_POINT);
                }
                Console.WriteLine();
            }
            lastCellRow = Console.CursorTop - 2;
        }