光标在控制台应用程序中覆盖文本

时间:2017-01-02 16:31:45

标签: c#

您好我正在构建一个ascii版本的TicTacToe作为一个类asigment,我遇到了一个问题。光标会对电路板和标志进行处理。

 while (pressed == false)
        {
            ConsoleKeyInfo cki;

            cki = Console.ReadKey();
            switch (cki.Key)
            {
                case ConsoleKey.RightArrow:
                    if(sides+1>Console.WindowWidth)
                        break;
                    if(sides+1==17||sides+1==8)
                    sides+=2;
                else
                    sides += 1;
                    Console.SetCursorPosition(sides, ver);
                    break;
                case ConsoleKey.LeftArrow:
                    if (sides - 1 < 0)
                        break;
                    if (sides -1 == 17 || sides -1 == 8)
                        sides -= 2;
                    else
                    sides -= 1;
                    Console.SetCursorPosition(sides, ver);
                    break;
                case ConsoleKey.DownArrow:
                    if (ver + 1 > Console.WindowHeight)
                        break;
                    if (ver+1==8||ver+1==17)
                        ver += 2;
                    else
                    ver += 1;
                    Console.SetCursorPosition(sides, ver);
                    break;
                case ConsoleKey.UpArrow:
                    if (ver - 1 < 0 )
                        break;
                    if (ver - 1 == 8 || ver - 1 == 17)
                    ver-=2;
                    else
                    ver -= 1;
                    Console.SetCursorPosition(sides, ver);
                    break;
                case ConsoleKey.X:
                case ConsoleKey.O:                        
                    br.PutSign(ver,sides,ch);
                    pressed = true;
                    break;
                default:
                    break;
            }
        }
    }

我修复了光标覆盖板的问题但是我仍然无法找到保护唱歌的方法(X和O) 这是董事会的参考:

public char[,] board = new char[27, 27];

public Board()
{
    for (int i = 0; i < board.GetLength(0); i++)
    {
        for (int j = 0; j < board.GetLength(1); j++)
        {
            if (i==8||i==17)
                board[i, j] = '_';

            if (j==8||j==17)
                board[i, j] = '|';
        }
    }
}

public void PrintB()
{
    for (int i = 0; i < board.GetLength(0); i++)
    {
        for (int j = 0; j < board.GetLength(1); j++)
        {
            Console.Write(board[i, j]);
        }
        Console.WriteLine("");
    }
}
public void PutSign(int row, int col, char ch)
{
    board[row, col] = ch;
}

提前致谢 多伦

0 个答案:

没有答案