Crates.io | casino_cards |
lib.rs | casino_cards |
version | 1.0.0 |
source | src |
created_at | 2024-07-14 19:50:30.88441 |
updated_at | 2024-08-30 15:33:13.78197 |
description | A library that provides a deck of playing cards that can be used for various card games. |
homepage | |
repository | https://github.com/winstonrc/casino/tree/main/crates/casino_cards |
max_upload_size | |
id | 1303210 |
size | 35,524 |
A library that provides a deck of playing cards that can be used for various card games.
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);
}