Rock Paper Scissors
Basic customizable Javascript version of Rock Paper Scissors.
by blue1086
HTML
<span id="rel"></span>
JavaScript
!function(s){var o={};o={states:{},possible:[],teach:function(s,e){o.states[s]=e,o.possible.push(s)},load:function(){var e,t;for(e=0;e<o.possible.length;e+=1)s('<button class="option" value="'+o.possible[e]+'">'+o.possible[e]+"</button>").insertAfter("#rel"),s(".option").click(function(){t=o.possible[Math.floor(Math.random()*o.possible.length)],alert(o.states[t]===s(this).val()?"You Lose! The Computer Chose: "+t:t===s(this).val()?"Tie! The Computer Chose: "+t:"You Win! The Computer Chose: "+t)})}},window.system=o}(jQuery);
//Rules
/*
system.load() - Load Game
system.teach(a,b) - item a wins against item b (imagine comma as "beats")
*/
window.system.teach("Rock","Scissors");
window.system.teach("Scissors","Paper");
window.system.teach("Paper","Rock");
window.system.load();