定制 bissolli/php-match-card-game 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bissolli/php-match-card-game

Composer 安装命令:

composer require 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!

关键字:

README 文档

README

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 Latest Stable Version Total Downloads License

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

  • 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

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

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

License

Laravel Cashier is open-sourced software licensed under the MIT license.

bissolli/php-match-card-game 适用场景与选型建议

bissolli/php-match-card-game 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「card game」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bissolli/php-match-card-game 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bissolli/php-match-card-game 我们能提供哪些服务?
定制开发 / 二次开发

基于 bissolli/php-match-card-game 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-06