$(document).ready(function(){ var k = Karma({ audio: [{'name':'correct','file':'correct.ogg'}, {'name':'incorrect','file':'incorrect.ogg'} ]}); k.ready(function(){ var i,j,flag; var TOTAL_QUES = 8; var TOTAL_LEVEL = 3; var currentDragObject; var randPositions = []; var randImages = []; var randOptions = []; var totalCounter; var correctCounter; var currentQuestion; var currentDragObject; var arrangedAns = []; var checked; var sectionNum; //store the current tab num var flag_checked; var currentQues; //store the current Animal name var currentAnimal; //store the current Animal Image name var correctQuest; //store 1 if the question and image is same var animals = new Array('tiger','elephant','jackel','bear','rhino','monkey','turtle','snake', 'duck','cock','pig','cow','goat','horse','sheep','rabbit', 'parrot','mynah','crow','sparrow','egret','pigeon','owl','eagle' ); var answersOpts = new Array('Yes','No','it','is',"isn't"); var tabs = new Array('wild','domestic','bird'); var correctYes = new Array('Yes','it','is'); var correctNo = new Array('No','it',"isn't"); var scoreboard = $('#score_box').scoreboard({'layout':'horizontal', 'winningScore': 8}); /*scoreboard.bind('winGame',function(){ //needs total score counter to be checked problem $('#gameOver').show(); $('#dot').hide(); $('#questionSection').hide(); $('#gameOver').append('Game Over !!!'); $('#gameOver').append('
You got '+correctCounter+ ' correct out of '+totalCounter+' questions .
'); }); */ var genRandOpts=function (){ randOptions[0] = k.rand(0,4); for(i=1; i<5; i++){ do{ flag = 0; randOptions[i] = k.rand(0,4); for(j=0; j'); $('#gameOver').append('Game Over !!!'); $('#gameOver').append('
You got '+correctCounter+ ' correct out of '+totalCounter+' questions .
'); }; var display_control = function(){ if(checked === 1){ next_questions(); } }; var delay_correctShow = function(){ document.delayForm.delayval.value = 1; $('#checkAnswer').hide(); display_control(); } var check_answers = function(){ $('#checkAnswer').show(); var correct = 0; var correctCheck = 0; if(correctQuest === 1){ for(var i = 0 ; i< 3; i++){ if(arrangedAns[i] === correctYes[i]){ correct++; } } if(correct === 3){ correctCheck = 1; } } else{ for(var i = 0 ; i< 3; i++){ if(arrangedAns[i] === correctNo[i]){ correct++; } } if(correct === 3){ correctCheck = 1; } } if(correctCheck === 1){ if(flag_checked === 0){ scoreboard.scoreboard('inc'); correctCounter++; } k.audio.correct.play(); $('#checkAnswer').html(''); checked = 1; totalCounter++; scoreboard.scoreboard('incTotal'); } else{ k.audio.incorrect.play(); $('#checkAnswer').html(''); checked = 0; flag_checked = 1; } t=setTimeout(function(){delay_correctShow();},1000); }; var assignTabs = function (tabId){ $('#tabs').append('
'); var tabImgCss = { 'width': '179px', 'height': '50px', 'background-image': 'url("assets/image/'+tabs[tabId]+'.png")', 'background-repeat': 'no-repeat' }; $('#tabs'+tabId).css(tabImgCss); $('#tabs'+tabId).click(function(){ for(j = 0; j'); var dropObjCss = { 'width':'125px','height': '30px','margin':'1.7em 0.5em 0.2em 0.5em' , 'border-bottom': '2px solid black','float':'left' }; $('.dropObjects').css(dropObjCss); }; var assignDragAns = function (optId){ $('#dragAnswers').append('
'+answersOpts[optId]+'
'); var dragObjCss = { 'float': 'left','cursor': 'move', 'height':'30px','padding': '0px 1em', 'font':'20px/25px bold Arial,Verdana,Geneva,Helvetica' }; $('.dragObjects').css(dragObjCss); }; var next_questions = function(){ if(totalCounter === TOTAL_QUES){ display_game_over(); } else{ currentQuestion = totalCounter; flag_checked = 0; genRandOpts(); for(i=0; i<3; i++){ arrangedAns[i] = 0; } var randImage = randImages[currentQuestion]+(sectionNum*TOTAL_QUES); var randNum = randPositions[currentQuestion]+(sectionNum*TOTAL_QUES); currentQues = animals[randNum]; currentAnimal = animals[randImage]; $('#questionSection').html(''); $('#imgAnimals').html(''); $('#questionSection').append('
'); $('#ques'+currentQuestion).append(totalCounter+1+'.').append(' Is this '); if(currentQues[0] === 'a' || currentQues[0] === 'e' ||currentQues[0] === 'i' ||currentQues[0] === 'o' ||currentQues[0] === 'u'){ $('#ques'+currentQuestion).append('an '); } else{ $('#ques'+currentQuestion).append('a '); } $('#ques'+currentQuestion).append(currentQues+' ?'); if(currentAnimal === currentQues){ correctQuest = 1; } else{ correctQuest = 0; } $('#questionSection').append('
'); for(i = 0; i<3 ;i++){ assignAns(i); } $('#answerSection').append('
'); $('#section').append('
'); $('#questionSection').append('
'); var randOption; for(i = 0; i<5 ;i++){ randOption = randOptions[i]; assignDragAns(randOption); } drag_drop(); } }; function game(){ scoreboard.scoreboard('reset'); $('#linkNext').hide(); $('#gameOver').hide(); correctCounter = 0; totalCounter = 0; genRandPosition(); genRandImages(); $('#section').html(''); $('#tabs1').removeClass('tabSelected'); $('#tabs2').removeClass('tabSelected'); $('#tabs'+sectionNum).addClass('tabSelected'); $('#section').append('
'); $('#section').append('
'); next_questions(); } for(i = 0; i< TOTAL_LEVEL; i++){ assignTabs(i); } sectionNum = 0; $('#linkCheck').click(function(){ check_answers(); }); $('#linkStart').click(function(){ sectionNum = 0; game(); }); $('#linkPlayAgain').click(function(){ game(); }); function drag_drop(){ $('.dragObjects').draggable({ containment: '#content'}); $('.dragObjects').bind('dragstart', function(event, ui) { currentDragObject = event.target.id; }); $(".dropObjects").droppable({ tolerence: 'intersect' ,hoverClass: 'drophover' }); $('.dropObjects').bind('drop', function(event, ui) { var currentDropObject = event.target.id; var droppedWord = parseInt(currentDropObject.substring(4)); arrangedAns[droppedWord] = $('#'+currentDragObject).text(); }); } }); //end of k.ready }); //end of document.ready