Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/lessons/6_English_alphabeticalOrder/js/lesson.js
blob: c128d5607a65ade26f052d51f6bb77487af305c3 (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
$(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 = 6;
		var TOTAL_LEVEL = 3;
		var currentDragObject;
		var randPositions = [];
		var arrangedAns = [];
		var sectionNum;  //store the three levels values 0,1,2
		var currentAlphaNum;  //store the current questions num
		var checked; //store the current checked value
		var num;
		var currentAnsArray = [];  //store the current array set of alphabets
		var flag_checked; //status flag for one time correct alpahbetical order
		var imgCounter;
		// six alphabets given to be ordered 6 steps needed to complete the picture 3 levels too complex
		var alphabets = new Array('aeroplane','apple','ant','arrow','audio','axe',
									'eagle','ear','east','egg','elephant','engine',
									'fan','fall','fat','first','fog','fun',
									'egg','goat','ladder','leaf','net','tiger',
									'crocodile','deer','elephant','lion','rhinosorous','tiger',
									'bus','flag','glass','nose','pencil','table',			
									'bag','ball','banana','bat','bed','bone',
									'cat','camera','class','color','country','cream',
									'cat','cow','dog','donkey','hen','rabbit',
									'dam','dark','den','dog','drink','duck',
									'glass','nail','picture','radio','star','watch',
									'bus','flag','glass','nose','pencil','table',									
									'magic','man','many','master','miracle','mouse',
									'pan','pencil','pig','pot','practice','pumpkin',
									'salte','school','short','smile','snake','stick',
									'axe','mountain','plate','umbrella','volley-ball','x-ray',
									'television','temple','toggle','trap','trust','turn',
									'bottle','fish','house','pan','tree','window'										
						);
		var imageDisplay = new Array('ele0','ele1','ele2','ele3','ele4','ele5','house0','house1','house2','house3','house4','house5',
									'ship0','ship1','ship2','ship3','ship4','ship5');
		var scoreboard = $('#score_box').scoreboard({'layout':'horizontal', 
		       'winningScore': alphabets.length});
 
		var genRandPosition=function (){
		  	randPositions[0] = k.rand(0,TOTAL_QUES-1);
			for(i=1; i<TOTAL_QUES; i++){
					do{
						flag = 0;
						randPositions[i] = k.rand(0,TOTAL_QUES-1);
						for(j=0; j<i; j++){
							if(randPositions[i] === randPositions[j]){
								flag++;
							}
						}
					}while(flag != 0 );  //end of do while loop	
				}
		};	
		var assignAlphabets = function (alphaId){	
			var alphaCloudId = 1;   //for positioning only
			if(alphaId>2){
				alphaCloudId = 2;
			}		
			var alphaCurId = alphaId + (currentAlphaNum*TOTAL_QUES);
			$('#alphaCloud'+alphaCloudId).append('<div id="drag'+alphaId+'" class="dragObjects">'+alphabets[alphaCurId]+'</div>');
			var dragObjCss = {
					'position':'relative','float': 'left','cursor': 'move',
					'width':'100px','height':'30px','padding-left': '20px',
					'font':'20px/25px bold Arial,Verdana,Geneva,Helvetica'
				};
			$('.dragObjects').css(dragObjCss);	
			
			$('#alphaArrange').append('<div id="drop'+num+'" class="dropObjects"></div>');
			var dropObjCss = { 
					'width':'222px','height': '33px','margin': '0.65em 0.5em'				
				};
			$('.dropObjects').css(dropObjCss);	
			num++;
		};
		
		function drag_drop(){
			$('.dragObjects').draggable({ containment: '#content'});	
			$('.dragObjects').bind('dragstart', function(event, ui) {
				currentDragObject = event.target.id;	
				var currentMonth = parseInt(currentDragObject.substring(4));

			});
			
			$(".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();
			});
		}
		var display_control = function(){
			if(checked === 1){
				$('#disImg'+imgCounter).show();
				imgCounter++;
				next_alphabets();	
			}
			
		};
		var delay_correctShow = function(){
			document.delayForm.delayval.value = 1;
			$('#checkAnswer').hide();
			if(currentAlphaNum%6 === 0 && currentAlphaNum != 0){ //next level
				$('#section').html('');
				$('#linkNext').show();
			}
			else{
			display_control();
			}
		};
		
		var check_alphabets_order = function(){
			var correct = 0;	
			for(i=0; i<TOTAL_QUES; i++){
				//var alpha = i+(currentAlphaNum*TOTAL_QUES);
				if(arrangedAns[i] === currentAnsArray[i] && arrangedAns.length != 0){
					correct++;
				}
			}
			$('#checkAnswer').show();
			if(correct === TOTAL_QUES){
				if(flag_checked === 0){
					scoreboard.scoreboard('inc');
				}
				currentAlphaNum++;
				checked = 1;
				k.audio.correct.play();
				$('#checkAnswer').html('<img src="assets/image/correct.png">');
				scoreboard.scoreboard('incTotal');
			}
			else{
				k.audio.incorrect.play();
				$('#checkAnswer').html('<img src="assets/image/incorrect.png">');
				checked = 0; 
				flag_checked = 1;
			}
			
			t=setTimeout(function(){delay_correctShow();},1000);
			
			
			
			
		};
		var display_game_over = function(){
			
				$('#section').hide();
				$('#gameOver').show();
				$('#gameOver').html('');
				$('#gameOver').append('GAME OVER<br/>Congratulations!!!');
		};
		var next_alphabets = function(){
			if(currentAlphaNum === alphabets.length){   //show all
				display_game_over();
			}
			else{	
					$('#section').html('').append('<div id="alphaCloud1"></div>');
					$('#section').append('<div id="alphaCloud2"></div>');
					$('#section').append('<div id="topText">Rearrange the above words in alphabetical order.</div>');
					$('#section').append('<div id="alphaArrange"></div>');
					genRandPosition();		
					num = 0;
					flag_checked = 0;
					for(i = 0; i< TOTAL_QUES ; i++){
						assignAlphabets(randPositions[i]);			
					}
					for(i = 0;i<TOTAL_QUES;i++){
						var curAlphabet = (currentAlphaNum*TOTAL_QUES)+i;
						currentAnsArray[i] = alphabets[curAlphabet];
					}
					currentAnsArray.sort();					
					drag_drop();
				
			}
		};
		function game_start(){
			$('#gameOver').hide();
			$('#displayImgArea').show();
			$('#displayImgArea').html('');
			imgCounter = 0;
			for(i = 0;i<TOTAL_QUES;i++){
				imgId = i + (sectionNum*TOTAL_QUES);
				$('#displayImgArea').append('<img id="disImg'+i+'" class="imgDisplay" src="assets/image/'+imageDisplay[imgId]+'.png" width="30%" height="50%">');
				$('#disImg'+i).hide();
			}
			next_alphabets();
		}
		$('#linkNext').hide();
		$('#linkCheck').click(function(){
			check_alphabets_order();
		});
		$('#linkNext').click(function(){
			$('#linkNext').hide();
			sectionNum += 1;
			game_start();
		});
		$('#linkStart').click(function(){
			sectionNum = 0;
			currentAlphaNum = 0;
			game_start();
		});
	
		$('#linkPlayAgain').click(function(){
			scoreboard.scoreboard('reset');
			currentAlphaNum = sectionNum*currentAlphaNum;
			game_start();		
		});
	}); //end of k.ready
});	//end of document.ready