Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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