Search Unity

State Machines for Turn-Based Games

Discussion in 'Getting Started' started by Delshire, May 22, 2018.

  1. Delshire

    Delshire

    Joined:
    May 21, 2018
    Posts:
    5
    Hello everyone, after having my doubt cleared about singletons on my previous post i now come to ask about machine states. I am currently trying to make a basic turn-based game, nothing new, the battle starts, the user (real user) gets some buttons to choose which action to make (attack, rest, etc) the game then process this info (deals the necessary dmg, increases the amount of hp, etc) and then depending on the local player health or the enemy health win/lose states could be reached. I've made a simple diagram to discuss if my approach is correct or if there's something i should change, with this i ask, is there a different way of approaching this or this is the optimal one?

    NOTE: Black arrows should be the user flow and red ones should be the enemy's (That is purely AI, not a real player) Note that here ProcessInfoState does either attack (lowers the other entity health)/rest (increases the entity stamina) depending on the input


    Thanks
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    This is similar to your last question. And it's really the wrong question to ask.

    First, it's wrong because in many cases there is no optimal code design. What's "optimal" depends highly on the specific requirements. A common mistake is to design too general in the beginning, trying to take into account all sorts of eventualities that may never occur. A better approach is to design as simply as possible, and then refactor as needed.

    Second, it's wrong because even if there were an optimal code design, that does you no good if you never actually get around to making your game. And by far the single greatest risk to your game is that you will never finish it. So at every turn, you must aggressively look for the "simple and good enough" solution and then get on with it. Don't let anything slow you down. Not doubts about whether your design is optimal; not issues that you haven't thought through in great detail; not worries about how you will monetize your game. Be focused like a laser on making some progress every day.

    Write a little, test a little, and repeat. Resist any urge that gets in the way of that cycle.
     
    Delshire likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    P.S. I suspect the real issue might be just that you don't like working in a vacuum, and you enjoy discussing your work with other developers. I get that. Consider making a Works in Progress thread, and posting to it regularly. I don't routinely follow that subforum like I do this one, but if you @-mention me by name, I'll jump in when I can. :)
     
  4. Delshire

    Delshire

    Joined:
    May 21, 2018
    Posts:
    5
    Yeah i do agree, maybe i am thinking to much on future code maintenance and i am not even coding it, still the question was not really about if it was optimal or not but more like if the method and implementation is the correct one, i think i do not have very clear the proper separation a system needs to have (GUI->UserInput->Calculations->Display) and i think i expressed myself wrong and that's where i wanted to ask for help. Thanks for the answer :D