DeckOfPlayingCards 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package DeckOfPlayingCards --version 1.1.2                
NuGet\Install-Package DeckOfPlayingCards -Version 1.1.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DeckOfPlayingCards" Version="1.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DeckOfPlayingCards --version 1.1.2                
#r "nuget: DeckOfPlayingCards, 1.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DeckOfPlayingCards as a Cake Addin
#addin nuget:?package=DeckOfPlayingCards&version=1.1.2

// Install DeckOfPlayingCards as a Cake Tool
#tool nuget:?package=DeckOfPlayingCards&version=1.1.2                

Deck of cards

Nuget

Table of Contents

About

This library can be used to create card games such as poker or blackjack. With this library, you can create a standard deck of 52 cards, shuffle it, and draw cards. You can also reset the deck if you want to run it again.

Features

This package includes the following classes:

  • Card.cs
  • Deck.cs

The Card.cs class is a simple class for storing the rank and the suit of the card. The Deck.cs class contains a list of cards as a property. It also includes the following methods:

  • get()
    • Gets a standards deck of 52 cards, not shuffled.
  • shuffle()
    • Shuffles the deck.
    • Includes a parameter to specify whether the already drawn cards should be shuffled back into the deck.
    • A Random variable can be passed in. If not, a Random variable is initialized.
  • draw()
    • Draws a card from the deck.
    • Returns the drawn card
  • reset()
    • Resets the deck, meaning all drawn cards will be put back onto the deck in the same order as they were originally.

The draw() method doesn't remove a card from the deck, it simply returns the card at the current index and moves the index up by 1. This is how already drawn cards can be put back into the deck in the same order.

For the source code, check out the GitHub repo.

Installation

To use Deck of Cards in your project, you can install it via NuGet Package Manager:

nuget install DeckOfPlayingCards

Usage

Getting a deck, shuffling it, drawing cards, and resetting it is pretty straightforward. See the code snippet below.

using DeckOfCardsLibrary;

// Get an unshuffled deck.
var deck = Deck.get();

// Shuffle the deck.
deck.shuffle();

// Draw some cards.
var firstCard = deck.draw()!;
var secondCard = deck.draw()!;

// Keep in mind that deck.draw() returns null if all the cards in the deck have already been drawn.
// In this case I have only drawn two cards, so I can safely say the method does not return null.

// I'll display them in a way that is easy on the eye.
// The rank "10" will be displayed as "T" here to make sure the display string will always be two characters.
Console.WriteLine(firstCard.getDisplayString(displayTenAsT: true));
Console.WriteLine(secondCard.getDisplayString(displayTenAsT: true));

// That was a good hand! Let's reset the deck so I get the same cards again.
deck.reset();

// Just kidding! I play fair.
deck = Deck.get();
deck.shuffle(random: new Random(915));

The GitHub repo also includes a console app which you can play around with.

Contributing and Feedback

If you have questions, concerns, or would like to contribute to this project, there are several ways to get involved:

  • Open an Issue: If you encounter a bug, have a feature request, or want to discuss improvements, please open an issue.

  • Start a Discussion: You can also initiate a discussion in the Discussions section of this repository to share ideas or seek help.

  • Fork and Contribute: If you'd like to make changes or enhancements to the project, fork the repository and submit a pull request with your proposed changes.

Your contributions and feedback are highly valued and essential to the improvement of this project. Thank you for your support!

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DeckOfPlayingCards:

Package Downloads
CasinoSuite.Poker

A comprehensive library for working with poker hands and cards in C#. This library includes classes for representing poker hands, cards, and offers utility methods for evaluating and comparing poker hands.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 328 10/21/2023
1.1.2 149 10/18/2023
1.1.1 156 10/14/2023
1.1.0 137 10/14/2023
1.0.0 143 9/20/2023

* `deck._index` now starts at 0 instead of -1.