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

@hitomihiumi/2048-game

v1.0.2

Published

simple 2048 game module, using lazy-canvas

Downloads

1

Readme

Introduction

This is a simple logic and rendering module for the game 2048, it is mainly intended for users of discord.js etc. The module uses @hitomihiumi/lazy-canvas to render the image.

Get Started

  1. Install the module by using npm i @hitomihiumi/2048-game
  2. Enjoy!

Documentation

You can find the documentation here

Game - class

Initialize class to create a new game.

const { Game } = require('@hitomihiumi/2048-game');

const game = new Game()

Methods - functions

setUser()

game.setUser('1111111111')

Used just for identify game, not used in module

setSize()

game.setSize(6)

Set the size of the game board. The default value is 4.

startGame()

await game.startGame(); 

Returns object with 'status' and canvas buffer. You can use this buffer in AttachmentBuilder (for discord.js), or save it to file by 'fs'.

move()

await game.move('up'); // Move the tiles up
await game.move('down'); // Move the tiles down
await game.move('left'); // Move the tiles left
await game.move('right'); // Move the tiles right

Returns object with 'status' and 'canvas' properties. 'status' is a string, 'canvas' is a canvas buffer. 'status' can be 'start', 'win', 'gameover', 'nochange' or 'move'.

reset()

game.reset();

Resets the game, use 'startGame()' to start a new one.

step()

game.step();

Returns the number of steps taken in the game.

score()

game.score();

Returns the current score in the game.

userId()

game.userId();

Returns the user id.

exportData()

game.exportData();

Returns the game data in JSON format.

importData()

game.importData(data);

Imports the game data in JSON format.

Customization

You can customize the game by changing the following properties:

setColors()

game.setColors({
    '0': '#191919',
    '2': '#A151DD',
    '4': '#A045BF',
    '8': '#9F39A1',
    '16': '#9E2D83',
    '32': '#9D2165',
    '64': '#9C1547',
    '128': '#A71D42',
    '256': '#BD3854',
    '512': '#D35366',
    '1024': '#E96E78',
    '2048': '#FF8A8A',
});

Set the colors of the tiles. '0' is the background color.

setFont()

const { Font } = require('@hitomihiumi/lazy-canvas');

game.setFont(
    new Font()
    .setFamily('Koulen')
    .setWeight('regular')
    .setPath('./fonts/Koulen-Regular.ttf')
);

Set the font of the text. Use @hitomihiumi/lazy-canvas to create a new font.

setOffsets()

game.setOffsets({
    '2': { x: 0, y: 0 },
    '4': { x: 0, y: 0 },
    '8': { x: 0, y: 0 },
    '16': { x: 0, y: 0 },
    '32': { x: 0, y: 0 },
    '64': { x: 0, y: 0 },
    '128': { x: 0, y: 0 },
    '256': { x: 0, y: 0 },
    '512': { x: 0, y: 0 },
    '1024': { x: 0, y: 0 },
    '2048': { x: 0, y: 0 },
});

Sets the x- and y-axis offsets for the numbers individually. If you need to set the offset for all digits at once, use setGlobalOffset().

setGlobalOffset()

game.setGlobalOffset({ x: 0, y: 0 });

Sets the x- and y-axis offsets for all numbers at once.

setLineThickness()

game.setLineThickness(5);

Sets the thickness of the cell number stroke line. The default value is 4.

setFilled()

game.setFilled(true);

Sets whether the cell number is filled or not. The default value is false.