Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Tic-Tac-Toe

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 vsg1990   Members   

252
Like
0Likes
Like

Posted 17 September 2012 - 10:27 PM

Hi,

I've been reading these forums for a while. This is my first post. I've been learning DirectX for a while and understand enough code to fill a window with a quad and color it. However, its getting very complicated very fast and I feel like I don't know enough about 'organizing' code to write a game with DirectX. So I decided to write a game with C++ in the console. Someone suggested Tic-Tac-Toe, so I decided to give it a whirl. I would like as many opinions as I can get about optimizing/organizing this code. You can be very critical, it won't hurt my feelings. Posted Image

http://pastebin.com/c2puhfFy - main.cpp
http://pastebin.com/bxQP7sB2 - main.h
http://pastebin.com/2bn6LxaL - board.cpp
http://pastebin.com/mbsKZhYE - board.h

Thanks,
Vince

Attached Files



#2 SimLabDevelopments   Members   

205
Like
0Likes
Like

Posted 18 September 2012 - 08:23 AM

A few things to look into...

A board could be represented as arrays--perhaps a row array, and then a board is a collection of rows.

Read into object oriented design.

#3 StaticPoof   Members   

283
Like
0Likes
Like

Posted 18 September 2012 - 12:51 PM

Your code is kinda lengthy for what your trying to do. It might be easier to organize if you condense it a bit. I'd suggest making a node class with the status of the tile (blank, X, or O) as a variable, and then made an 3x3 array made up of those nodes. Also to make checking if someone won easier I'd make 8 different empty strings that represented each of the 8 possible win combinations and a count variable. Whenever a player makes a move, just append it to the corresponding string (for example if a move is made in the top left corner by player one place an X in the topRow, leftColumn, and leftDiagonal strings. The order is unimportant since 3 same characters in the string means a victory) and check them for a winning combination (you really only have to start checking on the 5th move since that's when the first player is able to have 3 moves on the board, hence the count variable). After that it's as simple as waiting for someone to make a winning move.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.