diff options
author | Bryan Berry <bryan@olenepal.org> | 2010-03-15 08:43:52 (GMT) |
---|---|---|
committer | Bryan Berry <bryan@olenepal.org> | 2010-03-15 08:43:52 (GMT) |
commit | d03552a31d2b63b42084ae506fc94e6149a5440a (patch) | |
tree | 76608ccbe04fb941c9e4b69a205c957d29ac4b95 /English_Animal_Identification/js |
initial commit
Diffstat (limited to 'English_Animal_Identification/js')
-rwxr-xr-x | English_Animal_Identification/js/lesson.js | 159 | ||||
-rwxr-xr-x | English_Animal_Identification/js/lesson.js~ | 191 | ||||
-rwxr-xr-x | English_Animal_Identification/js/messages.es.json | 21 | ||||
-rwxr-xr-x | English_Animal_Identification/js/messages.ne.json | 21 | ||||
-rwxr-xr-x | English_Animal_Identification/js/messages.ne.json~ | 21 |
5 files changed, 413 insertions, 0 deletions
diff --git a/English_Animal_Identification/js/lesson.js b/English_Animal_Identification/js/lesson.js new file mode 100755 index 0000000..f932b4c --- /dev/null +++ b/English_Animal_Identification/js/lesson.js @@ -0,0 +1,159 @@ +$(document).ready( + function(){ + + + //preloads assets into karma 'collections' + var k = Karma({ + audio: [{'name':'correct','file':'correct.ogg'}, + {'name':'incorrect','file':'incorrect.ogg'} + ], + image: [{'name': 'bear', 'file': 'bear.png'}, + {name : 'goat', file: 'goat.png'}, + {name: 'tiger', file: 'tiger.png'}, + {name: 'elephant', file: 'elephant.png'}, + {name: 'horse', file: 'horse.png'}, + {name: 'cow', file: 'cow.png'} + ] + }); + + //this command will scale down the lesson if the user's browser window + //is smaller than 950px X 600px + k.scaleWindow(); + + //sets locale, otherwise defaults to English + //$.i18n.setLocale('en'); + + //put your main lesson code here + k.ready( + function(){ + + + $('#kHeader').kHeader({'title': 'English Animal Identification', + lessonPlan: true, teachersNote: true}); + + //Set up feedback widget, this shows the user a correct or incorrect + //icon and sound when triggered programmatically + var $feedback = $('#feedback').feedback(); + + var kFooter = $('#kFooter').kFooter({'winningScore': 6}); + + var score = 0; + var names = []; + var namesUsed = []; + var correctIndex = 0; + var $img = $('#imgObject'); + var $options = $('.option'); + + + var populateListNames = function() { + var i = 0; + $.each(k.image, function (img){ + names[i] = img; + i++; + }); + }; + + + var checkSelection = function(selectedOption){ + if(selectedOption === correctIndex){ + + score++; + kFooter.kFooter('inc'); + kFooter.kFooter('incTotal'); + + if (score === 6){ + $feedback.feedback('win'); + } else{ + $feedback.feedback('correct'); + game(); + } + } + else { + $feedback.feedback('incorrect'); + kFooter.kFooter('incTotal'); + } + }; + + var shuffleGlobal = function (list) { + var i = 0, j = 0, t = 0; + for (i = list.length - 1; i > 0; i -= 1) { + j = Karma.rand(0, i); + t = list[i]; + list[i] = list[j]; + list[j] = t; + } + }; + + var game = function(){ + correctIndex = 0; + + var pickCorrect = function(){ + var correct = 0; + + var used = function(index){ + var name = names[index]; + for (var i = 0; i < namesUsed.length; i++){ + if (namesUsed[i] === name){ + return true; + } + } + return false; + }; + + var getUnusedName = function(){ + correct = k.rand(0,3); + while(used(correct)){ + shuffleGlobal(names); + correct = k.rand(0,3); + } + return correct; + }; + + shuffleGlobal(names); + correct = getUnusedName(); + namesUsed.push(names[correct]); + + return correct; + }; + + correctIndex = pickCorrect(); + + for (var i = 0; i < 4; i++){ + $($options[i]).text(k.image[names[i]].name); + } + + $img.attr('src', k.image[names[correctIndex]].src) + .css('visibility', 'visible'); + + }; + + + kFooter.bind('kFooterWinGame', + function(){ + $('.optImg').hide(); + $('.imageBox').hide(); + $('#gameOver').show(); + }); + kFooter.bind('kFooterRestart', + function() { + namesUsed = []; + correctIndex = 0; + score = 0; + game(); + } + ); + + $options.click( + function(e){ + checkSelection(parseInt(e.target.id.slice(-1))); + } + ); + + + populateListNames(); + game(); //let the game begin + + + }); //end of games + +});
\ No newline at end of file diff --git a/English_Animal_Identification/js/lesson.js~ b/English_Animal_Identification/js/lesson.js~ new file mode 100755 index 0000000..4d60c7d --- /dev/null +++ b/English_Animal_Identification/js/lesson.js~ @@ -0,0 +1,191 @@ +$(document).ready( + function(){ + + var k = Karma({ + audio: [{'name':'correct','file':'correct.ogg'}, + {'name':'incorrect','file':'incorrect.ogg'} + ]}); + + k.scaleWindow(); + $.i18n.setLocale('ne'); + + k.ready( + function(){ + + var flag, i ,j; + var object_counter = 1; + var imgNameRand = []; + var optPosition = []; + var optOtherPos = []; + var imageObject = []; + var imgNames = ["Bear", "Cow", "Elephant", "Horse", "Tiger", "Goat"]; + var correctPosition; + var selectedOption; + var score = 0; + var wrong_selected = 0; //wrong option selected so don't score up + var pos; + var t; + var current_image; + + var $help = $('#kHelpText').dialog({ + position:[ "right", "top"], modal:'true',autoOpen:false + }); + + var $feedback = $('#feedback').feedback(); + + $('#kHeaderHelpBtn').click(function(){ $help.dialog('open');}); + + + $('#kHeader').kHeader({'title': 'English Animal Identification', + lessonPlan: true, teachersNote: true}); + + var kFooter = $('#kFooter').kFooter({'winningScore': 6}); + kFooter.bind('kFooterWinGame', + function(){ + $('.optImg').hide(); + $('.imageBox').hide(); + $('#gameOver').show(); + }); + kFooter.bind('kFooterRestart', + function() { + object_counter = 1; + imgNameRand = []; + optPosition = []; + optOtherPos = []; + imageObject = []; + score = 0; + wrong_selected = 0; //wrong option selected so don't score up + + load_images(); + game(); + + } + ); + + load_images(); //load the image numbers for random display + game(); //let the game begin + + + function checkDisplay(){ //Displays the correct and incorrect info + if(wrong_selected == 1){ + $feedback.feedback('incorrect'); + } + else if (object_counter === 7 ){ + $feedback.feedback('win'); + } else{ + $feedback.feedback('correct'); + } + } + + $("#anchorPlayAgain").click(function(){ + $('#gameOver').hide(); + $('.optImg').show(); + $('.imageBox').show(); + load_images(); + score = 0; + object_counter = 1; + wrong_selected = 0; + //display_score(); + kFooter.kFooter('reset'); + game(); + + }); + $("#anchorOpt0").click(function(){ + selected_Option_Process('0'); + }); + $("#anchorOpt1").click(function(){ + selected_Option_Process('1'); + }); + $("#anchorOpt2").click(function(){ + selected_Option_Process('2'); + }); + $("#anchorOpt3").click(function(){ + selected_Option_Process('3'); + }); + + + function load_images(){ + imageObject = k.shuffle([1, 2, 3, 4, 5, 6]); + } + + function selected_Option_Process(selectedOption){ + + if(selectedOption == correctPosition){ + object_counter++; + wrong_selected = 0; + score++; + kFooter.kFooter('inc'); + kFooter.kFooter('incTotal'); + checkDisplay(); + game(); + } + else { + wrong_selected = 1; + kFooter.kFooter('incTotal'); + checkDisplay(); + } + + } + + function game(){ + + wrong_selected = 0; + current_image = object_counter%6; + document.getElementById("imgObject").src = "assets/image/" + + imageObject[current_image] + ".png"; + + //find correct answer and apply it to the position + var currentImage = imageObject[current_image]; + imgNameRand[0] = currentImage; + //generate choices + + for(i=1; i<4; i++){ + do{ + flag = 0; + imgNameRand[i] = k.rand(1, 6); + for(j=0; j<i; j++){ + if(imgNameRand[i]===imgNameRand[j]){ + flag++; + } + } + }while(flag != 0 ); //end of do while loop + } + + + correctPosition = k.rand(0, 3); + + optOtherPos[0] = correctPosition; + + for(i=1; i<4; i++){ + do{ + flag = 0; + optOtherPos[i] = k.rand(0, 3); + for(j=0; j<i; j++){ //chek repeat within optOtherPos array + if(optOtherPos[i] === optOtherPos[j]){ + flag++; + } + } + + }while(flag != 0); + + } + + for(i=0; i<4; i++){ + pos = optOtherPos[i]; + optPosition[pos] = imgNameRand[i]; + //optPosition[pos] = imgNames[i]; + } + + + + //random positions are stored in optOtherPos array. Great + + + for(i=0; i<4; i++){ + document.getElementById("option"+i+"").src = "assets/image/image_name/"+optPosition[i]+".png"; + } + + + } //no change + }); //end of games +}); //end of DOM
\ No newline at end of file diff --git a/English_Animal_Identification/js/messages.es.json b/English_Animal_Identification/js/messages.es.json new file mode 100755 index 0000000..c9be5bd --- /dev/null +++ b/English_Animal_Identification/js/messages.es.json @@ -0,0 +1,21 @@ +/* -*- coding: utf-8 -*- */ +$.i18n.es = {}; +$.i18n.es.strings = { + "default":{ + + }, + "$.ui.kFooter":{ + "Play Again": "Repite", + "Pause" : "Pausa", + "Start" : "Comienza", + "Timer" : "Reloj", + "Total" : "Total", + "Score" : "Puntos" + }, + "$.ui.kHeader":{ + "Lesson Plan": "Plan de Lección", + "Teacher's Note": "Nota de Profesora" + } +}; + +$(function() { $.i18n.setLocale('es'); });
\ No newline at end of file diff --git a/English_Animal_Identification/js/messages.ne.json b/English_Animal_Identification/js/messages.ne.json new file mode 100755 index 0000000..f0145a7 --- /dev/null +++ b/English_Animal_Identification/js/messages.ne.json @@ -0,0 +1,21 @@ +/* -*- coding: utf-8 -*- */ +$.i18n.ne = {}; +$.i18n.ne.strings = { + "default":{ + + }, + "$.ui.kFooter":{ + "Play Again": "फेरी खेलौ", + "Pause" : "खेल रोकौ", + "Start" : "सुरु गरौ", + "Timer" : "", + "Total" : "जम्मा", + "Score" : "अङ्क" + }, + "$.ui.kHeader":{ + "Lesson Plan": "पाठविवरण", + "Teacher's Note": "पाठयोजना" + } +}; + +$(function() { $.i18n.setLocale('ne'); });
\ No newline at end of file diff --git a/English_Animal_Identification/js/messages.ne.json~ b/English_Animal_Identification/js/messages.ne.json~ new file mode 100755 index 0000000..c9be5bd --- /dev/null +++ b/English_Animal_Identification/js/messages.ne.json~ @@ -0,0 +1,21 @@ +/* -*- coding: utf-8 -*- */ +$.i18n.es = {}; +$.i18n.es.strings = { + "default":{ + + }, + "$.ui.kFooter":{ + "Play Again": "Repite", + "Pause" : "Pausa", + "Start" : "Comienza", + "Timer" : "Reloj", + "Total" : "Total", + "Score" : "Puntos" + }, + "$.ui.kHeader":{ + "Lesson Plan": "Plan de Lección", + "Teacher's Note": "Nota de Profesora" + } +}; + +$(function() { $.i18n.setLocale('es'); });
\ No newline at end of file |