Advertisement

Tic-Tac-Toe: what techniques can I use??

Started by April 08, 2000 04:55 PM
4 comments, last by Tako 24 years, 8 months ago
Hey all, I just started programming a couple weeks ago. I''m reading through Beggining C++ by Ivor Horton and halfway through C primer plus by the waite group. I started doing a tic tac toe game(my first game) in DOS but i realized it was quite long doing it with if-else statements and writing a cout of the layout for every move. I was just wondering if theres a different way of doing this. If there isn''t I''ll just do it with the if''s. Thx for your time - Tako
You may beable to use switch() and case but it depends on how you are making your game
Advertisement
The way I created a tic-tac-toe game was to create a multidimensional array, like this

int boxes[3][3];

and each place holds a number, where 0=black, 1=circle, 2=cross. It makes it a bit easier to check for lines and draw the board.

Hope that helps.

- Daniel


my homepage
- DanielMy homepage
I'm planning to write an article here on GameDev.net about how to make a Tic-Tac-Toe game, but not in DOS, in C++ and DirectX.

/Pelle


Edited by - Plutt on 4/9/00 6:19:09 AM

Edited by - Plutt on 4/9/00 6:19:31 AM
OoMMMoO: using the switch would be basically the same as if-else. I see how you could do it but it wouldn''t save me alot of time.

deakin: that seems like a good way of doing it. Although I''m not sure how to use arrays that way yet, I can see how that would work. I''ll read about it and give it a shot. Thx

and Plutt: I think it''s a good idea to write on article on that but it would be better for DOS(in C++), ''cause i think most people that know directX know how to do a tic tac toe game. It would be alot more helpful for people like me who want to start making games but don''t know where to start.
You might want to do it object oriented style. Create a class called box and give it a variable called state. Use state to tell what should be drawn in the square(0=empty, 1=o, 2=x). Then use the variable state to test whether someboddy got 3 in a row. I don''t see any real advantadges to using classes in tic-tac-toe but it would be good practice.

Visit http://members.xoom.com/ivanickgames
Visit http://members.xoom.com/ivanickgames

This topic is closed to new replies.

Advertisement