Scopa

Game development with Board Game Arena Studio
User avatar
Woodruff
Posts: 411
Joined: 08 March 2014, 00:53

Re: Scopa

Post by Woodruff »

Hi !
Send each player a private notif with the three cards drawn, then connect with addToStockWithId. Example code:

Code: Select all

/*** In PHP ***/
self::notifyPlayer($player_id, 'newCardsDrawn', _("You draw ${cards}"), array('cards' => /* Your card info goes here */) );

/*** In JS, in the setupNotifications method ***/
dojo.subscribe('newCardsDrawn', this, "notif_newCardsDrawn"); // Tell that the UI must react to this kind of notification, executing the JS function below

/*** In JS, create this method ***/
notif_newCardsDrawn : function(notif) {
	var cards = notif.args.cards; // Fetch the cards drawn
	for(c in cards) { // This loop for can change depending of the structure you choose for sending cards
		var card = cards[c];
		this.player_hand.addToStockWithId(card.type, card.id, /* from argument if needed*/)
	}
},
If you want cards to slide, coming from the deck for example, you can specify the 'from' corresponding to the id of this deck (situation A for adding/removing cards in Stock). Or you can just specify nothing for the 'from' argument just to make the new cards appear in place.
User avatar
tchobello
Posts: 525
Joined: 18 March 2012, 13:19

Re: Scopa

Post by tchobello »

hello, I have a problem with this code :

Code: Select all

    function setLastCardPlayed() {
           $last_trick_winner = self::getGameStateValue( 'last_trick_winner' );
           $cards_to_pick = array ();
           $cards_to_pick = $this->cards->getCardsInLocation( 'cardsontable');
           $this->cards->moveCards( 'cardsontable', 'cardswon', $last_trick_winner);
           self::notifyAllPlayers('pickCards', clienttranslate('${player_name} picks all remaining cards'), array (
                'cards_to_pick' => $cards_to_pick,
                'player_id' => $last_trick_winner,
                'player_name' => self::getPlayerName($last_trick_winner) ));
    }

    function checkPickUp($card_id, $card_available, $player_id) {
        // si une carte est disponible, on ramasse les deux 
        //récupère la carte de même valeur
        if ($card_available) {
           $cards_to_pick = array ();
           $cards_to_pick[] = $card_id;
           $cards_to_pick[] = $card_available;
           self::setGameStateValue( 'last_trick_winner', $player_id );
           $this->cards->moveCards( $cards_to_pick, 'cardswon', $player_id);
           self::notifyAllPlayers('pickCards', clienttranslate('${player_name} picks 2 cards'), array (
                'cards_to_pick' => $cards_to_pick,
                'player_id' => $player_id,
                'player_name' => self::getActivePlayerName() ));
        }
    }
the function checkPickUp works fine but not setLastCardPlayed.
I need the last two cards on the table but I get an empty array in JS.

can someone help me ?
User avatar
Woodruff
Posts: 411
Joined: 08 March 2014, 00:53

Re: Scopa

Post by Woodruff »

Hi,
You are using the wrong deck method:
  • $this->cards->moveCards is used when you already have an array of cards to transfer, as you did in self::checkPickUp.
  • To move all cards from a location to another, you have to call $this->cards->moveAllCardsInLocation. That's the case in self::setLastCardPlayed.
So you have to replace

Code: Select all

$this->cards->moveCards( 'cardsontable', 'cardswon', $last_trick_winner);
by

Code: Select all

$this->cards->moveAllCardsInLocation( 'cardsontable', 'cardswon', null, $last_trick_winner);
You can remove the line before that by the way

Code: Select all

$cards_to_pick = array ();
Since the array is returned by the method itself, you don't have to initialize it before.

Bye :)

Tcheby
User avatar
tchobello
Posts: 525
Joined: 18 March 2012, 13:19

Re: Scopa

Post by tchobello »

Damn, I've made minor changes and the setLastCardPlayed() function sends again an empty array for the cards id to be picked...

I don't know where it comes from since I'm using

Code: Select all

$this->cards->moveAllCardsInLocation( 'cardsontable', 'cardswon', null, $last_trick_winner);
Post Reply

Return to “Developers”