apetitpa/card-factory

CardFactory 是一个 PHP 库,旨在简化卡牌游戏的卡牌组创建和管理。它提供了一套有组织且可扩展的结构,包括用于卡牌、花色、点数和卡牌组的类和枚举,便于在各种游戏场景中构建和操作卡牌组。

v1.1.0 2023-03-27 21:55 UTC

This package is auto-updated.

Last update: 2024-09-28 01:41:11 UTC


README

License: MIT CI

CardFactory 是一个 PHP 库,旨在简化卡牌游戏的卡牌组创建和管理。它提供了一套有组织且可扩展的结构,包括用于卡牌、花色、点数和卡牌组的类和枚举,便于在各种游戏场景中构建和操作卡牌组。

需求

  • PHP >= 8.1

安装

要安装 CardFactory,请使用 Composer

composer require apetitpa/card-factory

用法

以下是一个使用 CardFactory 创建和操作一副卡牌的基本示例

use Apetitpa\CardFactory\Model\Deck;

// Create a standard deck of 52 playing cards (shuffled by default)
$deck = Deck::createStandardDeck();

// To create an ordered (not shuffled) deck, use:
$deck = Deck::createStandardDeck(false);

// Shuffle the deck
$deck->shuffle();

// Draw the top card from the deck
$card = $deck->drawCard();

// Check the card's suit and value
$suit = $card->getSuit();
$value = $card->getValue();

本地运行项目

您可以通过 Composer 安装 CardFactory

make install

代码分析

CardFactory 使用 PHPStanPsalm 进行静态代码分析。要运行 PHPStan 和 Psalm,请按照以下步骤操作

PHPStan

make phpstan

Psalm

make psalm

测试

要运行测试,请在项目根目录下执行以下命令

make test

许可证

CardFactory 是开源软件,受 MIT 许可证 许可。