Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/js/lesson.js~
blob: 4d60c7d6df2a8e9a3a0abc990f6786f5899c6b41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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