Is it easy to make a Turn based Game?

Hi, so I have recently started work on a Turned based RPG with the same battle style as Final Fantasy, but I’m having problems keeping the combat Turnbased and 3rd Person. Anyone have any tutorials or source codes that they know of which could help? maybe a Chess game or a Soccer Penalty Shoot Out?

I’d love to hear what you have to say and love it even more if you had some tutorials that you made or know about that you would like to share with everyone here :slight_smile:

Thanks In Advance!

-Mystic Works

How are you having trouble keeping it turn based? Simply give control to one and only one character, when he finishes give control to another one?

Hes not, hes just asking for someone to do it for him.

I’m not asking for someone to do it for me, I’m looking for tutorials, a source code would be great but thats not what I’m looking for 100%.

2 Likes

It just follows a simple event driven flow.

These are some basic tutorials from PlayerIO. They are geared toward Flash, but the concepts apply to Unity, too.

http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/turnbased

http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/examplegame

http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/example-turn-based

1 Like

Said it all.

I don’t know of a methodology for scripting turn based gameplay, but it shouldn’t be to hard to just make up your own!

In your script you should have an integer in charge of keeping track whose turn it is. For example a turns variable could be equal to the player turn’s number. If it’s player 1, turnsVariable should be 1, if it’s 2, then 2, and so on.

When player 1 finishes moving his units, he should somehow input that he’s done with his turn, maybe with a “next turn” button, the button’s script should increase the turns variable value, with ++, so now it’s player 2’s turn.*

*++ is the same as += 1

If player 2 is cpu controlled, every unit should follow their routines, and when all unit have been moved, you should ++ the turns variable automatically.

If there’re only two players, after you’ve ++ the turns variable, you should check if it’s equal or larger than a playerAmount variable (in this case it’s 2).
If so, that means all players are done for that round, and it’s time to reset the action points or move points or whatever you use to quantify the turn based units’ movement, also set the turns variable back to 1 so player 1 gains back control.

actually turn based games are kinda hard, Ive tried several and they have their own nuances and difficulties. Its harder than you think.

It is insanely hard! seriously its much much much much much much harder then just not turn based :smile: (no joke chess is ridiculous :()

I could happily do a fully networked implementation of chess in less than two days.

The key is knowing the right paradigms, once you’re familiar with them there’s no challenge in the programming, just implementation.

1 Like

Without cheating by downloading code and writting your own competitive AI? :wink:

AI? There’s a reason I said networked - no point reinventing the wheel if it’ll cost a lot in dev and add very little value! :slight_smile:

If I had to do AI, then I’d certainly be looking to existing code as it’s not my forte.

That said, I could create a chess game with a simple AI in 2 Days - and it might be a tad better then you’d imagine at first guess :stuck_out_tongue:

i had similar problems and similar answers, no one will help you , not for turn based, cause for pro’s is too simple. You need to learn . but someone did a chess in unity and provide the code

try this and give a like !

1 Like

Turn-based is too simple for pros? That’s not true, there are many very profitable turn-based games. I already told him how you go about it.

Look, let’s make this simple.

Grab the manual of any basic game, take Candyland if you like or even Snakes and Ladders. Code those rules into C#. Turn-based game.

It is just event-driven programming. If you can’t get that, then you need to go back to studying very basic programming. Something happens, it triggers the next event, which triggers the next, and so on.

1 Like

This is actually harder in Unity that many people think.

It takes understanding of specific commands out there (like how to properly use the yield command and IEnumerators) to set it up, and most people out there don’t do tutorials on things of this nature.

Ensure you use a custom built infinite loop that checks the game’s state to determine where to be. (Using a while(true) or for(;:wink: will do the trick). Start your loop inside Start or Awake in your main controller object. Then, inside that loop, ensure that every time it comes to a new player’s turn (NPC’s included) that it waits until the current process is done (use yield to proceed your function call). The yield statement forces Unity to wait until you are done with the current function completely before moving on to the next command in any way.

Using if statements based on turn/game state can tell it when to display things like menus.

Hopefully this helps you build what you need, as some people assume that with their experience with the system, it’s better to badmouth you for not understanding specific keywords and their functionality. My college courses certainly haven’t gone over this portion, and it took a while for me to figure it out as well because people that know it frequently consider it too easy to do to worry about discussing, and those that don’t know it can’t find it to share it.

2 Likes

No it isn’t. Really. It’s just like writing any other game. As JRavey says, it’s all about event-driven programming.

Real-time games update the game’s state every frame, but you don’t have to do it that way.

It’s a common misconception that a game must be tied to the camera and the Update() / LateUpdate() cycles. You need to decouple the game logic from the updating process.

Think of a game as three separate components: the “Model” (which represents the gameplay logic), the “View” (which displays the game’s state) and the “Controller” (which handles interactions with the Model and the View. (This is better known as the “MVC” design pattern. It’s used heavily in traditional application design.)

The “View” logic can be nailed into the camera scripts.
The “Model” logic should probably live in its own master GameObject. It controls all the game’s state and includes the Finite State Machine scripts.
The “Controller” logic may be better off added to the Camera too, although some “Controller”-related scripts will probably need to live in the master GameObject to help communications between the two.
I’d resist trying to throw everything into the camera GameObject as it’ll just get very bogged down.

Also, if you’re unfamiliar with creating your own standalone classes, I strongly recommend reading up on how to do this. Most C# tutorials will be able to help here. (I don’t tend to use Javascript much, but that’s an option if you prefer.)

Briefly:

You need a game state variable that keeps track of whose turn it is to play. If every player is sharing the same computer, the logic that changes that state variable would also throw up a “Get Ready Player ” (where “X” is the number of the player whose turn it is to play.) If playing over a network, you just prevent players who aren’t playing their turn from interacting with the game’s pieces. (But do remember to allow them access to the menus.)

Once a player has made his move(s), they hit an “End Turn” button and the client updates the game model, then cycles the “CurrentPlayer” state variable to the next player in sequence so they can take their turn.

None of this is particularly difficult. The fact that the graphics are updating every frame is irrelevant. Players can still be allowed to look over the board, spin the camera, etc. As long as they’re not allowed to actually change anything relevant to the gameplay, that’s fine.

2 Likes

Isn’t programming about looking at circumstances and figuring out how to create code that recreates that virtually? I’ve never made a turn based game but how to do it seems painfully obvious. Like another poster said, event driven… that’s the meat and potatoes right there. I’m sure there are some challenging aspects in the details but isn’t that true about most everything? If not for the networking I don’t see why a turn based game would be any more difficult than a Tetris clone.

Aha, now either you’re a genius, or you’re seriously underestimating chess games AIs (or you meant a really really really extremely simple AI) :stuck_out_tongue:

Jokes aside, this would truly be an interesting challenge if more people participated: “make a 2-day chess game with AI - and graphics”: I’d love to see the results and read the various post-mortem.

I know next to nothing about chess AI’s - but I know a bit about brute force :slight_smile:

Shouldn’t be too hard to get an AI to see a couple steps ahead - more steps the fewer the pieces available. There already exists a simple value system for pieces won/lost - so that’s easy to implement.

Simple yes, but it’d actually play.