Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
一副纸牌_创想鸟

一副纸牌

一副纸牌

我最近一直在与 verbs 和 livewire 合作,并认为尝试创建一些我喜欢玩的纸牌游戏是一个有趣的实验。

为了促进这一点,我需要定义一副卡片,我可以在之后从事的任何项目中使用它。

一副牌需要包含 card、deck 和 cardcollection 类。一张牌应有花色和数值,一副牌应由 52 张牌组成。因为花色和数值都是为一副牌定义的,所以我可以使用枚举来表示牌的属性。

cardcollection 类允许我以 verbs 状态安全地存储卡片集合。

<?php// cards/enums/suit.phpdeclare(strict_types=1);namespace cardsenums;enum suit: string{    case clubs = 'clubs';    case diamonds = 'diamonds';    case hearts = 'hearts';    case spades = 'spades';}
<?php// cards/enums/value.phpdeclare(strict_types=1);namespace cardsenums;enum value: string{    case two = 'two';    case three = 'three';    case four = 'four';    case five = 'five';    case six = 'six';    case seven = 'seven';    case eight = 'eight';    case nine = 'nine';    case ten = 'ten';    case jack = 'jack';    case queen = 'queen';    case king = 'king';    case ace = 'ace';}
<?php// cards/card.phpdeclare(strict_types=1);namespace cards;use cardsenumssuit;use cardsenumsvalue;final readonly class card{    public function __construct(        public suit $suit,        public value $value,    ) {}}
map(fn($serialized) => card::deserializeforverbs($serialized, $denormalizer));    }    public function serializeforverbs(normalizerinterface $normalizer): string|array    {        return $this->map(fn(card $card) => $card->serializeforverbs($normalizer))->tojson();    }}
cards = CardCollection::make([]);        collect(CardSuit::cases())            ->each(function (CardSuit $suit): void {                collect(CardValue::cases())                    ->each(function (CardValue $value) use ($suit): void {                        $this->cards->push(new Card($suit, $value));                    });            });        $this->shuffle();    }    public function shuffle(): void    {        $this->cards = $this->cards            ->shuffle()            ->reverse();    }    public function deal(): ?Card    {        if (0 === $this->cards->count()) {            return null;        }        return $this->cards->pop();    }    public function remainingCards(): int    {        return $this->cards->count();    }}

以上就是一副纸牌的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1249410.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
PHP 返回数组,如何用 HTML 的 ul 列表输出?
上一篇 2025年12月9日 21:22:09
为什么使用 “ 标签的 `onclick` 属性跳转失效?
下一篇 2025年12月9日 21:22:20

相关推荐

发表回复

登录后才能评论
关注微信