// wait until the page is finished loading
$(document).ready(function() {
var nameArray = ["Bow & Arrow", "Tiger", "Human", "Water", "Fire"];
var BOW = 0;
var TIGER = 1;
var HUMAN = 2;
var WATER = 3;
var FIRE = 4;
var WON = 0;
var DRAW = 1;
var LOST = 2;
function move(){
var player1 = parseInt($(this).attr('player'));
var player2 = getRandomInt(0,4);
var outcome = battle(player1, player2);
$('#you').text(getName(player1));
$('#computer').text(getName(player2));
$('#stuff').text(getOutcomeText(outcome));
$("#pwned").addClass("battle_over");
switch(outcome){
case WON: $("#pwned").addClass("won");
break;
case LOST: $("#pwned").addClass("lost");
break;
case DRAW: $("#pwned").addClass("draw");
break;
}
}
function getOutcomeText(outcome)
{
switch(outcome){
case WON: return "won against";
case LOST: return "lost against";
case DRAW: return "had a draw";
}
}
function battle(player1, player2){
//alert(getName(player1) + " vs " + getName(player2));
// if the computer generated the same, then we have a draw
if(player1 == player2) return DRAW;
// did we win or lose?
switch(player1){
case BOW:
if(player2 == TIGER || player2 == HUMAN) return WON;
return LOST;
case TIGER:
if(player2 == HUMAN || player2 == WATER) return WON;
return LOST;
case HUMAN:
if(player2 == WATER || player2 == FIRE) return WON;
return LOST;
case WATER:
if(player2 == FIRE || player2 == BOW) return...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.