简体   繁体   中英

Tic-Tac-Toe game weird symbol

I'm doing now a TTT game. but whenever I try to print the board I get something like this: https://gyazo.com/b080017e24acd68972ab4913e9cd2548

My question is what are those weird symbols and how to get rid of them

void TicTacToeGame::printBoard()
{
    cout << "\n";
    cout << "|1 2 3| \n";
    for (int i = 0; i < 3; i++)
    {
        cout << "------\n";
        cout << i+1 << "|" << board[i][0] << "|" << board[i][1] << "|" << board[i][2] << "|\n";
    }
    cout << "------\n";
}

edit: I init here:

void TicTacToeGame::playGame()
{
    char player1 = 'X';
    char player2 = 'O';
    char currentPlayer = 'X';

    bool isDone = false;

    int x, y;

    while (isDone == false)
    {
        printBoard();

        x = getXCoord();
        y = getYCoord();

        if (placeMarker(x, y, currentPlayer) == false)
        {
            cout << "can't place it here!\n";
        }
        else
        {
            changePlayers(currentPlayer, player1, player2);
        }
    }
}

edit2:

Has been fixed thank you for the help!

Those 'weird symbols' are unicode characters. After declaring your board, the char values are just random symbols, what else should the board elements contain?

You have to initialize your board like this:
Either on declaration:

char board[3][3] = {
    {' ',' ',' '},
    {' ',' ',' '},
    {' ',' ',' '}
};

Or in the constructor/some initialization method:

board = {
    {' ',' ',' '},
    {' ',' ',' '},
    {' ',' ',' '}
};

Now your board should consist of spaces only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM