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

simon-game

v1.3.0

Published

An API to use for building the Simon memory game.

Downloads

13

Readme

Simon

This is library that can be used for building a Simon web app (such as the one from Free Code Camp).

It features a simple API that you can easily plug into your application.

Install

$ npm install simon-game

Include This Library into Your Project

You can include this Tic Tac Toe module into your project by using either require or the ES6 import statement.

const simonGame = require('simon-game');
import simonGame from 'simon-game';

Simon Game

Set Up

When you require 'Simon' into your project, it gives you a function, which returns an instance of the Simon game. You can include two optional parameters: first is the number of possibilities (it defaults to 4), and the length of the initial series (this defaults to 20, per the requirements of the Free Code Camp project).

Example:

// If you want to go with the default configuration
const simon = simonGame();

or:

// If you want to make a more complex game of Simon with 8 possible moves and
// and a series length of 40
const simon = simonGame(8, 40);

Using the game

The game uses numbers in its pattern series, and when you initialize a game, it automatically configures a series.

To get the full series, call the getFullSeries method.

const simon = Simon();
// get the full series up front
simon.getFullSeries()
// [1, 2, 3, 2, 3, 4, 3, 1, 1, 1, 4, 4, 2, 3, 2, 2, 1, 1, 3, 2]

You can also get a totally different series with the newSeries method:

simon.newSeries()
simon.getFullSeries()
// [3, 1, 3, 2, 1, 4, 2, 1, 4, 3, 2, 2, 3, 2, 4, 1, 1, 2, 1, 3]

Once you've initialized your simon instance, you have access to the count, using the getCount method, and the current part of the series you're on, using the getCurrent method:

simon.getFullSeries()
// [3, 1, 3, 2, 1, 4, 2, 1, 4, 3, 2, 2, 3, 2, 4, 1, 1, 2, 1, 3]
simon.getCount()
// 1
simon.getCurrent()
// [3]

You can check user input for each move in the series with the checkGuess method, which will return a boolean:

simon.getCurrent()
// [3]
simon.checkGuess(3)
// true

You can get the number of guesses made in a try by calling the getGuesses method. It can be used to check against the series count:

simon.getGuesses()
// 0
simon.getCurrent()
// [3]
simon.checkGuess(3)
// true
simon.getGuesses()
// 1

You then call the next method, which updates both the count and the current series:

simon.getCount()
// 1
simon.getCurrent()
// [3]
simon.next()
simon.getCount()
// 2
simon.getCurrent()
// [3, 1]

You can check sequential user input again:

simon.getCurrent()
// [3, 1]
simon.checkGuess(3)
// true
simon.checkGuess(1)
// true

If the guess is incorrect, checkGuess returns false and resets the check iterator, so the user can retry the pattern:

simon.getCurrent()
// [3, 1, 3]
simon.checkGuess(3)
// true
simon.checkGuess(1)
// true
simon.checkGuess(1)
// false
simon.checkGuess(3)
// true
simon.checkGuess(1)
// true
simon.checkGuess(3)
// true

With checkGuess, the user must individually guess all answers in sequence.

As a simpler alternative to the iterative checkGuess method, you can check an entire series of guesses at once with the checkSeries method:

simon.getCurrent()
// [3, 1, 3, 2]
simon.checkSeries([3, 1, 3, 2])
// true

And that's it! You can decide when the user has won or lost. My goal was to create a simple library that holds the logic and state of a simple Simon app. You won't need to do any resets on state because as long as you are moving the game along and giving valid inputs, the main Simon module will keep track of the state for you.

Issues

If you find any issues or bugs with the game or want to request new features, please do so here.

Tests

(NOTE: requires mocha and chai)

$ npm test

License

The MIT License (MIT)

Copyright (c) 2017 Derek Shoemaker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.