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.
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.
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: