Wondering what’s next for npm?Check out our public roadmap! »

    rpsjs

    1.0.0 • Public • Published

    RockPaperScissorsJS


    moved to RPSjs

    Table of content

    intro


    RockPaperScissorsJS is a javascript library that simplifies the making of the great rock paper scissors game and easy to use


    the package is made in a Javascript class format where your play will be considered an object

    Here is an example:
      const player = new Play('paper'); 
      //this creates a new object player and the action must be passed as an argument
      //the three actions are users guess which could be `rock`,`paper` or `scissors`
    
     console.log(player.Roll()); 
     //the Roll() function assigned is where everything is done mostly.

    the response or display on the console:

    [
       user: 'paper',
       computer: 'scissors',
       won: true
    ]

    in the above the user placed paper which we see from the argument passed on new play('paper') and the computers guess is randomly generated and from the result we get that paper loses to scissors and hence the result brings false meaning the user lost, incase of a win it would be true and incase of draw it would be draw.

    getting started


    getting started you will first require the library which can be done by using the script tags

       <script src="./path/to/rockPaperScissors.JS"> </script>// get the library from the path where it's located

    or if you are using a CDN then you can use the following

       <script src="https://cdn.jsdelivr.net/npm/rockpaperscissorsjs@1.1.0/rockPaperScissors.min.js"></script> 

    the import is still not fully functional

    place the CDN link onto the header


    then crate an object to use

        const player = new Play();// you can name it anything other than player

    you can find the demos here

    using the functions

    there are three functions;

           Roll(user)//argument are not required 
           Compute()
           Won(user, computer)// required!

    Note that the functions beggin with a capital letter.

    Roll

    from the above example you can see that the Roll() function did everything for us without us doing anything. the Roll() function requires no parameters if you stated it when making the Object.
    Example 1:

      const player = new Play('rock');// user guess in this case is rock
      console.log(player.Roll());// since user guess was passed on the object there is no need to redo that again

    Example 2:

       const player = new Play();// user guess not passed
      console.log(player.Roll('paper'));

    Example 1 output could be:
        [
           user: rock,
           computer: scissors,
           won: true
        ]

    Example 2 output could be:

        [
           user: paper,
           computer: paper,
           won: draw
        ]

    the computer guess is randomly made

    Compute


    the compute() function will help you if you would like to get a random guess for the computer;
    Example:

    const player = new Play();
    let button = document.getElementById('computer-guess');
    button.addEventListener('click', function(){
        console.log('The computer guess is: '+player.Compute());
    })

    Example of output:
    The computer guess is: rock

    you can do a lot more with this just check the examples here

    won

           Won(user, computer)          

    This function determines the winner where the data passed
    required arguments are user and computer guess or trows eg. rock or paper or scissors

    it will to be like

          player.Won('rock','scissors')// user= rock and computer=scissors
          player.Won('paper','paper')// user= paper and computer=paper
          player.Won('scissors','rock')// user=scissors  and computer=rock

    Example:

         const player = new Play();
    
            console.log(player.Won('rock','scissors'))// user= rock and computer=scissors
            console.log(player.Won('scissors','scissors'))// user= scissors and computer=scissors
            console.log(player.Won('scissors','rock'))// user=scissors  and computer=rock 

    output:

           true
           draw
           false

    passing numbers is still supported but not required

    extra


    this are just some extras

    • you can clone this on github and if you would like to Contribute you can send a pull request and I will check it out and see if I can marge it.
    • creator bethropolis;

    License


    Licensed under my favourate License, MIT License.

    Install

    npm i rpsjs

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    7.89 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar