Show current player's board at the top

Game development with Board Game Arena Studio
Post Reply
User avatar
Kellbot
Posts: 3
Joined: 08 April 2020, 22:35

Show current player's board at the top

Post by Kellbot »

I'm working on a game where each player has their own board. Does anyone have an example handy of how to set up the view so that each player sees their own board at the top? Games like Potion Explosion and 7 Wonders do this.

I'm not sure if there's a way to do this in view.php, or if I should just use javascript to bring the appropriate board into place after the game loads. Doing it on the PHP side seems preferable. Right now my approach is to pull out the current player id from the player list array, set up their board, then loop through the remaining players after the current player is set up.

I've put together a crude illustration of the layout I'm going for, where the top div contains the player area consisting of their personal board (blue rectangle) and shared board (purple rectangle, same for everyone), and the bottom div has smaller versions of each of the opponents' player boards.

Image
User avatar
hersh
Posts: 76
Joined: 12 December 2013, 23:49

Re: Show current player's board at the top

Post by hersh »

I follow the same approach. In view.php I get the current player id and loop through rest. Not sure there is a better approach.
User avatar
tchobello
Posts: 526
Joined: 18 March 2012, 13:19

Re: Show current player's board at the top

Post by tchobello »

Did you have a look at Hearts tutorial ?
User avatar
Tisaac
Posts: 2381
Joined: 26 August 2014, 21:28

Re: Show current player's board at the top

Post by Tisaac »

I usually do all this stuff in js, leaving the view.php almost empty.

Code: Select all

  var currentPlayerNo = gamedatas.bplayers.reduce((carry, player) => (player.id == this.player_id)? player.no : carry, 0);
  gamedatas.bplayers.forEach( player => {
    let isCurrent = player.id == this.player_id;
    player.no = (player.no + nPlayers - currentPlayerNo) % nPlayers;
    dojo.place(this.format_block('jstpl_player', player), 'board');

    if(isCurrent){
      ...
    }
  });
Notice here I am re-indexing the "no" field to display the board in a circle with the current player on top (as on 7Wonders), but if the player's order is not relevant in your game, you can just remove this re-indexing.
(I am also using a custom bplayers field instead of players since this one is sent as an object to the js side... (so basically $bplayers = array_values($this->players))
User avatar
Marcuda
Posts: 25
Joined: 21 September 2015, 00:36

Re: Show current player's board at the top

Post by Marcuda »

I went with php as well. My function is actually in game.php but I realize now it doesn't need to be. One thing I ran into is I had to account for spectators.

Code: Select all

// game.php
function getPlayersInOrder() {
    $result = array();

    $players = self::loadPlayersBasicInfos();
    $next_player = self::getNextPlayerTable();
    $player_id = self::getCurrentPlayerId();

    // Check for spectator
    if (!key_exists($player_id, $players)) {
        $player_id = $next_player[0];
    }

    // Build array starting with current player
    for ($i=0; $i<count($players); $i++) {
        $result[] = $player_id;
        $player_id = $next_player[$player_id];
    }

    return $result;
}

// view.php
$players = $this->game->getPlayersInOrder();
foreach ($players as $player_id) { ... }
Post Reply

Return to “Developers”