PHPackages                             bissolli/php-match-card-game - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. bissolli/php-match-card-game

ActiveLibrary

bissolli/php-match-card-game
============================

Simple card game built in PHP that let players have fun playing against each other. Wins who gets its own hand empty first!

v1.0.1(7y ago)011MITPHPPHP &gt;=7.1

Since Oct 6Pushed 7y agoCompare

[ Source](https://github.com/bissolli/php-match-card-game)[ Packagist](https://packagist.org/packages/bissolli/php-match-card-game)[ RSS](/packages/bissolli-php-match-card-game/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

PHP Card Game
=============

[](#php-card-game)

Simple card game built in PHP that let players have fun playing against each other. Wins who gets its own hand empty first!

[![Build Status](https://camo.githubusercontent.com/d179d5c9e6d41bbb9c9b141985afc2e5d2ffd48c2d8bfa4a3158ea1bf22154f1/68747470733a2f2f7472617669732d63692e6f72672f626973736f6c6c692f7068702d6d617463682d636172642d67616d652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bissolli/php-match-card-game)[![Latest Stable Version](https://camo.githubusercontent.com/000c29cf860539c9db2173b17f7ba8c23868fd357cfef16f71a9ea54a62aa0c2/68747470733a2f2f706f7365722e707567782e6f72672f626973736f6c6c692f7068702d6d617463682d636172642d67616d652f762f737461626c65)](https://packagist.org/packages/bissolli/php-match-card-game)[![Total Downloads](https://camo.githubusercontent.com/6dcd97604694ef08a31728c2fa0035861b171d8312101c80d630ddb479254084/68747470733a2f2f706f7365722e707567782e6f72672f626973736f6c6c692f7068702d6d617463682d636172642d67616d652f646f776e6c6f616473)](https://packagist.org/packages/bissolli/php-match-card-game)[![License](https://camo.githubusercontent.com/4f44b55a42e5df4e3d1d5c1ec6f4b3a2447dd20af844f90d3a021c10ab632e64/68747470733a2f2f706f7365722e707567782e6f72672f626973736f6c6c692f7068702d6d617463682d636172642d67616d652f6c6963656e7365)](https://packagist.org/packages/bissolli/php-match-card-game)

Installation
------------

[](#installation)

To get started, require this composer package:

```
composer require bissolli/php-match-card-game
```

Or simply clone the project, run `composer install` and check the `index.php` file

Game rules
----------

[](#game-rules)

- The deck consists out of 52 cards.
- Every player starts with same amount of cards (`default: 7`).
- Game starts with the top card of the deck which is gonna create the leftover deck.
- Each turn another player places a card on the top of the leftover deck.
- This card must be of the same value or from the same color.
- If player cannot place a card, he should get a new card on the deck and skip his turn.
- The first player that doesn’t have any cards left, wins the game.

Usage
-----

[](#usage)

The first step to start the game is instantiating the Game class which is going to be our "Game Manager" and get the deck ready and shuffled.

```
$game = new \Bissolli\CardGame\Game();
```

Once we have the game ready, we need to add the players - you can add as much players as you wish as long as the deck supports it. Remember, each player starts with 7 cards and the deck has a total of 52 cards.

```
$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);
// ...
```

As long as we have the deck ready and the players enrolled, let's server 7 cards for each player.

```
$game->serveCards();
```

To start the game and shift the top card from the deck to the leftover deck:

```
$game->start();
```

From now on we all all the following methods available

```
// 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();
```

See below methods available for the Card model

```
// 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();
```

See below methods available for the Player model

```
// 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();
```

See below methods available for the DeckManager

```
// 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();
```

Output
------

[](#output)

You can see a code example in the `./index.php` which should output something like this:

```
Starting game with Freek, Bas, Henk, Pieter
Freek has been dealt: 1♠ King♠ 6♦ Jack♠ 9♣ Jack♥ 3♦
Bas has been dealt: 10♠ Queen♦ 10♦ 3♣ Jack♦ 9♠ Jack♣
Henk has been dealt: 6♥ 1♣ 9♦ 1♥ 1♦ 8♦ 6♠
Pieter has been dealt: 7♣ Queen♥ 4♠ 9♥ 2♦ 2♠ 8♣
Top card is: 6♣
Freek plays King♠
Bas plays 3♣
Henk plays 6♠
Pieter plays 2♠
Freek plays Jack♠
Bas plays Jack♦
Henk plays 8♦
Pieter plays 2♦
Freek plays 3♦
Bas plays Queen♦
Henk plays 6♥
Pieter plays Queen♥
Freek plays 6♦
Bas plays 10♦
Henk plays 1♥
Pieter plays 9♥
Freek plays 9♣
Bas plays Jack♣
Henk plays 1♣
Pieter plays 8♣
Freek plays 1♠
Bas plays 9♠
Henk plays 9♦
Pieter does not have a suitable card, taking from deck 4♦
Freek plays Jack♥
Freek has won
```

Author
------

[](#author)

- [Gustavo Bissolli](mailto:gustavo.bissolli@gmail.com)

License
-------

[](#license)

Laravel Cashier is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2776d ago

PHP version history (2 changes)v1.0.0PHP ^5.6|^7.0

v1.0.1PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/ca397144f6b529656fd8307e8d895a86d0afab2b6a622af7ee87e833a692950b?d=identicon)[bissolli](/maintainers/bissolli)

---

Top Contributors

[![bissolli](https://avatars.githubusercontent.com/u/1808444?v=4)](https://github.com/bissolli "bissolli (13 commits)")

---

Tags

phpcard game

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bissolli-php-match-card-game/health.svg)

```
[![Health](https://phpackages.com/badges/bissolli-php-match-card-game/health.svg)](https://phpackages.com/packages/bissolli-php-match-card-game)
```

###  Alternatives

[pestphp/pest-plugin-stressless

Stressless plugin for Pest

67792.6k16](/packages/pestphp-pest-plugin-stressless)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
