Jump to content
  • Advertisement
Sign in to follow this  
jordi_0071

C++ tic-tac-toe

This topic is 4738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey, ive made this code:
#include <iostream> // header-file for input/output
using namespace std; // standard namespace

int main()  // begin the main function
{
	cout << " ___________"  << endl;
	cout << "|   |   |   |" << endl;
	cout << "|   |   |   |" << endl;
	cout << "|___|___|___|" << endl;
	cout << "|   |   |   |" << endl;
	cout << "|   |   |   |" << endl;
	cout << "|___|___|___|" << endl;
	cout << "|   |   |   |" << endl;
	cout << "|   |   |   |" << endl;
	cout << "|___|___|___|" << endl;

	system("pause"); // pauses the program and wait for the users input.

	return 0;  // exit the progam
}


but how do i go further with this? i mean should i use arrays in the space in the board? and what else?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
isn't using OOP for tic-tac-toe a humungous overkill?

Share this post


Link to post
Share on other sites
no, using OOP for for this is not an overkill. there is noting about OOP that makes it 'heavy weight' or anything. it also is a good solution for almost all problem spaces. of course there is nothing OO in the above code.

Share this post


Link to post
Share on other sites
That isn't what he meant. I assume he meant your use of iostream, but I don't see a reason *not* to use it (except maybe personal preference).

Share this post


Link to post
Share on other sites
Quote:
Original post by mgarriss
no, using OOP for for this is not an overkill. there is noting about OOP that makes it 'heavy weight' or anything. it also is a good solution for almost all problem spaces. of course there is nothing OO in the above code.



same thing he said. there are a lot of tic tac toe games in the forums to look at to get an idea of were you can take it.

Share this post


Link to post
Share on other sites
You arn't using OOP and it isn't overkill, especially if this is a learning project which I'm guessing it is.

Your first step should be to replace your board drawng code with a function or method so you can draw the board to screen whenever you want. Then (as you suggested) use an array to hold the boards state. Allow your drawing function (or method) to have the board passed into it and draw the O, X and blanks accordingly.

Once you have that done you can go about actually coding the game :P

Share this post


Link to post
Share on other sites
Here are some directions :-

well you could use a [3][3] array to store the user input , per turn - may be initialize it to some constant value say 100.
Give each turn a different value say for user a = 10 , b = 20 ( so while
checking use these values , you could also use characters , just that i prefer intgegers ) Take the input in a while loop , after every input check if the user is winning , ie a conditional statement which if satisfied will break from the loop.
For outputting the values , there is a C function which i don't remember at the moment , but it takes 2 arguments , x and y . so you could jump there and print it. As for the selection , you could give each cell a number , so that based on the condition you pass some pre-defined co-ordinates and print the selection.

Just some ideas which came randomly [:)]

Share this post


Link to post
Share on other sites

Here are some directions :-

well you could use a [3][3] array to store the user input , per turn - may be initialize it to some constant value say 100.
Give each turn a different value say for user a = 10 , b = 20 ( so while
checking use these values , you could also use characters , just that i prefer intgegers ) Take the input in a while loop , after every input check if the user is winning , ie a conditional statement which if satisfied will break from the loop.
For outputting the values , there is a C function which i don't remember at the moment , but it takes 2 arguments , x and y . so you could jump there and print it. As for the selection , you could give each cell a number , so that based on the condition you pass some pre-defined co-ordinates and print the selection.

Just some ideas which came randomly [:)]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!