Hello !
I'm currently on the deck/stock part of the developement of my game and I have 2 main issues :
First : My cards seems to be stored in the database table in a wrong order.
If I understand well the process, I create the cards using the data I stored in the array 'wcards'.
So logicaly the first card in the database should be the card with 'type' = 1 and 'type_arg' = 1 but it's not the case. (see screenshot)
And the cards are stored at a different index every time i start a new game.
I'm probably missing something important but I can't figure out what.
Second : I can't get the card_id when I click on a card. Instead of the card_id I get 'undefined'.
It maybe a problem of scope or I'm not passing the right information in gamedata ?
I tried to find a solution looking into the heart tutorial but I couldn't find where I'm wrong.
Your help would be very appreciated !
Code php
function __construct :
function setupNewGame :
Code js
function constructor :
function setup :
Example of 'weapon_card' table :
I'm currently on the deck/stock part of the developement of my game and I have 2 main issues :
First : My cards seems to be stored in the database table in a wrong order.
If I understand well the process, I create the cards using the data I stored in the array 'wcards'.
So logicaly the first card in the database should be the card with 'type' = 1 and 'type_arg' = 1 but it's not the case. (see screenshot)
And the cards are stored at a different index every time i start a new game.
I'm probably missing something important but I can't figure out what.
Second : I can't get the card_id when I click on a card. Instead of the card_id I get 'undefined'.
It maybe a problem of scope or I'm not passing the right information in gamedata ?
I tried to find a solution looking into the heart tutorial but I couldn't find where I'm wrong.
Your help would be very appreciated !
Code php
function __construct :
Code: Select all
$this->weapon_card = self::getNew("module.common.deck");
$this->weapon_card->init("weapon_card");function setupNewGame :
Code: Select all
$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);
}function constructor :
Code: Select all
this.playerHand = null;
this.wcard_width = 69;
this.wcard_height = 96;Code: Select all
// player hand
this.playerHand = new ebg.stock(); // new stock object for hand
this.playerHand.create(this, $('myHand'), 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);
}
onPlayerHandSelectionChanged: function(){
var items = this.playerHand.getSelectedItems();
if(items.length > 0){
if(this.checkAction('playCard', true)){
// play a card
console.log("on cardChecked "+card_id);
var card_id = items[0].id;
this.playerHand.unselectAll();
}
else{
console.log("on cardChecked "+card_id);
this.playerHand.unselectAll();
}
}
},