C++ OOP Programming

Jul 28, 2011 at 9:21am
I need help on a tic tac toe game. I am trying to figure out how to switch between player one and player two each turn.
1
2
3
4
5
6
7
8
9
char playerMark;
    // Switch After Each Move
    char playerOne;
    for (int i = 1; i < 3; i++) {
        if (i == 1) 
            playerMark = 'x';
        else
            playerMark = 'o';
    }


From that code i can get it to switch from x and o, and i was thinking about looping it another 4 times but that does not work.

My other attempt to first just loop my the getmove function 9 times and each time there will be either an odd or even number. When theres an even number the player's number will turn into an X and when theres an odd it will turn into an O. Then i have to figure out how to get it to correspond with the number on the tic tac toe chart i made. My main problem is figuring how to switch players each turn. Any hint will appreciated. Thank You

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void Tictac::getMove()
{
	cout << "Enter Box: ";
	char c;
	cin.get(c);
	if (c > '9' || c < '0')
    {
		// Error message here.
        cout << "please enter a number between 1-9";
        cin.get(c);
    }
        
        int number = c - '0';
    
	cout << "your number is " << isnumber;
	// Your implementation here...
    char playermark;
    int playerNumber;
    int i = 2;
    i = i % 2;
    if (i == 0) 
    {
        playermark = 'x';
        playerNumber = 1;
    }
    
    else{
        playermark = 'o';
        playerNumber = 1;
    }
    
    i++;
    
    
}


Then loop ttt.playgame 9 times
1
2
3
4
5
6
7
int main ()
{
	TicTacToe ttt;
    
	// you need to do the following in a loop 9 times
	ttt.playGame();
}

Last edited on Jul 28, 2011 at 10:17am
Jul 28, 2011 at 2:15pm
I guess they want you to pass in something to the getMove() routine. Perhaps:

1
2
3
4
5
6
7
8
9
10
11
12

int main()
    {
    TicTacToe ttt;

    for( int i = 0; i < 9; i++ )
        {
        ttt.playGame( i );

        }    /*    for( i < 9 )    */

Topic archived. No new replies allowed.