Jump to content
  • Advertisement
Sign in to follow this  
Rozik

turns of a game

This topic is 4865 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 everyone:) i am kinda new to gameprogramming and all i did so far was a asteroids clone and another little game. Now i was thinking about starting something bigger. I was planing on doing something chess-like. But i am kinda confused with the game loop and how it would work to have Turns of a player and the AI. If i would pause the loop or how it would be done. Before i had menus in the games for which i used variables called Gamestate, where 1 would be the menu and 2 would be the game itself. I was wondering if someone would have any hints for me or point me somewhere where i could read up on this:) thx a lot Rozik

Share this post


Link to post
Share on other sites
Advertisement
Oh boy, this is gonna be fun. But first I must ask: Are you using a class for you game? Are you using any OOP at all?
What programming language are you using?

Share this post


Link to post
Share on other sites
i am using c++
for one of the two games i made i used no classes cause it was so simple,
for the other one i used a class to load bitmaps and one for the graphic attributs i.e. xloc, yloc, speed ect.

i timed the game loop to a framerate of 30fps and used a global variable to determin in wich state of the game i am in i.e. Gamestate=1 for being at the start menu

Share this post


Link to post
Share on other sites
A simple way of implementing the turns is to have a currentTurn and assign 1 as the players turn and -1 as the AI's turn then change by multiplying by -1.

Share this post


Link to post
Share on other sites
First of all, I recommend reading "Game Coding Complete" by Mike McShaffry. It will give you a lot of good ideas about how to design and organize game code. I'm sure there are other good books out there on the topic, but it is by far the best one I've read.

Secondly, DO NOT pause the main game loop while you are waiting for the user to make his/her move. The main game loop should run continuously, and should only be stopped if game looses focus to another application. Depending on how you do it, pausing the loop might work to a limited extent, but you'll find yourself having to work around it a lot.

Generally, your main game loop should do a number of things: process user input, execute game logic, manage and update the display graphics, and render the display to the screen. All these functions should be driven by the current state of the game. One good way to handle this is to define an abstract class exposes these functions, and then have concrete classes that implement those functions for a given state. So, for instance, you might have one class for the menu screen, and another for the play screen, both which implement the same base class. When switching into another state, you can swap out your menu object with an instance of your play screen class. This way, all your main loop's logic can change on the fly.

This is a very simplified explaination. The book goes into much more detail than what I've described here, but this should help point you in the right direction. You can also search these boards, as I know this kind of topic comes up often.

Share this post


Link to post
Share on other sites
Quote:
Original post by nimrand
First of all, I recommend reading "Game Coding Complete" by Mike McShaffry. It will give you a lot of good ideas about how to design and organize game code. I'm sure there are other good books out there on the topic, but it is by far the best one I've read.




is "Game Coding Complete Second edition" just as good?

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!