Card game : Display player hand to all players

Game development with Board Game Arena Studio
Post Reply
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

Card game : Display player hand to all players

Post by Ottoreg »

Hello,

I'm experiencing some trouble to find out how to display the hands of my players to each other.

In my game, player hands are not hidden (only the first card) so I wanted to display those cards on the board for every player to see them.

I managed to place each players hand in the right spots of my board but couldn't have the hands to be seen in all screens. Each player can only see his cards on his spot.

My other stocks are correctly displayed to all players at the same time (see the screenshots).

Any tips or advices would be very appreciated :)


example:

player 1:

Image

player 3:

Image

here's my code for deck creation :

Code: Select all


// create weapond cards

        $wcards = array();
        for($color = 1; $color <= 5; $color++ )
        {
            for($value = 1; $value <= 7; $value++ ){
                $wcards [] = array ('type' => $color, 'type_arg' => $value, 'nbr' => 1);
            }  
        }
        $this->weapon_card->createCards( $wcards, 'deck' );
        $this->weapon_card->shuffle('deck');
        $players = self::loadPlayersBasicInfos();
        foreach($players as $player_id => $player){
            $wcards = $this->weapon_card->pickCards(1,'deck', $player_id);
            // todo : remember that this card is hidden
        }
        foreach($players as $player_id => $player){
            $wcards = $this->weapon_card->pickCards(1,'deck', $player_id);
        }


and my code for stock creation :

Code: Select all


this.playerHand = new ebg.stock(); // new stock object for hand
this.playerHand.create(this, $('playerTableCard_' + this.player_id), this.wcard_width, this.wcard_height);
this.playerHand.image_items_per_row = 7; // 7 images per row
dojo.connect( this.playerHand, 'onChangeSelection', this, 'onPlayerHandSelectionChanged');

// create card types:
 for(var color = 1; color <= 5; color++){
 	for(var value = 1; value <= 7; value++)
 	{
 		// build card type id
                var card_type_id = this.getCardUniqueId(color,value);
                this.playerHand.addItemType(card_type_id, card_type_id, g_gamethemeurl + 'img/wcards.png', card_type_id);
         }
}

// cards in player hand 

for( var i in this.gamedatas.hand){
	var card = this.gamedatas.hand[i];
	var color = card.type;
	var value = card.type_arg;
	this.playerHand.addToStockWithId(this.getCardUniqueId(color,value),card.id);
}

this.playerHand.centerItems = true;
this.playerHand.setOverlap(50,0);

User avatar
ShaPhi7
Posts: 37
Joined: 22 April 2020, 20:44

Re: Card game : Display player hand to all players

Post by ShaPhi7 »

All of the code you have shared looks like it is from your server side (php). So at a guess, the game knows where all the cards are, but to display this on the screen, it now needs to tell the client side (your javascript, which runs for each individual player) to display the cards on all players screens.

Have a look at using the notifyAllPlayers method if you have not already? (Take a look at "Notify Players" section here: https://en.doc.boardgamearena.com/Main_ ... e.game.php).
User avatar
Ottoreg
Posts: 16
Joined: 16 March 2021, 11:13

Re: Card game : Display player hand to all players

Post by Ottoreg »

Yep that was a problem with notifications ! I thought I implemented them but I did it wrong ^^
Thanks !
Post Reply

Return to “Developers”