Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhitman <bryan@olenepal.org>2009-10-01 02:37:16 (GMT)
committer hitman <bryan@olenepal.org>2009-10-01 02:37:16 (GMT)
commit46a36a27fff8205893571a80dae11c1b886724f7 (patch)
tree49da5a9da3473b56f49b33ec098ab30f5b20e070
parent52bfde0e45ad3afcade398340effc1263105f325 (diff)
completed renaming adding_up according to dojo style conventions. Also
fixed problem where sometimes and correct answer displayed in two different cards.
-rwxr-xr-xcss/karma.css3
-rwxr-xr-xexamples/adding_up_to_10/css/lesson.css50
-rwxr-xr-xexamples/adding_up_to_10/index.html51
-rwxr-xr-xexamples/adding_up_to_10/js/lesson.js264
-rw-r--r--examples/adding_up_to_10/js/rename.txt11
5 files changed, 188 insertions, 191 deletions
diff --git a/css/karma.css b/css/karma.css
index 0135a5e..bce5ee2 100755
--- a/css/karma.css
+++ b/css/karma.css
@@ -19,6 +19,3 @@ karma loader
}
}
-.canvas {
-
-} \ No newline at end of file
diff --git a/examples/adding_up_to_10/css/lesson.css b/examples/adding_up_to_10/css/lesson.css
index f96d0ba..6ef7e3e 100755
--- a/examples/adding_up_to_10/css/lesson.css
+++ b/examples/adding_up_to_10/css/lesson.css
@@ -3,31 +3,30 @@
width:800px;
height:600px;
position:absolute;
-opacity: 1;
}
-#action {
+
+#main {
float:left;
position:relative;
width: 650px;
height: 600px;
}
-#sidebar {
+#side {
background-image: url(../assets/generic/images/sidebar.png);
--moz-background-clip:border;
--moz-background-inline-policy:continuous;
--moz-background-origin:padding;
background:none none repeat scroll 0 0;
float:left;
height:600px;
position:relative;
width:150px;
}
-#actionTop {
+
+#top {
width: 650px;
height: 300px;
position:relative;
}
+
#bottom {
clear:both;
float:left;
@@ -35,32 +34,26 @@ width: 650px;
height: 300px;
position:relative;
}
-#topLtSide {
+#topLeftArea {
float:left;
width: 300px;
height: 300px;
position:relative;
}
-#topMd {
--moz-background-clip:border;
--moz-background-inline-policy:continuous;
--moz-background-origin:padding;
+#topMiddleArea {
background:none none repeat scroll 0 0;
float:left;
width: 50px;
height: 300px;
position:relative;
}
-#topRtSide {
+#topRightArea {
float:left;
width: 300px;
height:300px;
position:relative;
}
-#topLtBox {
--moz-background-clip:border;
--moz-background-inline-policy:continuous;
--moz-background-origin:padding;
+#topLeftCard {
background:none none repeat scroll 0 0;
width: 200px;
height: 200px;
@@ -69,10 +62,7 @@ position:absolute;
top:50px;
}
-#topLtPaper {
--moz-background-clip:border;
--moz-background-inline-policy:continuous;
--moz-background-origin:padding;
+#topLeftPaper {
background:none none repeat scroll 0 0;
position:absolute;
top: 50px;
@@ -80,13 +70,14 @@ left: 75px;
width:200px;
height:200px;
}
-#plussign {
+
+#plusSign {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 150px;
}
-#topRtBox {
+#topRightCard {
background: none none repeat scroll 0 0;
width: 200px;
height: 200px;
@@ -94,7 +85,7 @@ position:absolute;
right: 50px;
top: 50px;
}
-#topRtPaper {
+#topRightPaper {
background:none none repeat scroll 0 0;
position:absolute;
left: 50px;
@@ -105,9 +96,6 @@ height:200px;
}
.bottom {
--moz-background-clip:border;
--moz-background-inline-policy:continuous;
--moz-background-origin:padding;
background:none none repeat scroll 0 0;
float:left;
width: 216.5px;
@@ -115,7 +103,7 @@ height: 300px;
position:relative;
}
-.bottomBox {
+.bottomCard {
left:25px;
position:absolute;
width: 200px;
@@ -124,7 +112,7 @@ position:relative;
}
-.sidebarItem {
+.sideItem {
clear:both;
float:left;
width:150px;
@@ -148,7 +136,7 @@ top:10px;
left:25px;
}
-#scorebox {
+#scoreBox {
position:absolute;
width:100px;
height:150px;
@@ -157,7 +145,7 @@ left:25px;
z-index: 10;
}
-#scoreboxText {
+#scoreBoxText {
position:relative;
top:60px;
font: 70px Arial;
diff --git a/examples/adding_up_to_10/index.html b/examples/adding_up_to_10/index.html
index 69dcfc7..2f769b8 100755
--- a/examples/adding_up_to_10/index.html
+++ b/examples/adding_up_to_10/index.html
@@ -19,52 +19,51 @@
<body>
<div id="karma-main">
- <div id="action">
- <div id="actionTop">
+ <div id="main">
+ <div id="top">
- <div id="topLtSide">
- <img id="topLtBox" src="assets/generic/images/yellowBox.png" alt="" />
- <div id="topLtPaper" ></div>
+ <div id="topLeftArea">
+ <img id="topLeftCard" src="assets/generic/images/yellowBox.png" alt="" />
+ <div id="topLeftPaper" ></div>
</div>
- <div id="topMd">
- <img id="plussign" src="assets/generic/images/plussign.png" alt=""/>
+ <div id="topMiddleArea">
+ <img id="plusSign" src="assets/generic/images/plussign.png" alt=""/>
</div>
- <div id="topRtSide">
- <img id="topRtBox" src="assets/generic/images/yellowBox.png" alt=""/>
- <div id="topRtPaper"></div>
+ <div id="topRightArea">
+ <img id="topRightCard" src="assets/generic/images/yellowBox.png" alt=""/>
+ <div id="topRightPaper"></div>
</div>
</div>
<div id="bottom">
- <!-- <div id="bottomPaper"></div> -->
- <div id="bottomLt" class="bottom">
- <img class="bottomBox" src="assets/generic/images/yellowBox.png" alt=""/>
- <div id="bottomLtPaper" class="bottomBox"> </div>
+ <div id="bottomLeft" class="bottom">
+ <img class="bottomCard" src="assets/generic/images/yellowBox.png" alt=""/>
+ <div id="bottomLeftPaper" class="bottomCard"> </div>
</div>
- <div id="bottomMd" class="bottom">
- <img class="bottomBox" src="assets/generic/images/yellowBox.png" alt=""/>
- <div id="bottomMdPaper" class="bottomBox"> </div>
+ <div id="bottomMiddle" class="bottom">
+ <img class="bottomCard" src="assets/generic/images/yellowBox.png" alt=""/>
+ <div id="bottomMiddlePaper" class="bottomCard"> </div>
</div>
- <div id="bottomRt" class="bottom">
- <img class="bottomBox" src="assets/generic/images/yellowBox.png" alt=""/>
- <div id="bottomRtPaper" class="bottomBox"> </div>
+ <div id="bottomRight" class="bottom">
+ <img class="bottomCard" src="assets/generic/images/yellowBox.png" alt=""/>
+ <div id="bottomRightPaper" class="bottomCard"> </div>
</div>
</div>
</div>
- <div id="sidebar">
- <div class="sidebarItem">
+ <div id="side">
+ <div class="sideItem">
<img id="timer" src="assets/generic/images/scorebox.png" alt=""/>
<div id="timerPaper"> </div>
</div>
- <div class="sidebarItem">
- <img id="scorebox" src="assets/generic/images/scorebox.png" alt=""/>
- <div id="scoreboxText"></div>
+ <div class="sideItem">
+ <img id="scoreBox" src="assets/generic/images/scorebox.png" alt=""/>
+ <div id="scoreBoxText"></div>
</div>
- <div class="sidebarItem">
+ <div class="sideItem">
<div id="chimpPaper"> </div>
<div id="buttons">
<button id="start">Start</button>
diff --git a/examples/adding_up_to_10/js/lesson.js b/examples/adding_up_to_10/js/lesson.js
index c2393c7..2331fd1 100755
--- a/examples/adding_up_to_10/js/lesson.js
+++ b/examples/adding_up_to_10/js/lesson.js
@@ -28,22 +28,29 @@ $(document).ready(function(){
k.main(function() {
- var imgNames = ["ball", "banana", "balloon","chilli", "fish", "flower"];
+ var imageNames = ["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 cards;
+ var totalCorrect = 0, n0 = 0, n1 = 0, correctCard = 0,
+ level = 0, score = 0, numCorrectAnswers = 0;
+ var DRAW_MAX_X = 170, DRAW_MAX_Y = 170;
+ var choices=[0, 0, 0]
+ var timerSpeed = 12000;
+ var START_TIMER_Y = 25, END_TIMER_Y = 125;
+ var timerPaper, chimpPaper;
+ var timerRect;
+ var normalChimpImage, sadChimpImage, happyChimpImage;
+ var overlayCard, topLeftCard, topRightCard, bottomLeftCard,
+ bottomMiddleCard, bottomRightCard;
+
var buttons=[];
- var stopTimer = false;
- var chooseMe;
+ var isTimerRunning = false;
+ var dispatchChoice;
+
+ var createCard = function (paperName, width, height) {
+ var set;
+ var paper;
- var createBox = function (paperName, width, height) {
- var set, paper;
if(!width || !height){
paper = Raphael(paperName+"Paper", 200, 200);
}
@@ -55,144 +62,148 @@ k.main(function() {
};
- overlayBox = createBox("overlay", 800, 600);
- topLtBox = createBox("topLt");
- topRtBox = createBox("topRt");
- bottomLtBox = createBox("bottomLt");
- bottomMdBox = createBox("bottomMd");
- bottomRtBox = createBox("bottomRt");
+ overlayCard = createCard("overlay", 800, 600);
+ topLeftCard = createCard("topLeft");
+ topRightCard = createCard("topRight");
+ bottomLeftCard = createCard("bottomLeft");
+ bottomMiddleCard = createCard("bottomMiddle");
+ bottomRightCard = createCard("bottomRight");
- boxes = [ topLtBox, topRtBox, bottomLtBox,
- bottomMdBox, bottomRtBox];
+ cards = [ topLeftCard, topRightCard, bottomLeftCard,
+ bottomMiddleCard, bottomRightCard];
- sets = [topLtBox["set"], topRtBox["set"], bottomLtBox["set"],
- bottomMdBox["set"], bottomRtBox["set"]];
+ sets = [topLeftCard["set"], topRightCard["set"], bottomLeftCard["set"],
+ bottomMiddleCard["set"], bottomRightCard["set"]];
- function game () {
- boxes.forEach(function (box) {
+ function drawCards () {
+ var imageId = imageNames[ level ] ;
+ //reinitialize choices to zero
+ choices = [0, 0, 0];
+
+ cards.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
+ totalCorrect = k.math.rand( 2, 5 + level ); //the totalCorrect
+ n0 = totalCorrect - k.math.rand(1, totalCorrect - 1 ); //first number
+ n1 = totalCorrect - 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;
+ correctCard = k.math.rand( 0, 2 );
+ choices[ correctCard ] = totalCorrect;
+
+ var computeUniqueChoice = function(choice){
+ var newChoice = 0;
+ if (choice === totalCorrect) {
+ return choice;
} 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 );
- }
- }
+ newChoice = k.math.rand( 1, 10 );
+ if (newChoice === totalCorrect){
+ return computeUniqueChoice(choice);
+ } else {
+ return newChoice;
+ }
}
- }
-
- var imgId = imgNames[ level ] ;
+ };
+ choices = choices.map(computeUniqueChoice);
- 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();
+ var drawCard = function (card, n) {
+ var positions = [];
+ var x = 0, y = 0;
+ var isOverlapping = false;
+ var imageVarNames = {};
+ var varPrefix = card["prefix"];
+ imageVarNames[varPrefix] = [];
+ card["set"] = card["paper"].set();
for (var i=0; i<n; i++) {
do {
- flag = false;
- x = k.math.rand( 0, d);
- y = k.math.rand( 0, d );
- for ( var j=0; j<pos.length; j++) {
- if ( k.geometry.distance2( pos[j],
+ isOverlapping = false;
+ x = k.math.rand( 0, DRAW_MAX_X);
+ y = k.math.rand( 0, DRAW_MAX_Y );
+ for ( var j=0; j<positions.length; j++) {
+ if ( k.geometry.distance2( positions[j],
{"x": x, "y": y} ) < 135 ) {
- flag = true;
+ isOverlapping = true;
break;
}
}
- }while ( flag === true );
- pos.push( { "x":x, "y": y } );
- imgVarNames[prefix][i] = box["paper"].image(k.library.images[imgId].src, x , y, 35, 35);
- box["set"].push(imgVarNames[prefix][i]);
+ }while ( isOverlapping === true );
+ positions.push( { "x":x, "y": y } );
+ imageVarNames[varPrefix][i] = card["paper"].
+ image(k.library.images[imageId].src, x , y, 35, 35);
+ card["set"].push(imageVarNames[varPrefix][i]);
}
}
//put the cards
- card(topLtBox, n0, 160);
- card(topRtBox, n1 , 160);
- card(bottomLtBox, choices[ 0 ], 160);
- card(bottomMdBox, choices[ 1 ] , 160);
- card(bottomRtBox, choices[ 2 ] , 160);
+ drawCard(topLeftCard, n0);
+ drawCard(topRightCard, n1);
+ drawCard(bottomLeftCard, choices[ 0 ]);
+ drawCard(bottomMiddleCard, choices[ 1 ]);
+ drawCard(bottomRightCard, choices[ 2 ]);
}
//put the buttons on the cards
- buttons[ 0 ] = { node: $('#bottomLtPaper')[0], num: 0};
- buttons[ 1 ] = { node: $('#bottomMdPaper')[0], num: 1};
- buttons[ 2 ] = { node: $('#bottomRtPaper')[0], num: 2};
+ buttons[ 0 ] = { node: $('#bottomLeftPaper')[0], num: 0};
+ buttons[ 1 ] = { node: $('#bottomMiddlePaper')[0], num: 1};
+ buttons[ 2 ] = { node: $('#bottomRightPaper')[0], num: 2};
var addButtons = function(){
buttons.forEach(function(button) {
- var buttonNum = button.num;
- button.node.addEventListener('click', function chooseMe(){
- var mybutton = buttonNum
- choose (mybutton);}, false);
+ var numButton = button.num;
+ button.node.addEventListener('click', function dispatchChoice(){
+ var myButton = numButton;
+ chooseCard (myButton);}, false);
});
};
var removeButtons = function(){
buttons.forEach(function(button) {
- button.node.removeEventListener('click', chooseMe, false);
+ button.node.removeEventListener('click', dispatchChoice, false);
});
};
- var choose = function(buttonNum) {
- if ( choices[buttonNum] === total){
+ var chooseCard = function(numButton) {
+ if ( choices[numButton] === totalCorrect){
//If the player has completed all the levels
- if (playerCorrect === 4 && level === 5) {
+ if (numCorrectAnswers === 4 && level === 5) {
congrats();
} else {
- answer(true, false);
+ computeScore(true, false);
resetTimer();
animateTimer();
- game();
+ drawCards();
}
}else {
- answer(false, false);
+ computeScore(false, false);
resetTimer();
animateTimer();
- game();
+ drawCards();
}
};
- var writeScore = function (newscore){
- $('#scoreboxText')[0].innerHTML = newscore;
+ var writeScore = function (newScore){
+ $('#scoreBoxText')[0].innerHTML = newScore;
};
- var answer = function (correct, tooSlow) {
+ var computeScore = function (correct, tooSlow) {
if ( correct === false) {
//answer was incorrect or took too long
score = score - 1;
- playerCorrect = playerCorrect - 1;
+ numCorrectAnswers = numCorrectAnswers - 1;
writeScore(score);
if (tooSlow === true) {
k.library.sounds[ "trigger" ].play();
@@ -204,14 +215,14 @@ k.main(function() {
} else {
score = score + 1;
- playerCorrect = playerCorrect + 1;
+ numCorrectAnswers = numCorrectAnswers + 1;
writeScore(score);
k.library.sounds[ "correct" ].play();
animateChimp(true);
- if (playerCorrect == 5){
+ if (numCorrectAnswers == 5){
level = level + 1;
- speed = speed - 1000;
- playerCorrect = 0;
+ timerSpeed = timerSpeed - 1000;
+ numCorrectAnswers = 0;
}
}
@@ -220,11 +231,11 @@ k.main(function() {
};
- var start = function () {
+ var startGame = function () {
score = 0;
writeScore(score);
addButtons();
- stopTimer = false;
+ isTimerRunning = true;
//move timer back to start in case it is
//already running
@@ -233,44 +244,45 @@ k.main(function() {
//start timer
animateTimer();
- game();
+ drawCards();
};
- var stop = function () {
+ var stopGame = function () {
writeScore(' ');
removeButtons();
//stop timer
- stopTimer = true;
+ isTimerRunning = false;
resetTimer();
//clear the cards
- boxes.forEach(function (box) {
- box.set.remove();
- box.set = box.paper.set();
+ cards.forEach(function (card) {
+ card.set.remove();
+ card.set = card.paper.set();
});
};
- var reset = function () {
+ var resetGame = function () {
score = 0;
writeScore(score);
- stopTimer = false;
+ isTimerRunning = true;
resetTimer();
animateTimer();
- game();
+ drawCards();
};
var resetTimer = function () {
- timerRect.animate({y: startTimerY}, 0);
+ timerRect.animate({y: START_TIMER_Y}, 0);
};
var animateTimer = function () {
- timerRect.animate({y: 130}, speed, function(){
- timerRect.attr("y", startTimerY);
- if (stopTimer === false){
- answer(false, true);
+ timerRect.animate({y : END_TIMER_Y}, timerSpeed, function(){
+ timerRect.attr("y", START_TIMER_Y);
+ if (isTimerRunning === true){
+ computeScore(false, true);
animateTimer();
+ drawCards();
}
});
};
@@ -278,68 +290,68 @@ k.main(function() {
var animateChimp = function (answer) {
var timerChimp;
- normalChimp.hide();
+ normalChimpImage.hide();
if( answer === true){
- happyChimp.show();
+ happyChimpImage.show();
} else {
- sadChimp.show();
+ sadChimpImage.show();
}
timerChip = setTimeout(function() {
- happyChimp.hide();
- sadChimp.hide();
- normalChimp.show();}, 800);
+ happyChimpImage.hide();
+ sadChimpImage.hide();
+ normalChimpImage.show();}, 800);
};
var congrats = function () {
var congratsText;
- stop();
+ stopGame();
$('#overlayPaper').css({"position": "absolute",
"background": "white", "opacity": "0.8",
"z-index": "100"});
- congratsChimp = overlayBox.paper.image(
+ congratsChimp = overlayCard.paper.image(
k.library.images["happyChimp"].src, 200, 100, 300, 400);
congratsChimp.attr({"fill-opacity": "1", "opacity": "1"});
- congratsText = overlayBox.paper.text(400, 550, "Great Job!");
+ congratsText = overlayCard.paper.text(400, 550, "Great Job!");
congratsText.attr({"font-size": 80});
- overlayBox.set.push(congratsChimp, congratsText);
+ overlayCard.set.push(congratsChimp, congratsText);
congratsChimp.node.addEventListener('click', function(){
$('#overlayPaper').css({"opacity": 0});
- overlayBox.set.remove();
+ overlayCard.set.remove();
}, false);
};
document.getElementById('start').
- addEventListener('click', start, false);
+ addEventListener('click', startGame, false);
document.getElementById('stop').
- addEventListener('click', stop, true);
+ addEventListener('click', stopGame, true);
document.getElementById('reset').
- addEventListener('click', reset, false);
+ addEventListener('click', resetGame, false);
//set up the timer
timerPaper = Raphael('timerPaper', 100, 150);
- timerRect = timerPaper.rect(7, 25, 85, 20, 3);
+ timerRect = timerPaper.rect(7, START_TIMER_Y, 85, 20, 3);
timerRect.attr('fill', "#fff");
//Set up the monkeys
chimpPaper = Raphael('chimpPaper', 120, 125);
- normalChimp = chimpPaper.image(k.library.images["normalChimp"].src,
+ normalChimpImage = chimpPaper.image(k.library.images["normalChimp"].src,
0, 20, 100, 100);
- sadChimp = chimpPaper.image(k.library.images["sadChimp"].src,
+ sadChimpImage = chimpPaper.image(k.library.images["sadChimp"].src,
0, 20, 100, 100);
- happyChimp = chimpPaper.image(k.library.images["happyChimp"].src,
+ happyChimpImage = chimpPaper.image(k.library.images["happyChimp"].src,
0, 20, 100, 100);
- happyChimp.hide();
- sadChimp.hide();
+ happyChimpImage.hide();
+ sadChimpImage.hide();
diff --git a/examples/adding_up_to_10/js/rename.txt b/examples/adding_up_to_10/js/rename.txt
index 500bec1..155c17a 100644
--- a/examples/adding_up_to_10/js/rename.txt
+++ b/examples/adding_up_to_10/js/rename.txt
@@ -7,13 +7,14 @@ div id="topLtSide" --- topLeftArea
img id="topLtBox" --- topLeftCard
div id="topLtPaper" --- topLeftPaper
div id="topMd" --- topMiddleArea
-img id="plussign" --- plusImage
+img id="plussign" --- plusSign
div id="topRtSide" --- topRightArea
img id="topRtBox" --- topRightCard
div id="topRtPaper" --- topRightPaper
div id="bottom" --- bottom
+class="bottom" --- bottom
div id="bottomLt" --- bottomLeft
-img class="bottomBox" --- bottomCards
+img class="bottomBox" --- bottomCard
div id="bottomLtPaper" class="bottomBox" --- bottomLeftPaper, bottomCard
div id="bottomMd" class="bottom" --- bottomMiddle, bottomAreas
img class="bottomBox" --- bottomCards
@@ -80,7 +81,7 @@ library.images
var buttons=[];
var stopTimer = false; -- isTimerActive
- var chooseMe; --- dispatchCardChoice
+ var chooseMe; --- dispatchChoice
var createBox = function (paperName) { ---- createCard
var set, paper; ---
@@ -90,12 +91,12 @@ library.images
};
- function game () { ---- setCards()
+ function game () { ---- drawCards()
var imgId = imgNames[ level ] ; --- imgId
- var card = function (box, n, d) { ---- setCard()
+ var card = function (box, n, d) { ---- drawCard()
var pos = []; --- positions
var x, y, flag; ---- flag -- isOverlapping
var imgVarNames = {};