Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/lessons/6_Maths_variables/js/lesson.js
blob: dd84b83deb8a08b2338aff18703769a4eca2d90c (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.wav'},
			{'name':'incorrect','file':'incorrect.wav'}
		]});
		  
	k.ready(function(){
		var i,j;
		var totalCounter;
		var correctCounter;
		var currentQuestion;
		var TOTAL_QUES = 8;
		var flag_correct;
		var randPositions = [];
		
		var question1 = new Array('एउटा झोलामा  x ओटा आपहरु छन ',
				'एउटा बिस्कुटको प्याकेटमा  x ओटा बिस्कुटहरु छन',
				'एउटा प्याकेटमा z ओटा कलमहरु छन', 
				'एउटा झोलामा  y ओटा आपहरु छन',
				'एउटा डालोमा  y ओटा आपहरु छन',
				'एउटा बिस्कुटको प्याकेटमा  x ओटा बिस्कुटहरु छन',
				'एउटा बिस्कुटको प्याकेटमा  x ओटा बिस्कुटहरु छन',
				'एउटा बट्टामा z ओटा कलमहरु छन'			
		);
		var question2 = new Array('x भनेको कति हो खनाएर हेर्दा थाहा हुन्छ',
				'x भनेको कति हो प्याकेट खोलेर  हेर्दा थाहा हुन्छ',
				'z भनेको कति हो प्याकेट खोलेर  हेर्दा थाहा हुन्छ',
				'y भनेको कति हो खनाएर हेर्दा थाहा हुन्छ',
				'y भनेको कति हो खनाएर हेर्दा थाहा हुन्छ',
				'x भनेको कति हो प्याकेट खोलेर  हेर्दा थाहा हुन्छ',
				'x भनेको कति हो प्याकेट खोलेर  हेर्दा थाहा हुन्छ',	
				'z भनेको कति हो बट्टा खोलेर  हेर्दा थाहा हुन्छ'
		);
		var infoQues = new Array('आप खन्याउन झोलामा  क्लिक गर्नुहोस',
				'प्याकेट खोल्न प्याकेटमा  क्लिक गर्नुहोस',
				'प्याकेट खोल्न प्याकेटमा  क्लिक गर्नुहोस',
				'आप खन्याउन झोलामा  क्लिक गर्नुहोस',
				'आप खन्याउन डालोमा  क्लिक गर्नुहोस',
				'प्याकेट खोल्न प्याकेटमा  क्लिक गर्नुहोस',
				'प्याकेट खोल्न प्याकेटमा  क्लिक गर्नुहोस',
				'बट्टा खोल्न बट्टामा  क्लिक गर्नुहोस'				
		);
		var infoQuesClicked = new Array('एउटा झोलामा 12 ओटा आपहरु रहेछन',
				'एउटा प्याकेटमा 10 ओटा बिस्कुटहरु रहेछन',
				'एउटा प्याकेटमा 10 ओटा कलमहरु रहेछन',
				'एउटा झोलामा 9 ओटा आपहरु रहेछन',
				'एउटा डालोमा 10 ओटा आपहरु रहेछन',
				'एउटा प्याकेटमा 15 ओटा बिस्कुटहरु रहेछन',
				'एउटा प्याकेटमा 20 ओटा बिस्कुटहरु रहेछन',
				'एक बट्टामा 4 ओटा कलमहरु छन'
		);	
		
		var answers = new Array('12','10','10','9','10','15','20','4');
		
		var scoreboard = $('#score_box').scoreboard({'layout':'horizontal', 
		       'winningScore': TOTAL_QUES});
		
		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 next_question = function (){
			currentQuestion = randPositions[totalCounter];
			flag_correct = 1;
			$('.bgAns').hide();
			$('#linkCheck').hide();
			$('.bgQues').html('<img id="img'+currentQuestion+'" src="assets/image/img'+currentQuestion+'.png" />');
			$('#question1').addClass('quesText').html(question1[currentQuestion]+' ।');
			$('#question2').addClass('quesText').html(question2[currentQuestion]+' ।');
			$('.bgInfo').addClass('quesText').html(infoQues[currentQuestion]+' ।');

			$('#img'+currentQuestion).click(function(){
				$('#linkCheck').show();
				$('.bgQues').html('<img id="img'+currentQuestion+'" src="assets/image/img'+currentQuestion+'Clicked.png" />');
				$('.bgAns').show();
				$('.bgAns').html('').append('<div id="ans'+currentQuestion+'" class="quesText">तेसो भए यहा  x = </div>');
				$('#ans'+currentQuestion).append('<input type="text" class="textBox" maxlength = "2" />');
				$('#ans'+currentQuestion).append(' हुन्छ ।');
				$('.bgInfo').addClass('quesText').html(infoQuesClicked[currentQuestion]+' ।');
				foucs_blur();
			});
			
		};
		
		function game_start(){
			$('#gameOver').hide();
			$('#linkCheck').show();
			$('#section').removeClass('backOpaque');
			genRandPosition();			
			next_question();	
		}
		
		function game() {
			totalCounter = 0;			
			$('#section').html('').append('<div id="left-side"></div>');
			$('#left-side').append('<div id="topText">चलको मान पत्ता लगाउ </div>');
			$('#left-side').append('<div class="bgQues"></div>');
			$('#left-side').append('<div class="bgAns"></div>');
			$('#section').append('<div id="right-side"></div>');
			$('#right-side').append('<div id="question1" class="bgQuestion"></div>');
			$('#right-side').append('<div id="question2" class="bgQuestion"></div>');
			$('#right-side').append('<div class="bgInfo"></div>');
			$('#help').hide();
			$('.bgAns').hide();
			$('#linkCheck').hide();
			$('#gameOver').hide();
		}
		
		game();
		
		var delay_nextQues = function(){
			document.delayForm.delayval.value = 1;
			next_question();
		}
		
		var delay_gameOver = function(){
			document.delayForm.delayval.value = 1;
			$('#section').addClass('backOpaque');
			$('#linkCheck').hide();
			$('#gameOver').show();
			
		};
		var check_answer = function(){
			var textVal = $('.textBox').val();
			if(answers[currentQuestion] === textVal){
				if(flag_correct === 1){
					correctCounter++;
					scoreboard.scoreboard('inc');
				}
				k.audio.correct.play();
				totalCounter++;
				scoreboard.scoreboard('incTotal');
				if(totalCounter != TOTAL_QUES){
					t=setTimeout(function(){delay_nextQues();},1000);
				}
				else{
					t=setTimeout(function(){delay_gameOver();},1000);
				}				
			}
			else{
				flag_correct = 0;
				k.audio.incorrect.play();
			}
		};
		
		function foucs_blur(){
			$('input[type="text"]')
			.focus(function() {
			    $(this).removeClass('incorrect').addClass("focus");
			})
			.blur(function() {
			    $(this).removeClass("focus");
			})
			.keypress(function(event) {
				if(event.which === 13){
					check_answer();
				}
			});
			
			$('#linkCheck').click(function(){
				check_answer();
			});
		}
		
		$('#linkStart').click(function(){
			game_start();
		});
	
		$('#linkPlayAgain').click(function(){
			scoreboard.scoreboard('reset');
			game_start();		
		});
		$('#linkHelp').click(function(){
			$('#help').slideDown(2000);
		})
		.mouseout(function(){
			$('#help').slideUp(2000);
		});
	}); //end of k.ready
});	//end of document.ready