rockpaperscissorsjs
Version:
ready made package to help you with your rock paper scissors project.
177 lines (140 loc) • 5.05 kB
Markdown
# RockPaperScissorsJS
---
>moved to [RPSjs](https://www.npmjs.com/package/rpsjs)
## Table of content
* [intro](#intro)
* [getting started](#getting-started)
* [roll](#roll)
* [compute](#compute)
* [won](#won)
* [extras](#extras)
* [License](#license)
## intro
---
<p>RockPaperScissorsJS is a javascript library that simplifies the making of the great rock paper scissors game and easy to use</p><br>
<p> the package is made in a Javascript class format where your <b>play</b> will be considered an object</p>
Here is an example:
```js
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:
```js
[
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
```html
<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
```html
<script src="https://cdn.jsdelivr.net/npm/rockpaperscissorsjs@1.1.0/rockPaperScissors.min.js"></script>
```
> the import is still not fully functional <br>
> place the CDN link onto the header
<br>
then crate an object to use
```js
const player = new Play();// you can name it anything other than player
````
> you can find the demos [here](bethropolis.github.io/rockPaperScissorsJS)<br>
### using the functions
there are three functions;
```js
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.<br>
Example 1:
```js
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:
```js
const player = new Play();// user guess not passed
console.log(player.Roll('paper'));
```
<br>
Example 1 output could be:
```js
[
user: rock,
computer: scissors,
won: true
]
```
Example 2 output could be:
```js
[
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;<br>
Example:
```js
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:<br>
` The computer guess is: rock`
<br>
you can do a lot more with this just check the examples [here](bethropolis.github.io/rockPaperScissorsJS)<br>
### won
```js
Won(user, computer)
```
This function determines the winner where the data passed <br>
required arguments are `user` and `computer` guess or trows eg. `rock` or `paper` or `scissors`<br>
<br>
it will to be like
```js
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:
```js
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:
```js
true
draw
false
```
> passing numbers is still supported but not required
## extra
---
this are just some extras
* you can clone this on [github](https://github.com/bethropolis/rockPaperScissorsJS) 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](https://twitter.com/bethropolis);
## License
---
Licensed under my favourate License, MIT License.