Page 1 of 1

Questions about changing player order and active player

Posted: 18 June 2014, 18:21
by daikinee
Hi,

I've seen no real documentation/message about that:

- how to changer player order? By changing the player_no directly in the database?
- after changing the player order, how to say that the active player is the new first one? Using "$this->gamestate->changeActivePlayer( $player_id )"? I'm not sure on this point and i see no global game variable that contains active player.
- any advice to the check whether it's the last player turn in a 'game' type state? I need this to check whether i begin a new "round" in the game.

Thanks

Re: Questions about changing player order and active player

Posted: 25 June 2014, 18:14
by daikinee
daikinee wrote: - any advice to the check whether it's the last player turn in a 'game' type state? I need this to check whether i begin a new "round" in the game.
For your information, the solution i finally use:

Code: Select all

        $playersBasicInfos = self::loadPlayersBasicInfos();
        $activePlayerId = self::getActivePlayerId();
        
        $activePlayerNumber = $playersBasicInfos[$activePlayerId]['player_no'];
        $playersNumber = self::getPlayersNumber();

        if ($activePlayerNumber == $playersNumber) {
            // Last player
            $this->gamestate->nextState( 'endTurn' );
        } else {
            // Activate next player
            $player_id = self::activeNextPlayer();
        
            self::giveExtraTime( $player_id );

            $this->gamestate->nextState( 'nextPlayer' );         
        }

Re: Questions about changing player order and active player

Posted: 26 June 2014, 21:28
by Een
Looks good :)

Re: Questions about changing player order and active player

Posted: 17 July 2014, 13:34
by sourisdudesert
Hi,
- how to changer player order? By changing the player_no directly in the database?
No, you're not supposed to change player_no in the database. But you can create another column "player_order" in the same table for your needs.
- after changing the player order, how to say that the active player is the new first one? Using "$this->gamestate->changeActivePlayer( $player_id )"? I'm not sure on this point and i see no global game variable that contains active player.
Yes, you should use changeActivePlayer. BGA framework is providing easy-to-use methods for most common needs (ex: activeNextPlayer), but if you want to active player in a custom order you must use your own logic and finally changeActivePlayer.

Cheers,

Re: Questions about changing player order and active player

Posted: 26 July 2014, 15:48
by daikinee
Thanks, i have just done it like you suggest