npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uno-game-engine

v3.4.1

Published

This is a game engine for the card game UNO

Downloads

14

Readme

UNO Game Engine

Installing

npm i uno-game-engine

Basic Usage


const { Game, events } = require('uno-game-engine')

let game = new Game(["player1", "player2", "player3", "player4"]) // this also accepts an actual player objects array. but you need to create it yourself

game.eventManager.addEvent(new events.PlayerChangeEvent((oldPlayer, newPlayer) => {
    // do something with it
    console.log(`It is now ${newPlayer.name}'s turn`)

}))

game.start()

// playing cards
let cardToPlay = game.currentPlayer.hand.getCard("RED", "FIVE") // assuming the current player has a red five in their hand

let success = game.play(game.currentPlayer, cardToPlay) // returns true if the card was played, false if it was not

//drawing cards. all functions below return true if they succeed

// draws one card for the current player
game.draw(game.currentPlayer)

// draws five cards for "player3"
game.draw(game.getPlayerByName("player3"), 5)
// draw three cards for player with id 2. (default starts at 0 and increments by 1)
game.draw(game.getPlayerById(2),3)

Configs

const { Game, Config } = require('uno-game-engine') 

let config = new Config()

config.setDefaultRotation("CW") // CCW (counter clock wise) or CW (clock wise)
    .setInitialCards(7) // how many cards each player starts with
    .setPlayersPerDeck(4) // how many players per deck of cards 
                          //(if more players are present, another deck (to draw from) will be created)

let game = new Game(["player1", "player2", "player3", "player4"], config)

// alternatively you can do this:
game = new Game(["player1", "player2", "..."], new Config().setInitialCards(7).setPlayersPerDeck(4))

Events

const { Game, events } = require('uno-game-engine')
let game = new Game(["Player 1", "Player 2"])

game.eventManager.addEvent(new events.PlayerPlayEvent((player, card) => {
    console.log(`${player} played ${card}`)
}))

game.eventManager.addEvent(new events.PlayerChangeEvent((oldPlayer, newPlayer) => {
    console.log(`It is now ${newPlayer}'s turn`)
}))

game.eventManager.addEvent(new events.PlayerDrawEvent((player, cards) => {
    console.log(`${player} drew ${cards.length} cards`)
}))

// manually fire an event

game.eventManager.fireEvent(events.PlayerChangeEvent.fire(game.currentPlayer, game.getNextPlayer()))

// making own events

let Event = events.Event // sadly you need this
class MyEvent extends Event {
    /**
     * i recommend doing this. but is it NOT required
     * @param {(something: number, somethingElse: string) => any} callback 
     * @param {boolean} once 
     */
    constructor(callback, once = false) {
        super(callback, "myEvent", once)
    }

    /**
     * i also recommend doing this
     * @param {number} something 
     * @param {string} somethingElse 
     * @returns 
     */
    static fire(something, somethingElse) {
        return new events.FireEvent("myEvent", something, somethingElse)
    }
}

// using own events

game.eventManager.addEvent(new MyEvent((something, somethingElse) => {
    // do something with it
    console.log(`something: ${something}, somethingElse: ${somethingElse}`)
}))

// fireing the event
game.eventManager.fireEvent(MyEvent.fire(1, "hello"))

More coming soon