Skip to content

Instantly share code, notes, and snippets.

@nicinabox
Last active September 23, 2016 01:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicinabox/42f4350783239dfe6c48 to your computer and use it in GitHub Desktop.
Save nicinabox/42f4350783239dfe6c48 to your computer and use it in GitHub Desktop.
A simple game of rock, paper, scissors
// var rps = new Roshambo(shape)
// console.log(rps.outcome());
(function() {
'use strict';
var Roshambo, random;
random = function (min, max) {
return min + Math.floor(Math.random() * (max - min + 1));
};
Roshambo = function(input) {
this.playerA = input || 0;
this.playerB = random(0, 2);
this.result = this.fight();
return this;
};
Roshambo.prototype = {
shapes: [
'rock', 'paper', 'scissors'
],
outcomes: [
'Draw!', 'You won!', 'You lost!'
],
fight: function() {
return (3 + this.playerA - this.playerB) % 3;
},
outcome: function() {
return this.outcomes[this.result];
}
};
if (module && module.exports) {
module.exports = Roshambo;
} else {
window.Roshambo = Roshambo;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment