Page 1 of 1

[Beye] using Deck componant with hidden cards.

Posted: 01 April 2013, 21:15
by Rudolf
Bonsoir,
I need to better understand the rule of 'deck' componant.
To present the game: I need to show 21 cards in 3 rows of 7 columns. The first and the last row are hidden.
I use an array to initiate Occurancy relative to card picture (0 is back, so appears 0 times, then yellow fighter appers 3 times, red fighter 4 times, ..., empty plain 3 times)
this gives:

Code: Select all

$this->PlainCardOccurence = array( 0, 3, 4, 5, 3, 1, 1 , 1, 3 );

$this->cardtypes = 
array
(
    0 => array( 'name' => clienttranslate('back'),
                'nametr' => self::_('BACK') ),
    1 => array( 'name' => clienttranslate('yellow fighter'),
                'nametr' => self::_('YELF') ),
    2 => array( 'name' => clienttranslate('red fighter'),
                'nametr' => self::_('REDF') ),
    3 => array( 'name' => clienttranslate('green fighter'),
                'nametr' => self::_('GREF') ),
    4 => array( 'name' => clienttranslate('buffalo'),
                'nametr' => self::_('BUFFALO') ),
    5 => array( 'name' => clienttranslate('totem'),
                'nametr' => self::_('TOTEM') ),
    6 => array( 'name' => clienttranslate('shaman'),
                'nametr' => self::_('SHAMAN') ),
    7 => array( 'name' => clienttranslate('white buffalo'),
                'nametr' => self::_('SPIRIT') ),
    8 => array( 'name' => clienttranslate('plain'),
                'nametr' => self::_('EMPTY') )

);
I suppose that I have to feel my $location 'Plain' like this using only 'nbr' in game.php?

Code: Select all

protected function ShufflePlain()
    {
	// Create cards
        $cards = array();
        for( $j=1;$j<$this->PlainCardOccurence.length;$j++)
        {
                $cards[] = array( 
				'type' => $j, 
				'type_arg' =>$this->cardtypes[$j] , 
				'nbr' => $this->PlainCardOccurence[$j]
				);
        }

        $this->cards->createCards( $cards, 'plain' );
	$this->cards->shuffle( 'plain' );
    }
this will create 21 cards shuffled, even I enter only 8 times in array? (else I donot understand the goal of nbr)

Other thing, to be sure player cannot cheat in code to see what is id under back of card, i replace id when I get the data form the DB...
Is it correct to do like this?

Code: Select all

protected function getAllDatas()
    {
        $result = array( 'players' => array(), 'plaincards'=>array() );
    
        $current_player_id = self::getCurrentPlayerId();    // !! We must only return informations visible by this player !!
    
        // Get information about players
        // Note: you can retrieve some extra field you added for "player" table in "dbmodel.sql" if you need it.
        $sql = "SELECT player_id id, player_score score FROM player ";
        $result['players'] = self::getCollectionFromDb( $sql );
	$sql = "SELECT plain_index [index], plain_card card, plain_status [status] FROM plain";
  	$result['plaincards'] = self::getCollectionFromDb( $sql );
	// hide the id of cards hidden!
	for ($i=0; $i<21; $i++)
	{
		//check status if hidden, id=back of card.
		if( !($result['plaincards'][$i][2])) $result['plaincards'][$i][1]=0; 
	}
     
        return $result;
    }
And Last thing, I would like to know in my case, how I can get from $location 'plain', an indexed card...
for example I would like to know what is the id (between 1 and 8) of the card indexed 17 (between 0 and 20)...
I suppose I have to use $this->cards->getCard()... but I don't really understand how to manage it in this case?
could you explain more?
thanks

Re: [Beye] using Deck componant with hidden cards.

Posted: 01 April 2013, 21:26
by sourisdudesert
Hello,

For the 1st:
Yes, this is the way you should use "nbr" property in createcards.

For the 2nd:
Your approach is probably not the best one. This is true that the ID of a card can allow a player to determine its type, but this is not a problem as you must never send a player the ID of a card until he can see this card. If you make this happens, you don't have to worry anymore about your IDs.

For the 3rd:
You should use getCardsInLocation() method to retrieve the list of cards in a specific location.

Cheers

Re: [Beye] using Deck componant with hidden cards.

Posted: 01 April 2013, 22:05
by Rudolf
Sure fro me id is important, because I need it for background-position = -width * id !!!
it's better to use like that, no???

Re: [Beye] using Deck componant with hidden cards.

Posted: 02 April 2013, 09:25
by sourisdudesert
Hello Rudolf,

Well, 2 situations:
_ if your player has to see the card, then you transmit the ID of the card and use your formula.
_ if your player don't have to see the card, then you don't transmit the ID of the card and use the "backcard" background.

Cheers,

Re: [Beye] using Deck componant with hidden cards.

Posted: 02 April 2013, 15:24
by Rudolf
I think it's better to put backcard as beginning of "all cards picture", then id=0 is backcard.... id = 1 is yellow fighter... etc...
it optimizes the code. that's why I replace id=0 for hidden cards in php.
by the way, thanks for answers ;)