From 7e4d0f52de206019e3e07860d27d84af959411b0 Mon Sep 17 00:00:00 2001 From: hitman Date: Wed, 30 Sep 2009 07:14:21 +0000 Subject: added rename.js --- diff --git a/examples/adding_up_to_10/js/rename.js b/examples/adding_up_to_10/js/rename.js new file mode 100644 index 0000000..29f039a --- /dev/null +++ b/examples/adding_up_to_10/js/rename.js @@ -0,0 +1,317 @@ +$(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 timerPaper, timerRect, + chimpPaper, normalChimp, sadChimp, happyChimp, + topLtBox, topRtBox, bottomLtBox, bottomMdBox, bottomRtBox; + var buttons=[]; + var stopTimer = false; + var chooseMe; + + var createBox = function (paperName) { + var set, paper, box; + paper = Raphael(paperName+"Paper", 200, 200); + set = paper.set(); + return { "paper": paper, "prefix": paperName, "set": set}; + }; + + 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