Jump to content

  • Log In with Google      Sign In   
  • Create Account

Handling Turns in a Turn-Based Game


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
6 replies to this topic

#1 ka0tix   Members   -  Reputation: 126

Like
0Likes
Like

Posted 08 February 2013 - 04:45 PM

A friend and I are making a turn based game, but I'm not entirely sure how to handle the turn system.

 

Basically we want to:

-Start the turn which opens a menu

-Allow the user to go through menus, buy things, sell things, etc.

-End turn

 

And I would like to be able to do this for multiple users. Any tips? Also, I searched for a topic like this one but couldn't find it, so if there is one please link it.



Sponsor:

#2 Khatharr   Crossbones+   -  Reputation: 3038

Like
0Likes
Like

Posted 08 February 2013 - 08:48 PM

Well...

 

What do you have so far and where/why are you stuck?


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#3 ka0tix   Members   -  Reputation: 126

Like
0Likes
Like

Posted 08 February 2013 - 09:36 PM

Haven't made any progress so far. I'm not looking for actual code, just some ideas on how to structure the code.

 

So far, all I've really got is that it would make sense to write a function + helper functions which handle the actions. But I've never written anything like this, so I'm not sure exactly how or where to handle the actual turns. Should they be handled directly in the main loop, or should I deliberate the turns to a separate function?

 

I'm not too sure what to do here, so sorry if I seem a bit incoherent.



#4 warnexus   Prime Members   -  Reputation: 1502

Like
1Likes
Like

Posted 08 February 2013 - 10:58 PM

Haven't made any progress so far. I'm not looking for actual code, just some ideas on how to structure the code.

 

So far, all I've really got is that it would make sense to write a function + helper functions which handle the actions. But I've never written anything like this, so I'm not sure exactly how or where to handle the actual turns. Should they be handled directly in the main loop, or should I deliberate the turns to a separate function?

 

I'm not too sure what to do here, so sorry if I seem a bit incoherent.

I think you should implement it. It will enrich your knowledge. What you do not know will hurt you. In fact, struggle with it and we can better help you if you show us what you have done. There is no one-way ticket to do things. It's programming! There are many ways you can implement it!



#5 bubbaray97   Members   -  Reputation: 217

Like
0Likes
Like

Posted 09 February 2013 - 02:30 PM

I think you should implement it. It will enrich your knowledge. What you do not know will hurt you. In fact, struggle with it and we can better help you if you show us what you have done. There is no one-way ticket to do things. It's programming! There are many ways you can implement it!

 

I agree with warnexus.    I'm also building a turn based game and my first design was lets just say less than ideal.   But I learned a ton about how I really wanted my game to work.    Chances are at the stage it sounds like you are in your going to end up changing a few times away.

 

My recommendation would be to just map out what you want a player to be able to do on their turn.   Then build out those functions.    when you get to the point of advancing the turn chances are a few options will present themselves.

 

Maybe not the "best way" to go about design, but certainly one that will make you learn.    Plus as warnexus pointed out, once you actually have somethign going it will be easier for folks here to give "real" advice on direction.    Also I've found (as a hobby developer) if I spend too much time designing and not coding...its easy to get sidetracked with everything else in my life and not advance my project while I wait for "THE design"



#6 JTippetts   Moderators   -  Reputation: 8649

Like
0Likes
Like

Posted 09 February 2013 - 04:49 PM

Here is how the game logic is structured in Goblinson Crusoe. It isn't exactly what you are looking for, but it might give you some things to think about.

 

1) At the beginning of the round, check to see if our turn-list is empty. If it is empty, pump out a request to all combat objects. The request is for a packet of information including:

a) Are you alive?

b) Are you interested in participating this round?

c) What is your faction?

 

2) Iterate the list returned from the request above. Check to see if there is at least one player-controlled object in the list. If not, it indicates a loss condition. Then, iterate and see if there is at least one hostile enemy combatant in the list. If not, it indicates a victory condition. Otherwise, continue.

 

3) Initiative determination. Compile a list of all participating combatants and, based on haste modifiers, roll for initiative. Insert them into a list sorted by order of their initiative rolls, re-rolling to break any ties as needed.

 

4) Check to see if we have a currently active object. If we don't, pull the next object off the turn list compiled above.

 

5) (If we have a new combatant)  Send the combatant a BeginCombatTurn message. This message in effect passes a "token" to the object, indicating that the object is free to move. If it is an AI controlled object, this pulls the AI out of its Wait state and into an Active state. If it is a player object, this passes a message to any linked UI components telling them to activate and show themselves. These UI components are "owned" by the object; that is, each player object has an instance of PlayerUI that is customized to their own individual settings and characteristics. (Siege machinery has a different UI than the player character, etc...) During BeginCombatTurn, the number of movement points to be allocated to the object is passed.

 

6) (If we already have an active combatant) Pass a CombatUpdate message. For Player objects, this merely checks to see if there is anything in the Command Queue for that object (list of steps to take, attacks to make, etc....) whereas for AI objects it checks to see if the command queue is empty and, if so, calls Think() on the AI controller. Think() will evaluate the current situation based on certain criteria, and attempt to come up with a reasonable set of commands to place in the queue.

 

7) While an object has movement points and chooses not to Pass, call CombatUpdate.

 

8) For Player characters, the UI is used to gather input and generate commands for the command queue. Any input action done while an object's UI is active is screened and tested for validity, then used to push commands onto the queue. UI generates a Move command? Call the pathfinder, validate the path, and push the steps onto the queue.

 

9) CombatUpdate checks the command queue, as indicated, and if there are pending actions it will pull an action off the queue and execute it. If it is a movement command, then TakeStep is called on the combatant controller to move the unit in the given direction. If it is a spell-cast command, then another sequence of steps are executed.

 

10) When CombatUpdate is called and the queue is empty, and the controller either elects to Pass or hasn't enough movement points to do anything, then the object will de-activate itself so that when, at step 4 above, we check to see if we have an active object, the answer will now be false and the scheduler will move on to the next object. At this point, pass the object an EndCombatTurn message. This de-activates any UI (for player objects) and places any AI controllers in a suspend state.

 

All of this continues in progression until step 2 indicates a victory/loss condition.

 

Basically, at heart, it's just a token-passing system. Pass the "Active" token to each object in turn, and when they are done with it hand it on down the line. Exactly how you structure this, though, is really dependent upon your game.


Edited by JTippetts, 09 February 2013 - 04:51 PM.


#7 ka0tix   Members   -  Reputation: 126

Like
0Likes
Like

Posted 09 February 2013 - 05:00 PM

Also I've found (as a hobby developer) if I spend too much time designing and not coding...its easy to get sidetracked with everything else in my life and not advance my project while I wait for "THE design"

 

Fortunately, the game is basically designed. It's nothing too complex, so we're pretty fortunate on that. Thanks for the advice, though. That's actually how I've begun to proceed.

 

Basically, at heart, it's just a token-passing system. Pass the "Active" token to each object in turn, and when they are done with it hand it on down the line. Exactly how you structure this, though, is really dependent upon your game.

 

Awesome, thank you! It's not exactly what I need for the type of game I'm making, but that definitely gives me a few ideas. I'll update later.






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.



PARTNERS