$(document).ready(function(){ var k = $.karma ({container: "#karma-main", lang: "en"}); k.init({ images: [ {name: "ball", file: "ball37px.png", localized : false }, {name: "balloon", file: "balloon37px.png", localized : false }, {name: "banana", file: "banana37px.png", localized : false }, {name: "chilli", file: "chilli.png", localized : false }, {name: "fish" , file: "fish64px.png", localized : false }, {name: "flower", file: "flower37px.png", localized : false }, {name: "normalChimp", file: "normalChimp_120x125.png", localized : false}, {name: "happyChimp", file: "happyChimp_120x125.png", localized: false}, {name: "sadChimp", file: "sadChimp_120x125.png", localized : false} ] , sounds: [ {name: "correct", file: "correct.ogg"}, {name: "incorrect", file: "incorrect.ogg"}, {name: "trigger", file: "trigger.ogg", localized: false} ], }); k.main(function() { var imgNames = ["ball", "banana", "balloon","chilli", "fish", "flower"]; //game logic var total, time, n0, n1, correct; var level = 0, d=160; var choices=[], score = 0, speed = 12000; var playerCorrect = 0, endTimerX = 80, startTimerY = 25, endTimerY = 100, offsetTimerY = 5; var overlayPaper, timerPaper, timerRect, chimpPaper, normalChimp, sadChimp, happyChimp, overlayBox, topLtBox, topRtBox, bottomLtBox, bottomMdBox, bottomRtBox; var buttons=[]; var stopTimer = false; var chooseMe; var createBox = function (paperName, width, height) { var set, paper, box; if(!width || !height){ paper = Raphael(paperName+"Paper", 200, 200); } else { paper = Raphael(paperName+"Paper", width, height); } set = paper.set(); return { "paper": paper, "prefix": paperName, "set": set}; }; overlayBox = createBox("overlay", 800, 600); topLtBox = createBox("topLt"); topRtBox = createBox("topRt"); bottomLtBox = createBox("bottomLt"); bottomMdBox = createBox("bottomMd"); bottomRtBox = createBox("bottomRt"); boxes = [ topLtBox, topRtBox, bottomLtBox, bottomMdBox, bottomRtBox]; sets = [topLtBox["set"], topRtBox["set"], bottomLtBox["set"], bottomMdBox["set"], bottomRtBox["set"]]; function game () { boxes.forEach(function (box) { box.set.remove(); }); total = k.math.rand( 2, 5 + level ); //the total n0 = total - k.math.rand(1, total - 1 ); //first number n1 = total - n0; //second number //chose one option (the correct option) //and then put the correct value into it correct = k.math.rand( 0, 2 ); choices[ correct ] = total; for (var i=0; i<3; i++) { //generate the two other options if ( choices[i] === total) { continue; } else { // generate the other options choices[ i ] = k.math.rand( 2, 10 ); for (var j = 0; j < i; j++){ if (choices[i] === choices[j]) { choices[ i ] = k.math.rand( 2, 10 ); } } } } var imgId = imgNames[ level ] ; var card = function (box, n, d) { var pos = []; var x, y, flag; var imgVarNames = {}; var prefix = box["prefix"]; imgVarNames[prefix] = []; box["set"] = box["paper"].set(); for (var i=0; i