This repository has been archived by the owner on Mar 30, 2019. It is now read-only.
/
Snake.pas
1175 lines (1000 loc) · 26.6 KB
/
Snake.pas
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program _snake;
uses Crt, SnakeLib;
var snake: tSnake;
block: array [1..100] of tTemporaryPoint;
speed, auxBrightFood, contCrazyFood, blockFrequency: byte;
foods, score, snakeLength, auxCrazyFood, blockLength: word;
food: tPoint;
brightFood, crazyFood: tTemporaryPoint;
brightFoodOn, crazyFoodOn: Boolean;
cheat: array [1..5] of tCheat;
MainMenuOp, OptionsMenuOp, ColorsMenuOp: integer;
chdcolor, hdcolor, color, hcolor, foodColor, brightFoodColor, crazyFoodColor, snakeColor: byte;
{ Logo procedures }
procedure drawLogo(x, y: byte); forward;
{ Essential procedures }
procedure initDefaults; forward;
procedure initSnake; forward;
procedure initGame; forward;
procedure initCheats; forward;
{ Gaming functions }
function inSnake(p: tPoint; ini: integer): boolean; forward;
function inBlock(p: tPoint): boolean; forward;
procedure increaseSnake; forward;
function isValidPosition(point: tPoint): boolean; forward;
function isCheat(password: string): integer; forward;
function oppositeTo(ch: char): char; forward;
procedure moveTo(ch: char; var lose: boolean); forward;
procedure play; forward;
{ Drawing procedures }
procedure restore; forward;
procedure drawHeader; forward;
procedure drawScenario; forward;
procedure drawSnake; forward;
procedure eraseSnake; forward;
{ Block related procedures }
procedure addBlock; forward;
procedure drawBlocks; forward;
procedure manageBlocks; forward;
{ Food related procedures }
procedure generateFood; forward;
procedure drawFood; forward;
procedure generateBrightFood; forward;
procedure drawBrightFood; forward;
procedure manageBrightFood; forward;
procedure generateCrazyFood; forward;
procedure manageCrazyFood; forward;
procedure moveCrazyFood; forward;
procedure drawCrazyFood; forward;
procedure eraseCrazyFood; forward;
procedure checkFoods; forward;
{ Best Scores }
var scoresFile: file of tRecordInfo;
procedure openScoresFile; forward;
function isRecord(score: word): boolean; forward;
procedure insertRecord(rec: tRecordInfo); forward;
{ Navigation menus }
procedure mainMenu; forward;
procedure bestScoresMenu; forward;
procedure cheatsMenu; forward;
function pauseMenu: boolean; forward;
function youLoseScreen: boolean; forward;
procedure optionsMenu; forward;
procedure colorsMenu; forward;
{ Logo procedures }
procedure drawLogo(x, y: byte);
const logoy = 23;
const logo: array [1..logoy] of string[80] = (
' .. ... . . . . . ........................................',
' . . ....... .....................Copyright 2009 By Luiz Rodrigo a.k.a LuLu...',
'..... . $NNNMNN.... ... ... ....... Some rights reversed...',
'......DNMMNNMNDM: . . . . . ... ...$NNM.... ... ... ... ... ... ...',
'.....MMNMN8ZONNNN . ... .. NNMN.... ... ... ... ... ... ...',
'. .. NMNMM .NMDN ?NMN . .. ,NNMNND7... NNMN.... ... ... .+OZOO? ... ...',
'. .. NNNMM? DMDN NMNMMNMNMNNN. .DMMMMMNNNMN.. NNMD. .,NNMMN .,NNMMMNMNND. ..',
'......NNMMNNI . NMMMNMMDMMDNM .NNNNMM8MMMNZ..MMMM. ZMMNNZ..ZMMDNMNMNMMM7 ...',
'.... .=MMDNNMN7 MNNN OMNM$ MNNN~ MMNMN. MMNM NNMMM ZMNND. ... NNM. ..',
'.... ..,NDNMNDM MNNN =NMDM . .NMMNN .NMMMMNNMM... NDMD7.. .. NMM ...',
'......... MMNMM.NNND :MMDN 8NMMMNNMMM NMNMMNNN . MDNNNNMMNMNNNM~ ..',
'. . .MNMZ NDMN NNMM. MMNM.8MMNMMMNMMNN. NMDNNMNNN,. MNMMMMMNMMNNDN ..',
'.....MMNM8II?NNDM NNNN. MMMM,MMMNM. .NMNN..NMDMNMMNNM$ MMMNM..... . .. ...',
'. . ~NNMNNMNMMD$ MDNM NMMN:NNMNN ..MMMD MMNDM.MNNMMM MMNDM. MNND ..',
'. .. INNNMMNMN. .MNNM MMMN MNNNMMNMDMMN .MMNDM,.ZMNMMZ.MNMNNNMMNMMN=.....',
'. . .?ND$. .NNM N v 1.0 final NNM .NNMMN ...NN. ..DNNMNMNMMN... ...',
'. $= .. .. .. .. .. :NMNN7. .. ...',
'......... Chuck Norris Quality Seal . ........................................',
'. . . . . . . . . . ..',
'. Licensed by Chuck Norris Software Attribution 3.0: . . . .. .... ',
'. Chuck Norris is watching you... .. . . . . . . . .. .... ',
' .. ... . . . . . ........................................',
' .. ... . . . . . .....................................'
);
var i: integer;
begin
for i:= 1 to logoy do begin
gotoxy(x, y + i - 1);
writeln(logo[i]);
end;
end;
{ Essential }
procedure initDefaults;
begin
randomize;
color:= lightgray;
hcolor:= white;
foodColor:= green;
brightFoodColor:= yellow + blink;
crazyFoodColor:= red + blink;
snakeColor:= white;
MainMenuOp:= 1;
OptionsMenuOp:= 1;
ColorsMenuOp:= 1;
BlockFrequency:= 3;
brightFoodOn:= true;
crazyFoodOn:= true;
speed:= 5;
initCheats;
end;
procedure initSnake;
var i: integer;
begin
snakeLength:= 3;
snake[1].x:= width div 2;
snake[1].y:= height div 2;
for i:=2 to SnakeLength do begin
snake[i].x:= snake[i - 1].x - 1;
snake[i].y:= snake[i - 1].y;
end;
end;
procedure initGame;
begin
blockLength:= 0;
auxBrightFood:= 0;
brightfood.plays:= 0;
auxCrazyFood:= 0;
crazyfood.plays:= 0;
score:= 0;
foods:= 0;
hdcolor:= snakecolor;
chdcolor:= 0;
drawScenario;
initSnake;
drawSnake;
generateFood;
end;
procedure initCheats;
begin
cheat[PhantomCheat].password:= 'PHNTMFTHPR';
cheat[PhantomCheat].description:=
'With "Phantom of the Opera" cheat, you can go within the walls! If you go into a wall, you''ll appear at the opposite wall.';
cheat[PhantomCheat].activated:= false;
cheat[ChildCheat].password:= 'PTRPN';
cheat[ChildCheat].description:=
'With "Peter Pan" cheat, the snake will ever be little and won''t ever grow.';
cheat[ChildCheat].activated:= false;
cheat[SlowlyCrazyFoodCheat].password:= 'SPDFLGHT';
cheat[SlowlyCrazyFoodCheat].description:=
'With "Speed of Light" cheat, the crazy food will move less frequently.';
cheat[SlowlyCrazyFoodCheat].activated:= false;
cheat[BrightFoodForeverCheat].password:= 'KNGFYMMK';
cheat[BrightFoodForeverCheat].description:=
'With "King of Yamimakai" cheat, there will ever be a bright food.';
cheat[BrightFoodForeverCheat].activated:= false;
cheat[CrazyFoodForeverCheat].password:= 'VDLKCMDNTBDSS';
cheat[CrazyFoodForeverCheat].description:=
'With "Vida Loka Comanda NT Obedesse" cheat, there will ever be a crazy food.';
cheat[CrazyFoodForeverCheat].activated:= false;
end;
{ Gaming }
function inSnake(p: tPoint; ini: integer): boolean;
var i: integer;
begin
for i:= ini to snakeLength do
if (p.x = snake[i].x) and (p.y = snake[i].y) then begin
inSnake:= true;
exit;
end;
inSnake:= false;
end;
function inBlock(p: tPoint): boolean;
var i: integer;
begin
if blockFrequency = 0 then begin
inBlock:= false;
exit;
end;
for i:= 1 to blockLength do
if ( p.x = block[i].x) and ( p.y = block[i].y ) then begin
inBlock:= true;
exit;
end;
inBlock:= false;
end;
procedure increaseSnake;
begin
inc(snakeLength);
snake[snakeLength]:= snake[snakeLength - 1];
if snake[1].x <> (snake[snakeLength].x + 1) then
inc(snake[snakeLength].x)
else if snake[1].x <> (snake[snakeLength].x - 1) then
dec(snake[snakeLength].x)
else if snake[1].y <> (snake[snakeLength].y - 1) then
dec(snake[snakeLength].y)
else if snake[1].y <> (snake[snakeLength].y - 1) then
inc(snake[snakeLength].y)
else dec(snakeLength);
end;
function isValidPosition(point: tPoint): boolean;
begin
isValidPosition:= (point.x in [1..width]) and (point.y in [1..height]) and not inBlock(point);
end;
function oppositeTo(ch: char): char;
begin
if ch = up then oppositeTo:= down
else if ch = down then oppositeTo:= up
else if ch = left then oppositeTo:= right
else if ch = right then oppositeTo:= left
else oppositeTo:= #0;
end;
procedure moveTo(ch: char; var lose: boolean);
var i: integer;
begin
manageBlocks;
if not (ch in [up, down, left, right]) then exit;
for i:=snakeLength downto 2 do
snake[i]:= snake[i - 1];
case ch of
up: dec(snake[1].y);
down: inc(snake[1].y);
left: dec(snake[1].x);
right: inc(snake[1].x);
end;
if cheat[PhantomCheat].activated then
if snake[1].x = 0 then
snake[1].x:= width
else if snake[1].y = 0 then
snake[1].y:= height
else if snake[1].x = (width + 1) then
snake[1].x:= 1
else if snake[1].y = (height + 1) then
snake[1].y:= 1;
if inSnake(snake[1], 2) or (not isValidPosition(snake[1])) then begin
lose:= true;
exit;
end;
checkFoods;
lose:= false;
end;
procedure play;
var mov, movaux, mov2: char;
lose, quit: boolean;
i: integer;
cont: array [1..5] of integer;
begin
repeat
mov:= right;
movaux:= right;
mov2:= right;
for i:= 1 to 5 do
cont[i]:= 0;
repeat
delay( (10 - speed) * 50 div 3);
if blockFrequency > 0 then begin
for i:=1 to blockFrequency do begin
if cont[i] = 0 then
cont[i]:= 50 + random(50) + random(100) + random(i * i);
if cont[i] = 1 then
addBlock;
if cont[i] > 0 then
dec(cont[i]);
end;
end;
mov2:= movaux;
movaux:= mov;
if keypressed then
mov:= readkey;
if mov = oppositeTo(mov2) then
mov:= mov2;
if mov = esc then
if pauseMenu then begin
for i:= 1 to 5 do
cheat[i].activated:= false;
exit;
end
else begin
mov:= mov2;
restore;
end;
eraseSnake;
moveTo(mov, lose);
if lose then begin
drawSnake;
delay(1000);
if youLoseScreen then begin
initGame;
auxBrightFood:= 0;
break;
end
else exit;
end;
drawSnake;
until false;
until false;
end;
{ Drawing }
procedure restore;
begin
drawScenario;
drawSnake;
if blockFrequency > 0 then
drawBlocks;
drawFood;
if BrightFoodOn and (brightFood.plays <> 0) then
drawBrightFood;
if CrazyFoodOn and (crazyFood.plays <> 0) then
drawCrazyFood;
end;
procedure drawHeader;
begin
textcolor(color);
gotoxy(1, 1);
write('Speed: ');
textcolor(hcolor);
write(speed:2,'x');
textcolor(color);
gotoxy(20, 1);
write('Block frequency: ');
textcolor(hcolor);
write(blockFrequency:2,'x');
textcolor(color);
gotoxy(50, 1);
write('Foods: ');
textcolor(hcolor);
write(foods:2);
textcolor(color);
gotoxy(69, 1);
write('Score: ');
textcolor(hcolor);
write(score:4);
end;
procedure drawScenario;
var i: integer;
begin
clrscr;
drawHeader;
textcolor(color);
gotoxy(minX, minY);
for i:=minX to (minX + width + 1) do
write(fillHoriz);
gotoxy(minX, minY + height + 1);
for i:=minX to (minx + width + 1) do
write(fillHoriz);
for i:=minY to (minY + height + 1) do begin
gotoxy(minX, i);
write(fillVert);
gotoxy(minX + width + 1, i);
write(fillVert);
end;
gotoxy(minX, minY);
write(fillNW);
gotoxy(minX + width + 1, minY);
write(fillNE);
gotoxy(minX, minY + height + 1);
write(fillSW);
gotoxy(minX + width + 1, minY + height + 1);
write(fillSE);
end;
procedure drawSnake;
var i: integer;
begin
textcolor(snakeColor);
for i:=2 to snakeLength do begin
gotoxy(snake[i].x + minX, snake[i].y + minY);
write(snakeBody);
end;
textcolor(hdcolor);
gotoxy(snake[1].x + minX, snake[1].y + minY);
write(snakeHead);
textcolor(color);
end;
procedure eraseSnake;
var i: integer;
begin
for i:=1 to snakeLength do begin
gotoxy(snake[i].x + minX, snake[i].y + minY);
write(' ');
end;
end;
{ Blocks }
procedure addBlock;
begin
repeat
block[blockLength + 1].x:= random(width - 1) + 1;
block[blockLength + 1].y:= random(height - 1) + 1;
until (not inSnake(food, 1)) and
( (block[blockLength + 1].x <> food.x) or (block[blockLength + 1].y <> food.y) ) and
( (block[blockLength + 1].x <> brightFood.x) or (block[blockLength + 1].y <> brightFood.y) ) and
( (block[blockLength + 1].x <> crazyFood.x) or (block[blockLength + 1].y <> crazyFood.y) ) and
(abs( snake[1].x - block[blockLength + 1].x ) >= 3) and
(abs( snake[1].y - block[blockLength + 1].y ) >= 3);
inc(blockLength);
block[blockLength].plays:= 100 * ( 10 - blockFrequency );
gotoxy(block[blockLength].x + minX, block[blockLength].y + minY);
write(blockChar);
end;
procedure drawBlocks;
var i: integer;
begin
for i:= 1 to blockLength do begin
gotoxy(block[i].x + minX, block[i].y + minY);
write(blockChar);
end;
end;
procedure manageBlocks;
var i, j: integer;
begin
for i:= 1 to BlockLength do
if block[i].plays = 0 then begin
gotoxy(block[i].x + minX, block[i].y + minY);
write(' ');
for j:= i to blockLength - 1 do
block[j]:= block[j + 1];
dec(blockLength);
end
else
dec(block[i].plays);
end;
{ Foods }
procedure generateFood;
begin
repeat
food.x:= random(width - 1) + 1;
food.y:= random(height - 1) + 1;
until not inSnake(food, 1) and not inBlock(food);
drawFood;
end;
procedure drawFood;
begin
textcolor(foodColor);
gotoxy(minX + food.x, minY + food.y);
write(foodChar);
textcolor(color);
end;
procedure generateBrightFood;
begin
repeat
brightFood.x:= random(width - 1) + 1;
brightFood.y:= random(height - 1) + 1;
until not inSnake(brightFood, 1) and not((brightFood.x = food.x) and (brightFood.y = food.y)) and not inBlock(brightFood);
brightFood.plays:= 30 + random(30) + abs(snake[1].x - brightFood.x) + abs(snake[1].y - brightFood.y);
drawBrightFood;
end;
procedure drawBrightFood;
begin
textcolor(brightFoodColor);
gotoxy(minX + brightFood.x, minY + brightFood.y);
write(foodChar);
textcolor(color);
end;
procedure manageBrightFood;
begin
if auxBrightFood = 1 then begin
generateBrightFood;
dec(auxBrightFood);
end;
if brightFood.plays > 0 then begin
dec(brightFood.plays);
exit;
end;
if brightFood.plays = 0 then begin
gotoxy(brightFood.x + minX, brightFood.y + MinY);
write(' ');
end;
if cheat[BrightFoodForeverCheat].activated then
auxBrightFood:= 1
else if auxBrightFood = 0 then
auxBrightFood:= random(250)
else
dec(auxBrightFood);
end;
procedure generateCrazyFood;
begin
repeat
crazyFood.x:= random(width - 1) + 1;
crazyFood.y:= random(height - 1) + 1;
until not inSnake(crazyFood, 1) and not inBlock(crazyFood) and
not( (crazyFood.x = food.x) and (crazyFood.y = food.y)) and
not( (crazyFood.x = brightFood.x) and (crazyFood.y = brightFood.y));
crazyFood.plays:= 10 + random(20) + abs(snake[1].x - crazyFood.x) + abs(snake[1].y - crazyFood.y);
drawCrazyFood;
end;
procedure manageCrazyFood;
begin
if auxCrazyFood = 1 then begin
generateCrazyFood;
if cheat[SlowlyCrazyFoodCheat].activated then
contCrazyFood:= 6;
dec(auxCrazyFood);
end;
if crazyFood.plays > 0 then begin
dec(crazyFood.plays);
if cheat[SlowlyCrazyFoodCheat].activated then begin
if contCrazyFood = 0 then begin
contCrazyFood:= 6;
eraseCrazyFood;
moveCrazyFood;
drawCrazyFood;
end
else
dec(contCrazyFood);
end
else begin
eraseCrazyFood;
moveCrazyFood;
drawCrazyFood;
end;
exit;
end;
if crazyFood.plays = 0 then begin
gotoxy(crazyFood.x + minX, crazyFood.y + MinY);
write(' ');
end;
if cheat[CrazyFoodForeverCheat].activated then
auxCrazyFood:= 1
else if auxCrazyFood = 0 then
auxCrazyFood:= 100 + random(500)
else
dec(auxCrazyFood);
end;
procedure moveCrazyFood;
var aux: tPoint;
r, c: integer;
begin
c:= 0;
repeat
inc(c);
aux:= crazyFood;
r:= random(4) + 1;
if c = 10 then exit;
case r of
1: dec(aux.x);
2: inc(aux.x);
3: dec(aux.y);
4: inc(aux.y);
end;
until (isValidPosition(aux) and not inSnake(aux, 1)) and
not( (crazyFood.x = food.x) and (crazyFood.y = food.y)) and
not( (crazyFood.x = brightFood.x) and (crazyFood.y = brightFood.y));
crazyFood.x:= aux.x;
crazyFood.y:= aux.y;
end;
procedure drawCrazyFood;
begin
textcolor(CrazyFoodColor);
gotoxy(minX + crazyFood.x, minY + crazyFood.y);
write(foodChar);
textcolor(color);
end;
procedure eraseCrazyFood;
begin
gotoxy(minX + crazyFood.x, minY + crazyFood.y);
write(' ');
end;
procedure checkFoods;
var i, aux: integer;
b: boolean;
begin
b:= false;
if (snake[1].x = food.x) and (snake[1].y = food.y) then begin
hdcolor:= foodcolor;
chdcolor:= 15;
b:= true;
inc(foods);
inc(score, speed + blockFrequency);
drawHeader;
generateFood;
if not cheat[ChildCheat].activated then
increaseSnake;
end;
if BrightFoodOn then begin
if (brightFood.plays <> 0) and (snake[1].x = brightFood.x) and (snake[1].y = brightFood.y) then begin
hdcolor:= brightFoodColor - blink;
chdcolor:= 15;
b:= true;
inc(foods);
aux:= random(3) + 3;
inc(score, (speed + blockFrequency) * brightFood.plays div aux);
drawHeader;
auxBrightFood:= 0;
brightFood.plays:= 0;
if not cheat[ChildCheat].activated then
for i:=1 to aux do
increaseSnake;
end;
manageBrightFood;
end;
if CrazyFoodOn then begin
if (crazyFood.plays <> 0) and (snake[1].x = crazyFood.x) and (snake[1].y = crazyFood.y) then begin
hdcolor:= CrazyFoodColor - blink;
chdcolor:= 15;
b:= true;
inc(foods);
aux:= random(2) + 3;
inc(score, (speed + blockFrequency) * crazyFood.plays * aux);
drawHeader;
auxCrazyFood:= 0;
crazyFood.plays:= 0;
if not cheat[ChildCheat].activated then
for i:= 1 to aux do
increaseSnake;
end;
manageCrazyFood;
end;
if chdcolor > 0 then begin
dec(chdcolor);
exit;
end;
if b then exit;
hdcolor:= snakeColor;
end;
{ Best Scores }
procedure openScoresFile;
begin
assign(scoresFile, 'records.snk');
{$I-}
reset(scoresFile);
{$I+}
if IOResult <> 0 then begin
rewrite(scoresFile);
reset(scoresFile);
end;
end;
function isRecord(score: word): boolean;
var rInfo: tRecordInfo;
begin
openScoresFile;
if filesize(scoresFile) < 5 then begin
isRecord:= true;
exit;
end;
while not eof(scoresFile) do begin
read(scoresFile, rInfo);
if (score > rInfo.score) then begin
isRecord:= true;
close(scoresFile);
exit;
end;
end;
isRecord:= false;
close(scoresFile);
end;
procedure insertRecord(rec: tRecordInfo);
var s: array [1..5] of tRecordInfo;
len, i, j: integer;
begin
openScoresFile;
len:= 0;
while (not eof(scoresFile)) and (filepos(scoresFile) < 5) do begin
inc(len);
read(scoresFile, s[len]);
end;
if len < 5 then
inc(len);
for i:= 1 to len do
if rec.score > s[i].score then
break;
for j:= len downto i + 1 do
s[j]:= s[j - 1];
s[i]:= rec;
seek(scoresFile, 0);
for i:= 1 to len do
write(scoresFile, s[i]);
close(scoresFile);
end;
{ Menus }
procedure mainMenu;
var menuop: tMenuOptions;
begin
repeat
clrscr;
textcolor(color);
drawLogo(1, 3);
menuop[1]:= 'New Game';
menuop[2]:= 'Best Scores';
menuop[3]:= 'Cheats';
menuop[4]:= 'Options';
menuop[5]:= 'Exit';
MainMenuOP:= selectMenu(menuop, 5, 30, 30, color, hcolor, MainMenuOp);
case MainMenuOp of
1: begin
initGame;
play;
end;
2: bestScoresMenu;
3: cheatsMenu;
4: optionsMenu;
5, 6: exit;
end;
until false;
end;
procedure bestScoresMenu;
var rec: tRecordInfo;
i: integer;
begin
i:= 0;
clrscr;
textcolor(color);
drawLogo(1, 3);
textcolor(hcolor);
gotoxy(35, 30);
write('Blacklist');
gotoxy(25, 32);
write('Nick');
gotoxy(50, 32);
write('Score');
openScoresFile;
textcolor(color);
while not eof(scoresFile) do begin
inc(i);
read(scoresFile, rec);
gotoxy(25, 34 + 2 * filepos(scoresFile));
write(rec.name);
gotoxy(50, 34 + 2 * filepos(scoresFile));
write(rec.score:5);
end;
close(scoresFile);
readkey;
end;
function isCheat(password: string): integer;
var i: integer;
begin
for i:= 1 to 5 do
if upperCase(password) = cheat[i].password then begin
isCheat:= i;
exit;
end;
isCheat:= 0;
end;
procedure cheatsMenu;
var password: string[20];
menu: TMenuOptions;
i, op: integer;
begin
menu[1]:= 'Activate';
menu[2]:= 'Deactivate';
menu[3]:= 'Exit';
repeat
clrscr;
textcolor(color);
drawLogo(1, 3);
textcolor(hcolor);
gotoxy(30, 30);
write('Password: ');
textcolor(color);
readln(password);
if password = '' then
exit;
i:= isCheat(password);
if i = 0 then begin
gotoxy(32, 32);
textcolor(hcolor);
writeln('Invalid Password');
readkey;
end
else begin
textcolor(hcolor);
gotoxy(1, 32);
write('Password: ');
textcolor(color);
writeln(cheat[i].password);
textcolor(hcolor);
write('Description: ');
textcolor(color);
writeln(cheat[i].description);
textcolor(hcolor);
write('Status: ');
textcolor(color);
if cheat[i].activated then
writeln('on')
else
writeln('off');
op:= horizontalMenu(menu, 3, 27, 40, color, hcolor, 2);
case op of
1: begin
cheat[i].activated:= true;
textcolor(hcolor);
gotoxy(30, 44);
write('Activate Successfull!');
end;
2: begin
cheat[i].activated:= false;
textcolor(hcolor);
gotoxy(29, 44);
write('Deactivate Succesfull!');
end;
3: exit;
end;
readkey;
end;
until false;
end;
function pauseMenu: boolean;
var menuop, menuop2: tMenuOptions;
op, op2: integer;
begin
menuop[1]:= 'Resume';
menuop[2]:= 'Quit game';
repeat
clrscr;
textcolor(color);
drawLogo(1, 3);
op:= selectMenu(menuop, 2, 30, 30, color, hcolor, 1);
case op of
1: begin
pauseMenu:= false;
exit;
end;
2: begin
textcolor(color);
gotoxy(25, 39);
write('Are you sure you want to quit?');
menuop2[1]:= 'Yes';
menuop2[2]:= 'No';
op:= horizontalMenu(menuop2, 2, 35, 41, color, hcolor, 2);
if op = 1 then begin
pauseMenu:= true;
exit;
end;
end;
end;
until false;
end;
function youLoseScreen: boolean;
var menuop: tMenuOptions;
rec: tRecordInfo;
isrec: boolean;
i: integer;
begin
clrscr;
textcolor(color);
drawLogo(1, 3);
while keypressed do readkey;
if score >= 5000 then begin
gotoxy(64, 8);
write('# ',cheat[5].password);
end;
if score >= 3750 then begin
gotoxy(64, 10);