https://github.com/letsmakecakes/cards
Go Playing Cards Deck" is a Go project for managing and manipulating decks of playing cards, suitable for card games and simulations
https://github.com/letsmakecakes/cards
go golang
Last synced: 29 days ago
JSON representation
Go Playing Cards Deck" is a Go project for managing and manipulating decks of playing cards, suitable for card games and simulations
- Host: GitHub
- URL: https://github.com/letsmakecakes/cards
- Owner: letsmakecakes
- Created: 2023-10-24T08:32:51.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-05T14:50:29.000Z (over 2 years ago)
- Last Synced: 2025-01-14T01:49:44.660Z (over 1 year ago)
- Topics: go, golang
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go Playing Cards Deck
This Go program defines a simple deck of playing cards and provides various operations on it. You can create, manipulate, and save decks of cards, making it a useful tool for card games and simulations.
## Features
- **Create a New Deck**: Generate a deck of playing cards containing all the standard cards, such as Ace of Spades, Two of Diamonds, Three of Hearts, etc.
- **Display Cards**: Display all the cards in the deck.
- **Deal Cards**: Split the deck into two decks, simulating a card deal.
- **Convert to String**: Convert the deck into a comma-separated string.
- **Save to File**: Save the deck to a file on your local machine.
- **Load from File**: Read a deck from a file on your local machine.
- **Shuffle Cards**: Shuffle the cards in the deck, ensuring randomness.
## Installation
1. Clone this repository to your Go workspace:
```bash
git clone https://github.com/yourusername/cards.git
```
2. Navigate to the project directory:
```bash
cd goplayingcardsdeck
```
3. Build and run the application:
```bash
go build
./goplayingcardsdeck
```
## Usage
Here's an example of how to use the Go Playing Cards Deck in your Go program:
```go
package main
import "fmt"
func main() {
// Create a new deck
cards := newDeck()
// Shuffle the cards
cards.shuffle()
// Deal a hand of 5 cards
hand, remainingDeck := deal(cards, 5)
// Display the hand and the remaining cards
fmt.Println("Hand:")
hand.print()
fmt.Println("Remaining Cards:")
remainingDeck.print()
// Save the remaining deck to a file
remainingDeck.saveToFile("mydeck.txt")
// Load a deck from a file
loadedDeck := newDeckFromFile("mydeck.txt")
// Display the loaded deck
fmt.Println("Loaded Deck:")
loadedDeck.print()
}
```