dimanche 12 janvier 2020

Am I passing parameters on properly here?

I'm making a super simple Tic-Tac-Toe game for class. In order to determine whether or not to put an 'X' or an 'O' on a part of an array, I established an int called "turn" to determine which of the 2 players is currently playing.

int main()
{
bool win, tie = false;
int input;
char theBoard[LENGTH] = {SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE};
int turn = 1;

showInstructions();

do
{
showBoard(theBoard);
getMove(turn, input, theBoard);
if (turn == 1)
{
    turn++;
}
else if (turn == 2)
{
    turn--;
}
}
while(win == false || tie == false);
return 0;

and here's my function for getMove.

void getMove(int input, int turn, char theBoard[LENGTH])
{
    cout << "Pick a space from 0 - 8" << endl;
    cin >> input;
    if (input >= 0 && input <= 8)
    {
        if (turn == 1)
        {
        theBoard[input] = X;
        }
    else if (turn == 2)
        {
        theBoard[input] = O;
        }
    }
    else
    {
        cout << "Please make a valid move between 0 - 8" << endl;
        cin.ignore();
        cin.get();
    }
 }

Aucun commentaire:

Enregistrer un commentaire