Jump to content
  • Advertisement
Sign in to follow this  

OOP approach to connect 4

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

Hi, So I've finished programming a simple tic tac toe game using C++ and SDL, so I decided to make another harder board game before I do something that's more animated. So far my main problem is that I often feel like what I am doing is "hackey" workarounds to get some of the parts working. Here's my basic setup: Main (here is where the game loop lets the player take a turn, and where the cpu's turn is called) GameBoard (right now the board handles managing the 2D array of pieces, the game board also handles the rendering of the board within the class, I put in a drawBoard() function. The board has four SDL surface objects (redpeg,background,blackpeg, and message), is it poor design to use several SDL_Surfaces, I mean in a more complicated game would you instead do image swapping out of a vector of surfaces or something?) CPU Player (right now this does nothing, but I intend to call the cpus turn from main and pass it a reference to the board. In here it will scan the board for the players potential connect 4's in order to block them, and if there are none it will try and drop a peg in order to increase it's longest connection chain). I also don't really like my algorithms for checking for a win, but I can't think of a better way. Right now I scan the last peg that is dropped for horizontal wins, vertical wins, diagonal top to bottom wins, and diagonal bottom to top wins). I considered having some sort of vector of pegChain objects but couldn't figure out how that would work without even more calculations than the just doing the scans. Does anyone have suggestions on how I should split up and organize a game of connect 4. I'm unclear about where rendering should be in games, in this game the only thing that needs to be rendered is the board, but if for example I had a game with multiple characters and backgrounds would you have the rendering in the character objects themself, or somewhere else?

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!