Jump to content
  • Advertisement
Sign in to follow this  
DannyW

SDL Tic-Tac-Toe: My first game - Comments?

This topic is 4078 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

Good morning! I'm about half way through Programming Linux Games and have made this Tic-Tac-Toe game with SDL. It's my first game there are no frills and it's probably badly programmed, so I'm welcoming all criticism! I'm running it on Linux, but it should compile on Windows. source (6.1KB .tar.bz2) source (8.2KB .zip) mkdir ~/somewhere cd ~/somewhere tar jxvf oxo.tar.bz2 make oxo ./oxo Thanks for your time! Danny [Edited by - DannyW on July 27, 2007 4:02:51 AM]

Share this post


Link to post
Share on other sites
Advertisement
I downloaded the program and tried to compile but the file board.cpp appeared to be a binary (containing what looks like junk). I don't know if it's my decompression (I used tar/bzip under cygwin and have had no problem in the past).
If you check it out, I'll try it again,

Dan

Share this post


Link to post
Share on other sites
Oops! Sorry! It's not your decompression, it was the same for me too... weird.

Well I remade the archive and uploaded it again, also have put a .zip there, just in case.

Thanks

Share this post


Link to post
Share on other sites
Hey, first off, nice game :). Your code is generally neat and tidy and easy to follow. Your object structure looks like you planned it before you started which is always a good plan. Your classes are also encapsulate their functioanlity well. Also it's nice to see someone using an enum from time to time ;). You're also quite careful to check operations were successful, which is a good habit to get into.

A few points I've noted, firstly... there are special literals true and false to use with bools... I noticed you using 0... A bool is what an if statement operates on... so you can do:
bool variable=true;
if (variable) do_stuff();
or
bool variable=false;
if (!variable) do_other_stuff();

Second, I was wondering why you used the PumpEvent and keystate array reading method rather than the SDL_PollEvent loop (that is suggested in the SDL docs). It is more common to use preprocessor directives to encapsulate your debugging information to avoid having to check for a debug flag at various points in your release build. If you want the end user to be able to turn on debugging though, this is ok.

If you want to swap the state of a boolean, it's easiest to go:
variable=!variable;

Your logic regarding who goes next looks a little verbose, I'm guessing you could have tightened that up somehow (I've not thought about it very hard). Your logic for finding a winner also looks a little verbose too, again, I don't have a specific suggestion, it's just a feeling. As to both of these points... Code that works should take priority over elegance. Your code is logical and correct and fulfils its purpose. Elegance is just nice :).

I know a lot of people don't like doing this... but if you have any Get/Set methods that simply return a (non-const) reference or pointer to non const data (and the datatype is fixed... like say and SDL_Rect) then it's simpler to just make the data member public. I know some people are very attached to the get/set pattern, and for providing a consistent interface to potentially variable underlying datatypes or for various consistency checks it makes sense. Other than that, it seems like semantics you can do without.

Your board drawing all seems sensible enough, though if you wanted (and this may require a slight design change) you could simply draw the element just placed instead of all of them. In practise the draw is very cheap, so it makes no real difference.

You could have also set the player's parameters in a constructor and used the initialisation list, but the way you did it is nice and clean/clear too. Also, I believe you only need to seed the random number generator once per program (this could be wrong, and I don't know the situation for multithreading either), so it'd probably make more sense to seed it in the same function you initialise SDL... also SDL_GetTicks returns the time since SDL was initialised... and it's only accurate to about 10ms... meaning you may find you get the same seed everytime you run the program. It makes somewhat more sense to use the system time (in seconds) or some such thing to ensure that (unless you run the program twice per second) you don't get the same seed.

Also, it'd make sense to simply pass the click events to the player from the game object rather than have that code embeded in the player... another option is to make it the responsibility of the board. It's a design decision you had to make one way or other... and as I said before, working should be top priority... and it does.

As I hope you can tell from my comments... I think the game is fairly well put together with only a few minor points... and some contentious issues. Anyway, once again, good work.
Good luck for your future game programming endeavours!

Dan

Share this post


Link to post
Share on other sites
Thank you very much Dan!

This is just the sort of thing I wanted to hear. It great to get some good feedback! You just can't get it out of a book.

Thanks again,
Danny

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!