Giter Site home page Giter Site logo

ttg-cards's Introduction

ttg-cards. Flexible Tabletop Card library for PHP

A standard 52-card deck is provided by default, but one can customize to build any deck needed. Create Bridge, BlackJack, Poker and more...

Installation

Pull in the package through Composer.

Run composer require jouva/ttg-cards

Usage

To start using the deck...

$d = new Deck;

$d->shuffle();

//deal... an array of cards
$hand1 = $d->drawHand(10);
$hand2 = $d->drawHand(10);

//draw a single card
$card = deck->draw();

//do something with card
$value = $card->value();
$suit = $card->suit();

//special card?
if($card->isFaceCard()){...}

//cards left in the deck
$deck->count(); 

When the game is over, simply reset the deck by shuffle(ing). The deck now has all the cards (including drawn).

//start a new game...
$deck->shuffle();

To customise the deck of cards (i.e. which cards are part of the deck) one can implement the CardProvider interface

class MyGameDeckProvider implements CardProvider {
    
    public function getCards(): array {

        //return an array of card for MyGame 
	}
}
//...
$deck = new Deck(new MyGameDeckProvider);

You may also want to look at:

  • Shuffleable for shuffling the cards
  • CardProvider for providing cards to the deck

The current implementation doesn't let putting cards back into the deck after drawing them. Shuffle resets the deck

ttg-cards's People

Contributors

jouva avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.