This is a documentation for Board Game Arena: play board games online !
Deck: تفاوت میان نسخهها
(Created page with ""Deck" is one of the most useful component on PHP side. With "Deck", you can manage cards of your game on server side. Using "deck", you will be able to use the following fea...") |
بدون خلاصۀ ویرایش |
||
خط ۵: | خط ۵: | ||
* "Auto-reshuffle" discard pile into deck when deck is empty. | * "Auto-reshuffle" discard pile into deck when deck is empty. | ||
* Move cards between different locations: hands of players, the table, ... | * Move cards between different locations: hands of players, the table, ... | ||
== Using Deck: Hearts example == | |||
Deck component is massively used in "Hearts" example game - a card game. You can find in "hearts.game.php" that the object "$this->cards" is used many times. | |||
== Deck general principles == | |||
For each Deck component in your game, you need to create a dedicated table in database. This table has a standard format. In practical, if you want to have a Deck component named "card", you just have to copy/paste the following in your "dbmodel.sql": | |||
<pre> | |||
CREATE TABLE IF NOT EXISTS `card` ( | |||
`card_id` int(10) unsigned NOT NULL AUTO_INCREMENT, | |||
`card_type` varchar(16) NOT NULL, | |||
`card_type_arg` int(11) NOT NULL, | |||
`card_location` varchar(16) NOT NULL, | |||
`card_location_arg` int(11) NOT NULL, | |||
PRIMARY KEY (`card_id`) | |||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; | |||
</pre> | |||
Once you did this (and restart your game), you can declare your Deck component in your PHP code in your class constructor. For Hearts for example, I added to "Hearts()" method: | |||
<pre> | |||
$this->cards = self::getNew( "module.common.deck" ); | |||
$this->cards->init( "card" ); | |||
</pre> | |||
Note that we specify "card" here, the name of our previously created table. It means you can create several "Deck" with several tables. Most of the time this is unuseful: a Deck component should manage all objects of the same kind (ex: all cards of the game). |
نسخهٔ ۱۱ فوریهٔ ۲۰۱۳، ساعت ۱۸:۰۵
"Deck" is one of the most useful component on PHP side. With "Deck", you can manage cards of your game on server side.
Using "deck", you will be able to use the following features without writing a single SQL database request:
- Place cards in pile, shuffle cards, draw cards one by one or many by many.
- "Auto-reshuffle" discard pile into deck when deck is empty.
- Move cards between different locations: hands of players, the table, ...
Using Deck: Hearts example
Deck component is massively used in "Hearts" example game - a card game. You can find in "hearts.game.php" that the object "$this->cards" is used many times.
Deck general principles
For each Deck component in your game, you need to create a dedicated table in database. This table has a standard format. In practical, if you want to have a Deck component named "card", you just have to copy/paste the following in your "dbmodel.sql":
CREATE TABLE IF NOT EXISTS `card` ( `card_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `card_type` varchar(16) NOT NULL, `card_type_arg` int(11) NOT NULL, `card_location` varchar(16) NOT NULL, `card_location_arg` int(11) NOT NULL, PRIMARY KEY (`card_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Once you did this (and restart your game), you can declare your Deck component in your PHP code in your class constructor. For Hearts for example, I added to "Hearts()" method:
$this->cards = self::getNew( "module.common.deck" ); $this->cards->init( "card" );
Note that we specify "card" here, the name of our previously created table. It means you can create several "Deck" with several tables. Most of the time this is unuseful: a Deck component should manage all objects of the same kind (ex: all cards of the game).