Subversion Repositories Kolibri OS

Rev

Rev 1805 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1805 yogev_ezra 1
// Исходник игры "Кто хочет быть миллионером?" для Колибри ОС
2
// by Андрей Михайлович (Dron2004)
3
 
4
#include 
5
#include 
2830 leency 6
#include 
1805 yogev_ezra 7
 
2830 leency 8
char sVersion[] = "‚ҐабЁп 0.2";
1805 yogev_ezra 9
 
10
int status=0;
11
 
12
bool needcleanup = false; //Символ того, что игра была начата... Необходимо для высвобождения памяти
13
int questioncount = 0; //Число вопросов
14
int currentquestion = 0; //Номер текущего вопроса (1, 2, ..., 15)
15
 
16
int askedquestions[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
17
 
18
char friendsAdvice[1]={' '};
19
 
20
char summs[][16]={"0","100","200","300","500","1000","2000","4000","8000","16000","32000","64000","125000","250000","500000","1000000"};
21
char * question;
22
char * answerA;
23
char * answerB;
24
char * answerC;
25
char * answerD;
26
Byte correctanswer=0x00;
27
 
28
int questionlength=0;
29
int answerAlength=0;
30
int answerBlength=0;
31
int answerClength=0;
32
int answerDlength=0;
33
 
34
bool na50available = true;
35
bool callfriendavailable = true;
36
bool zalavailable = true;
37
 
38
int zalA=0;
39
int zalB=0;
40
int zalC=0;
41
int zalD=0;
42
 
43
 
44
 
45
bool drawA = true;
46
bool drawB = true;
47
bool drawC = true;
48
bool drawD = true;
49
 
50
 
51
char * tempquestion;
52
char * tempanswerA;
53
char * tempanswerB;
54
char * tempanswerC;
55
char * tempanswerD;
56
Byte tempcorrectanswer=0x00;
57
int tempquestionlength=0;
58
int tempanswerAlength=0;
59
int tempanswerBlength=0;
60
int tempanswerClength=0;
61
int tempanswerDlength=0;
62
 
63
 
2830 leency 64
const char header[]="Љв® е®зҐв Ўлвм ¬Ё««Ё®­Ґа®¬";
65
void app_halt();
1805 yogev_ezra 66
 
67
 
68
 
69
char * filepathname; //Определяем путь и имя файла с базой вопросов
70
void getFilePathName(){
71
	int lastslashindex=0;
72
	char ourfilename[]="appdata.dat";
73
	int tmpcnt=0;
74
 
75
	for (tmpcnt=0;tmpcnt
76
		if (kosExePath[tmpcnt]=='/'){lastslashindex=tmpcnt;}
77
	}
78
	filepathname = new char [lastslashindex+strlen(ourfilename)+1];
79
 
80
	for (tmpcnt=0; tmpcnt<=lastslashindex; tmpcnt++){
81
		filepathname[tmpcnt]=kosExePath[tmpcnt];
82
	}
83
	for (tmpcnt=0; tmpcnt
84
		filepathname[tmpcnt+lastslashindex+1]=ourfilename[tmpcnt];
85
	}
86
 
87
}
88
 
89
void prepareFileData() { //Предварительные подсчёты
90
	Byte tmpbyte[1]={0x00};
91
   CKosFile basefile(filepathname);
92
 
93
   while (tmpbyte[0]!=0x14){
94
		basefile.Read (tmpbyte,1);
95
		if (tmpbyte[0]==0x10) {questioncount++;};
96
   }
97
  // basefile
98
}
99
 
100
void loadquestion(){
101
 
102
	//Страшно корявая процедура генерации случайного номера вопроса
103
//	rtlSrand(kos_GetSystemClock() / 100000);
104
 
105
	int qcodee;
106
 
107
	int skipsleft;
108
 
109
regenerate:
110
	qcodee=(rtlRand()%questioncount)+1;
111
 
112
	Byte inputbyte[1]={0x00};
113
 
114
	//Первый проход - проверяем сложность и считаем длины строк
115
	tempquestionlength = 0;
116
	tempanswerAlength = 0;
117
	tempanswerBlength = 0;
118
	tempanswerClength = 0;
119
	tempanswerDlength = 0;
120
 
121
 
122
	skipsleft=qcodee;
123
	CKosFile basefile(filepathname);
124
	//Найдём то место, откуда начинается наш вопрос
125
	while (skipsleft>0){
126
		basefile.Read (inputbyte,1);
127
		if (inputbyte[0]==0x10){
128
			skipsleft--;
129
		}
130
		inputbyte[0]=0x00;
131
	}
132
 
133
	//Проверим сложность
134
	basefile.Read (inputbyte,1);
135
 
136
	// Нам нужно, чтобы сложность задаваемого вопроса соответствовала номеру задаваемого
137
	// в игре вопроса (на какую сумму мы играем; вопрос на 1000000 должен быть посложнее,
138
	// чем вопрос на 100 рублей :-)))
139
 
140
	if (inputbyte[0]==0x05) //Лёкгий вопрос
141
	{
142
		if (currentquestion > 5){ //Лёгкие вопросы - вопросы от 1 до 5
143
			goto regenerate; //Если это уже 6 вопрос и более - ищем другой вопрос
144
		}
145
	}
146
	if (inputbyte[0]==0x06) //Средний вопрос
147
	{
148
		if ((currentquestion < 6)||(currentquestion > 10)){ //Средние вопросы - вопросы от 6 до 10
149
			goto regenerate;
150
		}
151
	}
152
	if (inputbyte[0]==0x07) //Сложный вопрос
153
	{
154
		if (currentquestion < 11){ //Средние вопросы - вопросы от 11 до 15
155
			goto regenerate;
156
		}
157
	}
158
 
159
 
160
	for (int counter=0; counter 
161
		if (askedquestions[counter]==qcodee){goto regenerate;}
162
	}
163
 
164
 
165
	askedquestions[currentquestion-1]=qcodee;
166
 
167
 
168
	inputbyte[0]=0x00;
169
	//Считаем, сколько символов в вопросе
170
	tempquestionlength = 0;
171
	tempanswerAlength = 0;
172
	tempanswerBlength = 0;
173
	tempanswerClength = 0;
174
	tempanswerDlength = 0;
175
	while (inputbyte[0]!=0x01){
176
		basefile.Read (inputbyte,1);
177
		tempquestionlength++;
178
	}
179
	while (inputbyte[0]!=0x02){
180
		basefile.Read (inputbyte,1);
181
		tempanswerAlength++;
182
	}
183
	while (inputbyte[0]!=0x03){
184
		basefile.Read (inputbyte,1);
185
		tempanswerBlength++;
186
	}
187
	while (inputbyte[0]!=0x04){
188
		basefile.Read (inputbyte,1);
189
		tempanswerClength++;
190
	}
191
	while (inputbyte[0]!=0x08){
192
		basefile.Read (inputbyte,1);
193
		tempanswerDlength++;
194
	}
195
	//Первый проход завершён!!!!
196
 
197
	if (needcleanup==true){
198
		delete question;
199
		delete answerA;
200
		delete answerB;
201
		delete answerC;
202
		delete answerD;
203
	}
204
	needcleanup=true;
205
 
206
	tempquestion = new char[tempquestionlength+1];
207
	tempanswerA = new char[tempanswerAlength+1];
208
	tempanswerB = new char[tempanswerBlength+1];
209
	tempanswerC = new char[tempanswerClength+1];
210
	tempanswerD = new char[tempanswerDlength+1];
211
 
212
 
2830 leency 213
 
1805 yogev_ezra 214
	// ВТОРОЙ ПРОХОД: ФОРМИРУЕМ В ПАМЯТИ ВОПРОС И ВАРИАНТЫ ОТВЕТА
215
	CKosFile basefile2(filepathname);
216
	inputbyte[0]=0x00;
217
	skipsleft=qcodee;
218
 
219
	//Найдём то место, откуда начинается наш вопрос
220
	while (skipsleft>0){
221
		basefile2.Read (inputbyte,1);
222
		if (inputbyte[0]==0x10){
223
			skipsleft--;
224
		}
225
		inputbyte[0]=0x00;
226
	}
227
 
228
	basefile2.Read (inputbyte,1); // Это - сложность вопроса. Мы её уже проверили.
229
 
230
	//Читаем вопрос
231
	int currentbyte=0;
232
	while (inputbyte[0]!=0x01){
233
		basefile2.Read (inputbyte,1);
234
		if (inputbyte[0]!=0x01){tempquestion[currentbyte]=inputbyte[0];}
235
		currentbyte++;
236
	}
237
	tempquestion[currentbyte]='\n';
238
 
239
	//Читаем ответ A
240
	currentbyte=0;
241
	while (inputbyte[0]!=0x02){
242
		basefile2.Read (inputbyte,1);
243
		if (inputbyte[0]!=0x02){tempanswerA[currentbyte]=inputbyte[0];}
244
		currentbyte++;
245
	}
246
	tempanswerA[currentbyte]='\n';
247
 
248
	//Читаем ответ B
249
	currentbyte=0;
250
	while (inputbyte[0]!=0x03){
251
		basefile2.Read (inputbyte,1);
252
		if (inputbyte[0]!=0x03){tempanswerB[currentbyte]=inputbyte[0];}
253
		currentbyte++;
254
	}
255
	tempanswerB[currentbyte]='\n';
256
 
257
	//Читаем ответ C
258
	currentbyte=0;
259
	while (inputbyte[0]!=0x04){
260
		basefile2.Read (inputbyte,1);
261
		if (inputbyte[0]!=0x04){tempanswerC[currentbyte]=inputbyte[0];}
262
		currentbyte++;
263
	}
264
	tempanswerC[currentbyte]='\n';
265
 
266
	//Читаем ответ D
267
	currentbyte=0;
268
	while (inputbyte[0]!=0x08){
269
		basefile2.Read (inputbyte,1);
270
		if (inputbyte[0]!=0x08){tempanswerD[currentbyte]=inputbyte[0];}
271
		currentbyte++;
272
	}
273
	tempanswerD[currentbyte]='\n';
274
 
275
	basefile2.Read (inputbyte,1); // Это-правильный ответ
276
	tempcorrectanswer=inputbyte[0];
277
	// ВСЁ!!!!!! ГОТОВО!!!! УРА!
278
 
279
	//Считали. Теперь надо перетасовать вопросы.
280
	questionlength = 0;
281
	answerAlength = 0;
282
	answerBlength = 0;
283
	answerClength = 0;
284
	answerDlength = 0;
285
	//Сам вопрос остаётся без изменения
286
	questionlength=tempquestionlength;
287
	question = new char[questionlength];
288
	for (int cd=0; cd
289
		question[cd]=tempquestion[cd];
290
	}
291
 
292
 
293
	//Тасуем ответы
294
	bool answerAfree = true;
295
	bool answerBfree = true;
296
	bool answerCfree = true;
297
	bool answerDfree = true;
298
 
299
	int tmpvalue=0;
300
 
301
	//Первый вопрос
302
regenA:
303
	tmpvalue = (rtlRand() % 4) +1;
304
	if (tmpvalue==1){
305
		if (answerAfree==true){
306
			answerAfree=false;
307
			answerAlength=tempanswerAlength;
308
			answerA= new char [answerAlength];
309
 
310
			for (int c=0; c
311
				answerA[c]=tempanswerA[c];
312
			}
313
			if (tempcorrectanswer==0x01){correctanswer=0x01;}
314
		}
315
		else
316
		{
317
			goto regenA;
318
		}
319
	}
320
	if (tmpvalue==2){
321
		if (answerBfree==true){
322
			answerBfree=false;
323
			answerBlength=tempanswerAlength;
324
			answerB= new char [answerBlength];
325
 
326
			for (int c=0; c
327
				answerB[c]=tempanswerA[c];
328
			}
329
			if (tempcorrectanswer==0x01){correctanswer=0x02;}
330
		}
331
		else
332
		{
333
			goto regenA;
334
		}
335
	}
336
	if (tmpvalue==3){
337
		if (answerCfree==true){
338
			answerCfree=false;
339
			answerClength=tempanswerAlength;
340
			answerC= new char [answerClength];
341
 
342
			for (int c=0; c
343
				answerC[c]=tempanswerA[c];
344
			}
345
			if (tempcorrectanswer==0x01){correctanswer=0x03;}
346
		}
347
		else
348
		{
349
			goto regenA;
350
		}
351
	}
352
	if (tmpvalue==4){
353
		if (answerDfree==true){
354
			answerDfree=false;
355
			answerDlength=tempanswerAlength;
356
			answerD= new char [answerDlength];
357
 
358
			for (int c=0; c
359
				answerD[c]=tempanswerA[c];
360
			}
361
			if (tempcorrectanswer==0x01){correctanswer=0x04;}
362
		}
363
		else
364
		{
365
			goto regenA;
366
		}
367
	}
368
 
369
//Второй вопрос
370
regenB:
371
	tmpvalue = (rtlRand() % 4) +1;
372
	if (tmpvalue==1){
373
		if (answerAfree==true){
374
			answerAfree=false;
375
			answerAlength=tempanswerBlength;
376
			answerA= new char [answerAlength];
377
 
378
			for (int c=0; c
379
				answerA[c]=tempanswerB[c];
380
			}
381
			if (tempcorrectanswer==0x02){correctanswer=0x01;}
382
		}
383
		else
384
		{
385
			goto regenB;
386
		}
387
	}
388
	if (tmpvalue==2){
389
		if (answerBfree==true){
390
			answerBfree=false;
391
			answerBlength=tempanswerBlength;
392
			answerB= new char [answerBlength];
393
 
394
			for (int c=0; c
395
				answerB[c]=tempanswerB[c];
396
			}
397
			if (tempcorrectanswer==0x02){correctanswer=0x02;}
398
		}
399
		else
400
		{
401
			goto regenB;
402
		}
403
	}
404
	if (tmpvalue==3){
405
		if (answerCfree==true){
406
			answerCfree=false;
407
			answerClength=tempanswerBlength;
408
			answerC= new char [answerClength];
409
 
410
			for (int c=0; c
411
				answerC[c]=tempanswerB[c];
412
			}
413
			if (tempcorrectanswer==0x02){correctanswer=0x03;}
414
		}
415
		else
416
		{
417
			goto regenB;
418
		}
419
	}
420
	if (tmpvalue==4){
421
		if (answerDfree==true){
422
			answerDfree=false;
423
			answerDlength=tempanswerBlength;
424
			answerD= new char [answerDlength];
425
 
426
			for (int c=0; c
427
				answerD[c]=tempanswerB[c];
428
			}
429
			if (tempcorrectanswer==0x02){correctanswer=0x04;}
430
		}
431
		else
432
		{
433
			goto regenB;
434
		}
435
	}
436
 
437
	//Третий вопрос
438
regenC:
439
		tmpvalue = (rtlRand() % 4) +1;
440
	if (tmpvalue==1){
441
		if (answerAfree==true){
442
			answerAfree=false;
443
			answerAlength=tempanswerClength;
444
			answerA= new char [answerAlength];
445
 
446
			for (int c=0; c
447
				answerA[c]=tempanswerC[c];
448
			}
449
			if (tempcorrectanswer==0x03){correctanswer=0x01;}
450
		}
451
		else
452
		{
453
			goto regenC;
454
		}
455
	}
456
	if (tmpvalue==2){
457
		if (answerBfree==true){
458
			answerBfree=false;
459
			answerBlength=tempanswerClength;
460
			answerB= new char [answerBlength];
461
 
462
			for (int c=0; c
463
				answerB[c]=tempanswerC[c];
464
			}
465
			if (tempcorrectanswer==0x03){correctanswer=0x02;}
466
		}
467
		else
468
		{
469
			goto regenC;
470
		}
471
	}
472
	if (tmpvalue==3){
473
		if (answerCfree==true){
474
			answerCfree=false;
475
			answerClength=tempanswerClength;
476
			answerC= new char [answerClength];
477
 
478
			for (int c=0; c
479
				answerC[c]=tempanswerC[c];
480
			}
481
			if (tempcorrectanswer==0x03){correctanswer=0x03;}
482
		}
483
		else
484
		{
485
			goto regenC;
486
		}
487
	}
488
	if (tmpvalue==4){
489
		if (answerDfree==true){
490
			answerDfree=false;
491
			answerDlength=tempanswerClength;
492
			answerD= new char [answerDlength];
493
 
494
			for (int c=0; c
495
				answerD[c]=tempanswerC[c];
496
			}
497
			if (tempcorrectanswer==0x03){correctanswer=0x04;}
498
		}
499
		else
500
		{
501
			goto regenC;
502
		}
503
	}
504
 
505
	//Четвёртый вопрос
506
regenD:
507
	tmpvalue = (rtlRand() % 4) +1;
508
	if (tmpvalue==1){
509
		if (answerAfree==true){
510
			answerAfree=false;
511
			answerAlength=tempanswerDlength;
512
			answerA= new char [answerAlength];
513
 
514
			for (int c=0; c
515
				answerA[c]=tempanswerD[c];
516
			}
517
			if (tempcorrectanswer==0x04){correctanswer=0x01;}
518
		}
519
		else
520
		{
521
			goto regenD;
522
		}
523
	}
524
	if (tmpvalue==2){
525
		if (answerBfree==true){
526
			answerBfree=false;
527
			answerBlength=tempanswerDlength;
528
			answerB= new char [answerBlength];
529
 
530
			for (int c=0; c
531
				answerB[c]=tempanswerD[c];
532
			}
533
			if (tempcorrectanswer==0x04){correctanswer=0x02;}
534
		}
535
		else
536
		{
537
			goto regenD;
538
		}
539
	}
540
	if (tmpvalue==3){
541
		if (answerCfree==true){
542
			answerCfree=false;
543
			answerClength=tempanswerDlength;
544
			answerC= new char [answerClength];
545
 
546
			for (int c=0; c
547
				answerC[c]=tempanswerD[c];
548
			}
549
			if (tempcorrectanswer==0x04){correctanswer=0x03;}
550
		}
551
		else
552
		{
553
			goto regenD;
554
		}
555
	}
556
	if (tmpvalue==4){
557
		if (answerDfree==true){
558
			answerDfree=false;
559
			answerDlength=tempanswerDlength;
560
			answerD= new char [answerDlength];
561
 
562
			for (int c=0; c
563
				answerD[c]=tempanswerD[c];
564
			}
565
			if (tempcorrectanswer==0x04){correctanswer=0x04;}
566
		}
567
		else
568
		{
569
			goto regenD;
570
		}
571
	}
572
 
573
	delete tempquestion;
574
	delete tempanswerA;
575
	delete tempanswerB;
576
	delete tempanswerC;
577
	delete tempanswerD;
2830 leency 578
}
1805 yogev_ezra 579
 
580
 
581
 
2830 leency 582
void draw_window(void){ //Рисуем окно
583
	sProcessInfo sPI;
1805 yogev_ezra 584
 
2830 leency 585
	kos_WindowRedrawStatus(1);
586
	kos_DefineAndDrawWindow(10,10,619,179+kos_GetSkinHeight(),0x74, 0xDDDDFF, 0,0, (Dword)header);
587
	kos_WindowRedrawStatus(2);
588
 
589
	kos_ProcessInfo( &sPI );
590
	if (sPI.rawData[70]&0x04) return; //ничего не делать если окно схлопнуто в заголовок
1805 yogev_ezra 591
 
592
 
593
	if (status==0){ //Меню
2830 leency 594
		kos_DrawBar(0,0,610,175,0xFFFFBB);
1805 yogev_ezra 595
                kos_WriteTextToWindow (10,10,0x80,0x000000, "Љв® е®зҐв Ўлвм ¬Ё««Ё®­Ґа®¬?", 3);
596
 
597
		kos_WriteTextToWindow (10,25,0x80,0x000000, sVersion, 3);
598
 
599
                kos_WriteTextToWindow (10,70,0x80,0x770000, " - ­ з вм ЁЈаг", 0);
600
                kos_WriteTextToWindow (10,85,0x80,0x770000, " - ўл室", 0);
601
 
602
                kos_WriteTextToWindow (10,150,0x80,0x000000, "(C) 2008 Ђ­¤аҐ© ЊЁе ©«®ўЁз aka Dron2004", 0);
603
		//kos_DisplayNumberToWindow (questioncount,3,40,60,0x000000, nbDecimal, false);
604
	}
605
	if (status==1){ //Игра
606
 
2830 leency 607
		kos_DrawBar(0,0,610,175,0xEEEEFF);
1805 yogev_ezra 608
 
609
		kos_WriteTextToWindow (10,10,0x0,0x000000, question, questionlength-1);
610
 
611
		if (drawA==true){
612
			kos_WriteTextToWindow (10,40,0x80,0x000000, "A. ", 0);
613
			kos_WriteTextToWindow (30,40,0x0,0x000000, answerA, answerAlength-1);
614
		}
615
		if (drawB==true){
616
			kos_WriteTextToWindow (10,60,0x80,0x000000, "B. ", 0);
617
			kos_WriteTextToWindow (30,60,0x0,0x000000, answerB, answerBlength-1);
618
		}
619
		if (drawC==true){
620
			kos_WriteTextToWindow (10,80,0x80,0x000000, "C. ", 0);
621
			kos_WriteTextToWindow (30,80,0x0,0x000000, answerC, answerClength-1);
622
		}
623
		if (drawD==true){
624
			kos_WriteTextToWindow (10,100,0x80,0x000000, "D. ", 0);
625
			kos_WriteTextToWindow (30,100,0x0,0x000000, answerD, answerDlength-1);
626
		}
627
                if (na50available==true){kos_WriteTextToWindow (30,150,0x80,0x000000, "<7> 50 ­  50", 0);}
628
                if (callfriendavailable==true){kos_WriteTextToWindow (150,150,0x80,0x000000, "<8> ‡ў®­®Є ¤агЈг", 0);}
629
                if (zalavailable==true){kos_WriteTextToWindow (280,150,0x80,0x000000, "<9> Џ®¤бЄ §Є  § « ", 0);}
630
 
631
                if((na50available==false)&&(callfriendavailable==false)&&(zalavailable==false)) {kos_WriteTextToWindow (30,150,0x80,0x000000, " - § Ўа вм ¤Ґ­мЈЁ Ё г©вЁ", 0);}
632
 
633
                kos_WriteTextToWindow (430,130,0x80,0x000000, "‚®Їа®б ­ ", 0);
634
		kos_WriteTextToWindow (500,130,0x80,0x000000, summs[currentquestion], 0);
635
 
636
                kos_WriteTextToWindow (430,150,0x80,0x000000, "“ ў б", 0);
637
		kos_WriteTextToWindow (500,150,0x80,0x000000, summs[currentquestion-1], 0);
638
 
639
 
640
 
641
	}
642
	if (status==2){ //Окно "Это - правильный ответ"
2830 leency 643
		kos_DrawBar(0,0,610,175,0xDDFFDD);
1805 yogev_ezra 644
                kos_WriteTextToWindow (10,10,0x80,0x000000, "„ , нв® Їа ўЁ«м­л© ®вўҐв!", 0);
645
 
646
                kos_WriteTextToWindow (10,150,0x80,0x000000, " - Їа®¤®«¦Ёвм", 0);
647
	}
648
	if (status==3){ //Вы выиграли миллион, однако ж!!!
2830 leency 649
		kos_DrawBar(0,0,610,175,0x00FF00);
1805 yogev_ezra 650
                kos_WriteTextToWindow (10,10,0x80,0x000000, "‚л ўлЁЈа «Ё ¬Ё««Ё®­!!!", 0);
651
                kos_WriteTextToWindow (10,150,0x80,0x000000, " - ўл室", 0);
652
	}
653
	if (status==4){ //Звонок другу
2830 leency 654
		kos_DrawBar(0,0,610,175,0xAAFFFF);
1805 yogev_ezra 655
                kos_WriteTextToWindow (10,10,0x80,0x000000, "„агЈ б®ўҐвгҐв ў ¬ ®вўҐв", 0);
656
		kos_WriteTextToWindow (165,10,0x80,0x000000, friendsAdvice, 0);
657
                kos_WriteTextToWindow (10,150,0x80,0x000000, " - Їа®¤®«¦Ёвм", 0);
658
	}
659
	if (status==5){ //Подсказка зала
2830 leency 660
		kos_DrawBar(0,0,610,175,0xAAFFFF);
1805 yogev_ezra 661
                kos_WriteTextToWindow (10,10,0x80,0x000000, "Њ­Ґ­ЁҐ  г¤Ёв®аЁЁ а бЇаҐ¤Ґ«Ё«®бм в Є:", 0);
662
		if (drawA==true){
663
                        kos_WriteTextToWindow (10,30,0x80,0x000000, "ЋвўҐв A:  ", 0);
664
			kos_DisplayNumberToWindow(zalA,3,60,30,0x000000,nbDecimal,0);
665
			kos_WriteTextToWindow (80,30,0x80,0x000000, "%", 0);
666
		}
667
		if (drawB==true){
668
                        kos_WriteTextToWindow (10,45,0x80,0x000000, "ЋвўҐв B:  ", 0);
669
			kos_DisplayNumberToWindow(zalB,3,60,45,0x000000,nbDecimal,0);
670
			kos_WriteTextToWindow (80,45,0x80,0x000000, "%", 0);
671
		}
672
		if (drawC==true){
673
                        kos_WriteTextToWindow (10,60,0x80,0x000000, "ЋвўҐв C:  ", 0);
674
			kos_DisplayNumberToWindow(zalC,3,60,60,0x000000,nbDecimal,0);
675
			kos_WriteTextToWindow (80,60,0x80,0x000000, "%", 0);
676
		}
677
		if (drawD==true){
678
                        kos_WriteTextToWindow (10,75,0x80,0x000000, "ЋвўҐв D:  ", 0);
679
			kos_DisplayNumberToWindow(zalD,3,60,75,0x000000,nbDecimal,0);
680
			kos_WriteTextToWindow (80,75,0x80,0x000000, "%", 0);
681
		}
682
 
683
 
684
 
685
 
686
 
687
                kos_WriteTextToWindow (10,150,0x80,0x000000, " - Їа®¤®«¦Ёвм", 0);
688
	}
689
 
690
	if (status==6){ //Вы забрали деньги ;-)
2830 leency 691
		kos_DrawBar(0,0,610,175,0xBBFFBB);
1805 yogev_ezra 692
                kos_WriteTextToWindow (10,10,0x80,0x000000, "‚л § Ўа «Ё ¤Ґ­мЈЁ Ё ги«Ё. ‚ и ўлЁЈали б®бв ўЁ«:", 0);
693
		kos_WriteTextToWindow (10,20,0x80,0x000000, summs[currentquestion-1], 0);
694
                kos_WriteTextToWindow (10,150,0x80,0x000000, " - ўл室", 0);
695
	}
696
	if (status==-1){ //Вы ошиблись :-(
2830 leency 697
		kos_DrawBar(0,0,610,175,0xFF8888);
1805 yogev_ezra 698
                kos_WriteTextToWindow (10,10,0x80,0x000000, "Љ ᮦ «Ґ­Ёо, ўл ®иЁЎ«Ёбм... Џа ўЁ«м­л© ®вўҐв -", 0);
699
 
700
		switch (correctanswer){
701
		case 0x01:
702
			kos_WriteTextToWindow (10,25,0x80,0x000000, "A. ", 0);
703
			kos_WriteTextToWindow (30,25,0x0,0x000000, answerA, answerAlength-1);
704
			break;
705
		case 0x02:
706
			kos_WriteTextToWindow (10,25,0x80,0x000000, "B. ", 0);
707
			kos_WriteTextToWindow (30,25,0x0,0x000000, answerB, answerBlength-1);
708
			break;
709
		case 0x03:
710
			kos_WriteTextToWindow (10,25,0x80,0x000000, "C. ", 0);
711
			kos_WriteTextToWindow (30,25,0x0,0x000000, answerC, answerClength-1);
712
			break;
713
		case 0x04:
714
			kos_WriteTextToWindow (10,25,0x80,0x000000, "D. ", 0);
715
			kos_WriteTextToWindow (30,25,0x0,0x000000, answerD, answerDlength-1);
716
			break;
717
		}
718
        kos_WriteTextToWindow (10,50,0x80,0x000000, "‚ १г«мв вҐ ўл ўлЁЈа «Ё:", 0);
719
 
720
	if (currentquestion<6) {kos_WriteTextToWindow (220,50,0x80,0x000000,summs[0], 0);}
721
	if ((currentquestion>5)&&(currentquestion<11)) {kos_WriteTextToWindow (220,50,0x80,0x000000,summs[5], 0);}
722
	if (currentquestion>10) {kos_WriteTextToWindow (220,50,0x80,0x000000,summs[10], 0);}
723
 
724
 
725
 
726
 
727
        kos_WriteTextToWindow (10,150,0x80,0x000000, " - ўл室", 0);
728
	}
729
 
730
}
731
 
732
 
733
 
734
void call_friend(){
735
	int tmpcodee;
736
 
737
	recode5:
738
	tmpcodee =(rtlRand()%10)+1;
739
	int tmpbyte;
740
 
741
	if (currentquestion < 6 ){
742
		if (tmpcodee>3){ //Друг знает
743
			if (correctanswer==0x01) {friendsAdvice[0]='A';}
744
			if (correctanswer==0x02) {friendsAdvice[0]='B';}
745
			if (correctanswer==0x03) {friendsAdvice[0]='C';}
746
			if (correctanswer==0x04) {friendsAdvice[0]='D';}
747
		}
748
		else //Друг говорит наугад
749
		{
750
 
751
			int tmpbyte2=0;
752
			recode51:
753
			int tmpcodee2=(rtlRand()%4)+1;
754
 
755
			switch(tmpcodee2){
756
			case 1:
757
				friendsAdvice[0]='A';
758
				break;
759
			case 2:
760
				friendsAdvice[0]='B';
761
				break;
762
			case 3:
763
				friendsAdvice[0]='C';
764
				break;
765
			case 4:
766
				friendsAdvice[0]='D';
767
				break;
768
			}
769
		}
770
 
771
	}
772
 
773
	if ((currentquestion > 5) && (currentquestion<11)){
774
		if (tmpcodee>5){ //Друг знает
775
			if (correctanswer==0x01) {friendsAdvice[0]='A';}
776
			if (correctanswer==0x02) {friendsAdvice[0]='B';}
777
			if (correctanswer==0x03) {friendsAdvice[0]='C';}
778
			if (correctanswer==0x04) {friendsAdvice[0]='D';}
779
		}
780
		else //Друг говорит наугад
781
		{
782
 
783
			int tmpbyte2=0;
784
			recode52:
785
			int tmpcodee2=(rtlRand()%4)+1;
786
			switch(tmpcodee2){
787
			case 1:
788
				friendsAdvice[0]='A';
789
				break;
790
			case 2:
791
				friendsAdvice[0]='B';
792
				break;
793
			case 3:
794
				friendsAdvice[0]='C';
795
				break;
796
			case 4:
797
				friendsAdvice[0]='D';
798
				break;
799
			}
800
		}
801
 
802
	}
803
 
804
	if (currentquestion > 10){
805
		if (tmpcodee>7){ //Друг знает
806
			if (correctanswer==0x01) {friendsAdvice[0]='A';}
807
			if (correctanswer==0x02) {friendsAdvice[0]='B';}
808
			if (correctanswer==0x03) {friendsAdvice[0]='C';}
809
			if (correctanswer==0x04) {friendsAdvice[0]='D';}
810
		}
811
		else //Друг говорит наугад
812
		{
813
 
814
			int tmpbyte2=0;
815
			recode53:
816
			int tmpcodee2=(rtlRand()%4)+1;
817
 
818
			switch(tmpcodee2){
819
			case 1:
820
				friendsAdvice[0]='A';
821
				break;
822
			case 2:
823
				friendsAdvice[0]='B';
824
				break;
825
			case 3:
826
				friendsAdvice[0]='C';
827
				break;
828
			case 4:
829
				friendsAdvice[0]='D';
830
				break;
831
			}
832
		}
833
 
834
		if ((friendsAdvice[0]=='A')&&(drawA==false)){goto recode5;}
835
		if ((friendsAdvice[0]=='B')&&(drawB==false)){goto recode5;}
836
		if ((friendsAdvice[0]=='C')&&(drawC==false)){goto recode5;}
837
		if ((friendsAdvice[0]=='D')&&(drawD==false)){goto recode5;}
838
	}
839
 
840
 
841
 
842
 
843
 
844
 
845
}
846
 
847
void call_zal(){ //Подсказка зала
848
	int maxpercent=0;
849
	for (int tmpc=0; tmpc<(16-currentquestion);tmpc=tmpc+2){
850
		maxpercent=(rtlRand()%101);
851
		if (maxpercent>50) {break;}
852
	}
853
 
854
	if ((drawA==true)&&(drawB==true)&&(drawC==true)&&(drawD==true)){
855
		switch (correctanswer){
856
		case 0x01:
857
		zalA=maxpercent;
858
		zalB=(rtlRand()%(101-zalA));
859
		zalC=(rtlRand()%(101-zalA-zalB));
860
		zalD=100-zalA-zalB-zalC;
861
		break;
862
 
863
		case 0x02:
864
		zalB=maxpercent;
865
		zalA=(rtlRand()%(101-zalB));
866
		zalC=(rtlRand()%(101-zalA-zalB));
867
		zalD=100-zalA-zalB-zalC;
868
		break;
869
 
870
		case 0x03:
871
		zalC=maxpercent;
872
		zalB=(rtlRand()%(101-zalC));
873
		zalA=(rtlRand()%(101-zalC-zalB));
874
		zalD=100-zalA-zalB-zalC;
875
		break;
876
 
877
		case 0x04:
878
		zalD=maxpercent;
879
		zalB=(rtlRand()%(101-zalD));
880
		zalC=(rtlRand()%(101-zalD-zalB));
881
		zalA=100-zalD-zalB-zalC;
882
		break;
883
		}
884
	}
885
	else
886
	{
887
		if ((drawA==true)&&(drawB==true)){
888
			if (correctanswer==0x01){
889
				zalA=maxpercent;
890
				zalB=100-zalA;
891
			}
892
			else
893
			{
894
				zalB=maxpercent;
895
				zalA=100-zalB;
896
			}
897
		}
898
		if ((drawA==true)&&(drawC==true)){
899
			if (correctanswer==0x01){
900
				zalA=maxpercent;
901
				zalC=100-zalA;
902
			}
903
			else
904
			{
905
				zalC=maxpercent;
906
				zalA=100-zalC;
907
			}
908
		}
909
		if ((drawA==true)&&(drawD==true)){
910
			if (correctanswer==0x01){
911
				zalA=maxpercent;
912
				zalD=100-zalA;
913
			}
914
			else
915
			{
916
				zalD=maxpercent;
917
				zalA=100-zalD;
918
			}
919
		}
920
 
921
		if ((drawB==true)&&(drawC==true)){
922
			if (correctanswer==0x02){
923
				zalB=maxpercent;
924
				zalC=100-zalB;
925
			}
926
			else
927
			{
928
				zalC=maxpercent;
929
				zalB=100-zalC;
930
			}
931
		}
932
		if ((drawB==true)&&(drawD==true)){
933
			if (correctanswer==0x02){
934
				zalB=maxpercent;
935
				zalD=100-zalB;
936
			}
937
			else
938
			{
939
				zalD=maxpercent;
940
				zalB=100-zalD;
941
			}
942
		}
943
 
944
		if ((drawC==true)&&(drawD==true)){
945
			if (correctanswer==0x03){
946
				zalC=maxpercent;
947
				zalD=100-zalC;
948
			}
949
			else
950
			{
951
				zalD=maxpercent;
952
				zalC=100-zalD;
953
			}
954
		}
955
 
956
	}
957
}
958
 
959
void kos_Main(){
960
	rtlSrand(kos_GetSystemClock() / 10000);
2830 leency 961
	kos_InitHeap();
1805 yogev_ezra 962
	getFilePathName();
963
	prepareFileData();
964
	draw_window();
965
	while (true){
966
 
967
		switch (kos_WaitForEvent()){
968
		case 1:
969
			draw_window();
970
			break;
971
		case 2:
972
			Byte keyCode;
973
			kos_GetKey(keyCode);
974
 
975
			if (status==0){ //Меню
976
				if (keyCode==27){
977
					app_halt();
978
				}
979
				if (keyCode==13){
980
					currentquestion=1;
981
					status=1;
982
					loadquestion();
983
					////// ПОМЕНЯТЬ МЕСТАМИ!!!!!!! /////////
984
					draw_window();
985
 
986
				}
987
			}
988
			if (status==1){ //Игра
989
 
990
			if (keyCode==8){
991
				status=6;
992
				draw_window();
993
			}
994
 
995
			if (drawA==true){
996
			if ((keyCode==49)||(keyCode==97)||(keyCode==65)){
997
					if (correctanswer==0x01){
998
						status=2;
999
					}
1000
					else
1001
					{
1002
						status=-1;
1003
					}
1004
					drawA = true;
1005
					drawB = true;
1006
					drawC = true;
1007
					drawD = true;
1008
 
1009
					draw_window();
1010
			}
1011
			}
1012
 
1013
			if (drawB==true){
1014
			if ((keyCode==50)||(keyCode==98)||(keyCode==66)){
1015
					if (correctanswer==0x02){
1016
						status=2;
1017
					}
1018
					else
1019
					{
1020
						status=-1;
1021
					}
1022
					drawA = true;
1023
					drawB = true;
1024
					drawC = true;
1025
					drawD = true;
1026
 
1027
					draw_window();
1028
				}
1029
			}
1030
			if (drawC==true){
1031
			if ((keyCode==51)||(keyCode==99)||(keyCode==67)){
1032
					if (correctanswer==0x03){
1033
						status=2;
1034
					}
1035
					else
1036
					{
1037
						status=-1;
1038
					}
1039
					drawA = true;
1040
					drawB = true;
1041
					drawC = true;
1042
					drawD = true;
1043
 
1044
					draw_window();
1045
				}
1046
			}
1047
			if (drawD==true){
1048
			if ((keyCode==52)||(keyCode==100)||(keyCode==68)){
1049
					if (correctanswer==0x04){
1050
						status=2;
1051
					}
1052
					else
1053
					{
1054
						status=-1;
1055
					}
1056
					drawA = true;
1057
					drawB = true;
1058
					drawC = true;
1059
					drawD = true;
1060
 
1061
					draw_window();
1062
			}
1063
			}
1064
 
1065
			if (callfriendavailable==true){ //Реализация подсказки "Звонок другу"
1066
				if (keyCode==56){
1067
					callfriendavailable=false;
1068
					status=4;
1069
					call_friend();
1070
					draw_window();
1071
				}
1072
			}
1073
 
1074
			if (zalavailable==true){ //Реализация подсказки зала
1075
				if (keyCode==57){
1076
					zalavailable=false;
1077
					status=5;
1078
					call_zal();
1079
					draw_window();
1080
				}
1081
			}
1082
 
1083
			if (na50available==true){ //Реализация подсказки "50 на 50"
1084
			if (keyCode==55){
1085
 
1086
				if (correctanswer==0x01){
1087
					drawA=true;
1088
 
1089
						int tmpcodee;
1090
 
1091
						recode1:
1092
						tmpcodee =(rtlRand()%3)+1;
1093
 
1094
						int tmpbyte;
1095
 
1096
						switch(tmpcodee){
1097
						case 1:
1098
							drawB=true;
1099
							drawC=false;
1100
							drawD=false;
1101
							break;
1102
						case 2:
1103
							drawB=false;
1104
							drawC=true;
1105
							drawD=false;
1106
						case 3:
1107
							drawB=false;
1108
							drawC=false;
1109
							drawD=true;
1110
 
1111
						}
1112
				}
1113
				if (correctanswer==0x02){
1114
					drawB=true;
1115
 
1116
						int tmpcodee;
1117
 
1118
						recode2:
1119
						tmpcodee =(rtlRand()%3)+1;
1120
 
1121
						int tmpbyte;
1122
 
1123
 
1124
						switch(tmpcodee){
1125
						case 1:
1126
							drawA=true;
1127
							drawC=false;
1128
							drawD=false;
1129
							break;
1130
						case 2:
1131
							drawA=false;
1132
							drawC=true;
1133
							drawD=false;
1134
						case 3:
1135
							drawA=false;
1136
							drawC=false;
1137
							drawD=true;
1138
 
1139
						}
1140
				}
1141
				if (correctanswer==0x03){
1142
					drawC=true;
1143
 
1144
						int tmpcodee;
1145
 
1146
						recode3:
1147
						tmpcodee =(rtlRand()%3)+1;
1148
						int tmpbyte;
1149
 
1150
 
1151
						switch(tmpcodee){
1152
						case 1:
1153
							drawB=true;
1154
							drawA=false;
1155
							drawD=false;
1156
							break;
1157
						case 2:
1158
							drawB=false;
1159
							drawA=true;
1160
							drawD=false;
1161
						case 3:
1162
							drawB=false;
1163
							drawA=false;
1164
							drawD=true;
1165
 
1166
						}
1167
				}
1168
				if (correctanswer==0x04){
1169
					drawA=true;
1170
 
1171
						int tmpcodee;
1172
 
1173
						recode4:
1174
						tmpcodee =(rtlRand()%3)+1;
1175
 
1176
						int tmpbyte;
1177
 
1178
 
1179
						switch(tmpcodee){
1180
						case 1:
1181
							drawB=true;
1182
							drawC=false;
1183
							drawA=false;
1184
							break;
1185
						case 2:
1186
							drawB=false;
1187
							drawC=true;
1188
							drawA=false;
1189
						case 3:
1190
							drawB=false;
1191
							drawC=false;
1192
							drawA=true;
1193
 
1194
						}
1195
				}
1196
				na50available=false;
1197
				draw_window();
1198
 
1199
			}
1200
			}
1201
 
1202
			}
1203
			if (status==2){ //Окно "Это - правильный ответ!"
1204
				if (keyCode==13){
1205
					if (currentquestion<15){
1206
						currentquestion++;
1207
						status=1;
1208
						loadquestion();
1209
						draw_window();
1210
					}
1211
					else
1212
					{
1213
						status=3;
1214
						draw_window();
1215
					}
1216
 
1217
				}
1218
			}
1219
			if (status==3){ //Вы выиграли миллион
1220
				if (keyCode==27){
1221
					app_halt();
1222
				}
1223
			}
1224
			if (status==4){ //Совет друга
1225
				if (keyCode==13){
1226
					status=1;
1227
					draw_window();
1228
				}
1229
			}
1230
			if (status==5){ //Подсказка зала
1231
				if (keyCode==13){
1232
					status=1;
1233
					draw_window();
1234
				}
1235
			}
1236
			if (status==6){ //Вы забрали деньги ;-)
1237
				if (keyCode==27){
1238
					app_halt();
1239
				}
1240
			}
1241
			if (status==-1){ //Вы ошиблись :-(
1242
				if (keyCode==27){
1243
					app_halt();
1244
				}
1245
			}
1246
 
1247
			//kos_DrawBar(38,118,50,130,0xBBBBBB);
1248
			//kos_DisplayNumberToWindow (keyCode,3,40,120,0x000000, nbDecimal, false);
1249
 
1250
 
1251
			break;
1252
		case 3:
1253
			app_halt();
1254
			break;
1255
		}
1256
 
1257
	}
1258
}
1259
 
1260
 
1261
void app_halt(){
1262
	delete filepathname;
1263
 
1264
	if (needcleanup==true){
1265
		delete question;
1266
		delete answerA;
1267
		delete answerB;
1268
		delete answerC;
1269
		delete answerD;
1270
	}
1271
	kos_ExitApp();
1272
}