<ha*********@hotmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
>
Jim Langston wrote:
><ha*********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googleg roups.com...
>I was wondering if anyone knows how to write a tic tac toe game in c++?
Yes.
I got to do this for a final in my C++ class and to be honest i'm
completely clueless. Could you please enlighten me?
This is your final assignemtn and you're clueless? Didn't you do any of the
homework the instructor gave you? I find it hard to believe that you could
go through an entire class on c++ and not know how to do this.
Can you display a tic tac toe board in C++? Write code to just display a
tic tac toe board (without X's or O's).
Okay, now you're going to need to put in X's, O's or blanks depending on...
what? Hmm.. seems you're going to have to store the move for each square.
Lets look at a tic tac toe board:
| |
-------
| |
-------
| |
It seems to be 3 by 3. How would you store in memory 3 elements by 3
elements? There are a few ways (vector of vector, 9 variables, a 2d array).
Decide which way you want to go (for something simple like this I might
choose a simple 2d array, I.E. char Board[3][3]; Although you might want
std::vector<std::vector<char Board; You decide. There is no "right"
answer, though some may argue that a vector should always be used instead of
a static array, I'm not one of them.
Okay, now you have storage, intialize them to spaces.
Now fill in some X's and O's in your array, and get them to print out in the
board.
Okay, so there are 3 things that programs do, Input, processing and output.
So we have the output so far. Lets look at the input. Write a
class/method/function/routine to accept a players move. You decide how the
player picks a square. Common solutions are 1 thorugh 9, or 1,1 through
3,3.
But you'll need processing. Is the players move legal? Does it fall within
bounds? Is there already a move there? Did the player win?
Alternate players.
Okay, once you're done, you have a tic tac toe game.
Now you can go farther, have the player play against the computer.
Show me code, when you get stuck ask.