Turnbased with more than two players

0 favourites
  • 3 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Has anyone done a turnbased game where there are more than two players, and how do you keep track of it, going through the turns and handling their states?

    So far in my game everything works fine with just two players - human player and pc opponent, each kept check off with their units in two families called "Player" and "Enemy", with many of their stats taken care of in family variables. So the whole combat code works pretty much on "clicked Enemy family yes/no", "your turn yes/no", "Player gold/Enemy gold" etc. But there is planned to hopefully be a total of four "factions" in the game.

    Including more than one family of units and having the game switch between player 1-4 in turns, with the changes between who are now player/enemy/ally, seems to complicate things a bit. So before I throw myself into confused spaghetti code...

    Any tips from anyone who tried to do this, on how to approach it? All the examples I find are just with two very simple players. Maybe something with arrays?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Cant you just make a game controller of some kind that keep track of which turn it is to move. And use this as an overall controller for all things. So if this variable "Turn = Player 3" then nothing else will trigger for any other player. And then in all your functions, events etc where you need to pick or do something with some units or whatever, you just make sure that you always check or pass the current player "Turn" into the function, or just read it from the game controller, so this value always match the player that is currently moving.

    I assume that all units/stuff in the game have a variable that indicate who they belong to. So if you make these match the "Turn" variable it should be fairly easy to always make sure that you select the correct units.

    I don't think you necessarily need to use arrays, it ofc depend on the game you are making. But it should be enough to just make one variable that you use to whenever you need to check the ownership of something.

    You could for instant make a small sprite called Faction, add it to a family and give it a owner variable and at the beginning of the game you spawn 4 of these for instant and set the owner as following:

    Owner = Player 1

    Owner = Player 2

    Owner = Player 3

    Owner = AI 1

    And you can then add to the family the variables that you need like INT:money, BOOL:Ally with player 1, BOOL: Ally with player 2 etc and you just switch these on off. Whenever something changes.

    Due to the Owner variable it should be fairly simple to select the correct faction:

    Faction.Owner = Turn.variable (From the game controller)

  • That is a wonderfully simple idea compared to what I was thinking and confusing myself with. I'll try just that! Thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)