PHP code example of bissolli / php-match-card-game
1. Go to this page and download the library: Download bissolli/php-match-card-game library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bissolli / php-match-card-game example snippets
$game = new \Bissolli\CardGame\Game();
$playerA = new \Bissolli\CardGame\Models\Player('Freek');
$playerB = new \Bissolli\CardGame\Models\Player('Bas');
$playerC = new \Bissolli\CardGame\Models\Player('Henk');
$playerD = new \Bissolli\CardGame\Models\Player('Pieter');
$game->addPlayers([ $playerA, $playerB, $playerC, $playerD ]);
// Adding one by one also works
// $game->addPlayers($playerA);
// $game->addPlayers($playerB);
// ...
$game->serveCards();
$game->start();
// To get the current card
// @return \Bissolli\CardGame\Models\Card
$game->getCurrentCard();
// To get all the players
// @return array of \Bissolli\CardGame\Models\Player
$game->getPlayers();
// To play a card - add the the leftover deck and set as current
$game->playCard(Card $card);
// Get deck
// @returns DeckManager
$game->getDeck();
// Get leftover deck
// @returns DeckManager
$game->getLeftOverDeck();
// Get players name - comma separated
$game->stringfyPlayers();
// Get card's face
$card->getFace();
// Get card's color
$card->getColor();
// Get card's suit
$card->getSuit();
// Get card's full name (face + suit)
$card->toString();
// Get player's name
$player->getName();
// Get player's hand
// @return array of Card
$player->getHand();
// Add card to player's hand
$player->addCardToHand(Card $card);
// Get player's hand as string
$player->stringfyHand();
// See if there is a similar card in the player's hand
$player->fetchSimilarCard(Card $cardToBeCompared);
// Count how many card there is left with the player
$player->countHand();
// Get the list of the cards in the deck
$deck->getDeck();
// Shuffle the deck
$deck->shuffle();
// Get X random cards from the deck
$deck->getRandomCards(int $amount);
// Shift the top card from the deck
$deck->shiftDeck();
// Add a card to the deck
$deck->addCard(Card $card);
// Count how many card there is in the deck
$deck->count();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.