Confused

Hello, I'm learning c++ now, and now I have homework to make a game of tic tac toe. But unfortunately i confused how to make source code from this game.Can you teach me the step to make source code this game ? But i will use #inclue<stdio.h> and #include <conio.h> in header .. Thank you
Start with describing the game.
For example tic-tac-toe is:
- a turn based game
- for 2 players
- has a "board" with 9 positions
- each position on the board can be either unused, belong to player 1 or belong to player 2
<there are more to add here>

Then you start thinking about how you will program this, starting with the most important things. In this case that will probably turn out to be the board. So you decide how you are going to represent the board first and probably how to represent a player in your game will be next.

When you have decided on this you start to look at interaction. A player has to be able to do something. What should they do and how do you want them to do this.
In this case the player has to select a position on the board. You could number each position, you could have your player enter coordinates like on a map (1,1) or like a chess board (a,2).
When you have decided on this, you have to make your program accept the user input and update the board based on the input.

Probably you should at some point in time also check if the player entered a position that is allowed (for example not (-1, 1) or (5,10) ) and if this position is still available.

When you have processed the user input, you will probably check if the game has been ended and if it has not you should probably transfer to the other player.

Don't worry about what to include yet, you will need to include the required headers when you add the functionality.
Ok,i will try it .. thanks before

the meaning of "has a "board" with 9 positions" ?
1 | 2 | 3
----------
4 | 5 | 6
----------
7 | 8 | 9
system("cls");
printf("\n\n\tTic Tac Toe\n\n");

printf("Player 1 (X) - Player 2 (O)\n\n\n");


printf(" | | \n");
printf(" %c | %c | %c \n", square[1], square[2], square[3]);

printf("_____|_____|_____\n");
printf(" | | \n");

printf(" %c | %c | %c \n", square[4], square[5], square[6]);

printf("_____|_____|_____\n");
printf(" | | \n");

printf(" %c | %c | %c \n", square[7], square[8], square[9]);

printf(" | | \n\n");



Like that ?
Yes, seems you choose to represent your board as a char array[10].

Personally I would recommend to start at square[0], then your array only needs to contain 9 characters.
Also, don't forget to properly initialize the array.

But this is your board, so now you must figure out how player will put a mark on the board.
But how if i not use array ? its possible ?
because i have not try that
Have a look at: http://www.cplusplus.com/forum/beginner/199597/
and consider joining forces/merging the threads/posting your questions there.

If you are not allowed to use an array, you will have to come up with another kind or board representation. I recommend searching for "C++ struct example" or creating a Board class with 9 member variables. Other alternatives might be lists and vectors.

Also, I expect your next addition will be to do it without loops. For this consider recursion:
1
2
3
4
5
6
7
8
9
void processMove(representationOfTheMove, representationOfTheBoard)
{
       tempBoard = representationOfTheBoard;
       tempBoard = tempBoard->performChanges(representationOfTheMove);
       
       nextMove = getTheRepresentationOfTheNextMove();

       processMove(nextMove , tempBoard);
}
Topic archived. No new replies allowed.