Search Unity

Example's

Discussion in 'Scripting' started by mpiersant, Jun 3, 2011.

  1. mpiersant

    mpiersant

    Joined:
    Aug 29, 2010
    Posts:
    14
    I have been looking for examples of how to make class in C# to handle a standard turn for turn based gaming. I haven't found anything on the net using google, but I have found several games made in unity that are turn based.

    Thanks in advance for any assistance.
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Can you be more specific? What sort of help or examples are you looking for exactly?
     
  3. mpiersant

    mpiersant

    Joined:
    Aug 29, 2010
    Posts:
    14
    Like it says in the first sentence: Examples of procedures for a standard turn for a turn based strategy game. I am writing my game in C# and I have many concepts already mapped out or available to reference, except for the most important aspect: The turn handler.

    Basically each player has a number of units, and each unit it has an initiative value (based on its stats and starting conditions) to determine unit play order during a match. Each unit then has a standard turn in this order for the remained of the map, unless an effect is placed on him/her such slow (which just makes their imitative lower for x amount of turns then expires putting them back where they were in the turn list)

    Making the turn list is pretty start forward... I was going to have each player make a roll on a d20 then each of his units have their initiative stat added to it. The higher the value, the closer you are to the top of the list.

    I am just having trouble on how I should handle each units turn. I was thinking of a loop that is active until the "end turn" button is pressed and then while the loop is "true" the player can give the unit action commands. I just do not have the experience to visualize what I might need in this code such as checks or even how I should structure it.

    I hope this was a little more clear.
     
  4. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Hehe, so I guess you're saying I should have understood what you meant ;) My apologies then; the question just seemed a little general, and I wasn't quite sure what you were looking for exactly.

    I think I'd have to have a better understanding of the game structure to offer specific suggestions - maybe someone else will be able to help though.

    It sounds to me like a general programming problem though, more or less, with the (possible) catch that the 'main loop' has to be integrated with Unity's update system.

    One thing to consider (if you haven't already) is the idea of a central 'game' game object that orchestrates everything and keeps everything in sync. You can even take this further and have the 'game' object be the only object that receives Unity's 'update' callback(s), and then that object could in turn handle updating of all the other objects in the game (or at least those for which deterministic update handling is important). It seems this approach might be more beneficial for turn-based games than for some other types of game, but that's just speculative (I've never worked on anything turn-based myself).