The canonical rock-paper-scissors-lizard-spock library.
npm i --save rpsls
The default export is a class with only static members.
The class will contain the following static members. See the explanation for each member in the sections below.
The five moves in the game are accessed via static getters. They are aliases for the number 0 through 4.
The three outcomes of the game are static getters. They are aliases for the numbers 0, 1, and 2.
play method requires two parameters that represent the moves for player 1 and player 2 respectively.
An object will be returned with the details of the game.
The structure of the return object varies slightly depending upon whether the game is a tie or not.
Returned object for a TIE
let game = R;//game will look like thisoutcome: 0 //TIEresult: "rock vs rock is a tie"
Returned object for a NON-TIE
let game = R;//game will look like thisoutcome: 2 //PLAYER2winner: 3 //LIZARDloser: 4 //SPOCKmethod: 'poisons'result: 'lizard poisons spock'
getMoveName method takes a single parameter that represents a move. A string will be returned that is the readable name of the given move.
R; //'spock'R; //'spock'
getMoveName with throw an error if anything besides the integer numeric values of
0, 1, 2, 3, 4 are passed to them.
R; //errorR; //errorR; //errorR; //errorR; //errorR; //errorR; //errorR; //error
This serves as a reminder to myself of how to develop this project.
- clone repo
- npm i
- npm run typings
- edit .ts/.spec.ts
- npm run build
- npm test
- update npm version