定制 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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固