Git Product home page Git Product logo

matchmaking's Introduction

Matchmaking

Matchmaking will help you to create matches in games, chats or anything else you can imagine!

Installing

npm i matchmaking

How to use

Api reference

LobbyMaker

Create, list and join lobbies They can have password or be private (joined by name or id) With the third argument in the constructor you can customize the lobby settings

const { LobbyMaker } = require('matchmaking');

function runGame(players) {
  console.log("Game started with:");
  console.log(players);
}

function getPlayerKey(player){
  return player.id;
}

let lobby = new LobbyMaker(runGame, getPlayerKey);

let player1 = { id:20 }
let player2 = { id:21 }

// Create a room
let id = lobby.createLobby(player1, "Room 0");

// A player joined the room!
lobby.joinRoom(id, player2);

// Lets start the game
lobby.start(id);

// Game started with:
// [ {id:20}, {id:21} ]

FifoMatchMaker

This one is really simple, just push players to the queue, and games will be started automatically!

const { FifoMatchmaker } = require('matchmaking');

function runGame(players) {
  console.log("Game started with:");
  console.log(players);
}

let mm = new FifoMatchmaker(runGame, { checkInterval: 2000 });

let player1 = { id:1 }
let player2 = { id:2 }

// Players join match queue
mm.push(player1);
mm.push(player2);

// When there are enough players, runGame will be called

// Game started with:
// [ {id:1}, {id:2} ]

Author

  • Lui Franco Rocha

License

This project is licensed under the MIT License - see the LICENSE.md file for details

matchmaking's People

Contributors

luifr avatar luipronto 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.