#cards #deck #poker #casino #playing

casino_cards

提供一副可以用于各种纸牌游戏的纸牌库。

2 个版本

0.1.1 2024年7月14日
0.1.0 2024年7月14日

#541 in 游戏开发

Download history 184/week @ 2024-07-11 37/week @ 2024-07-18 8/week @ 2024-07-25

229 每月下载量
2 个包中使用 (通过 casino_poker)

MPL-2.0 许可证

19KB
441

crates.io Cards Test

纸牌

提供一副可以用于各种纸牌游戏的纸牌库。

用法

牌组创建

use casino_cards::deck::Deck;

fn main() {
    let mut deck = Deck::new();
    deck.shuffle();

    let card1 = deck.deal();
    // A card can be inserted at a specified position in the deck.
    deck.insert(12, card);

    let card2 = deck.deal();
    // A card can be inserted at the bottom of the deck.
    deck.insert_at_bottom(card2);

    let card3 = deck.deal();
    // A card can be inserted at the middle of the deck.
    deck.insert_at_middle(card3);

    let card4 = deck.deal();
    // A card can be inserted at the top of the deck.
    deck.insert_at_top(card4);

    deck.shuffle();
}

牌创建

use casino_cards::card;
use casino_cards::card::{Card, Rank, Suit};

fn main() {
    // A card can be created with the new() method.
    let two_of_diamonds = Card::new(Rank::Two, Suit::Diamond);

    // Or a card can be created by using a macro.
    let two_of_clubs = card!(Two, Club);
}

手牌创建

use casino_cards::card::Card;
use casino_cards::deck::Deck;
use casino_cards::hand::Hand;

fn main() {
    let mut deck = Deck::new();
    deck.shuffle()

    // A hand can be created by pushing cards into it.
    let card1 = deck.deal();
    let card2 = deck.deal();
    let mut hand = Hand::new();
    hand.push(card1);
    hand.push(card2);

    // Or a hand can be created from an existing Vec<Card>.
    let mut cards: Vec<Card> = Vec::new();
    let card3 = deck.deal();
    let card4 = deck.deal();
    cards.push(card3);
    cards.push(card4);
    let mut hand2 = Hand::new_from_cards(cards);
}

依赖

~0.6–1.1MB
~23K SLoC