-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
731 lines (686 loc) · 29.1 KB
/
main.py
File metadata and controls
731 lines (686 loc) · 29.1 KB
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
import pygame
import random
import pickle
import os
import math
cell = 20 #velikost samotného čtverce
cell2 = 22 #velikost buněk s okraji
cells = 20 #počet buněk
prostor_score = 100
vyska = cells*cell2
sirka = cells*cell2+prostor_score
pygame.init()
screen = pygame.display.set_mode((sirka, vyska))
clock = pygame.time.Clock()
pressed = pygame.key.get_pressed()
focused = pygame.key.get_focused()
font = pygame.font.Font("ARCADECLASSIC.TTF", 30)
font2 = pygame.font.Font("ARCADECLASSIC.TTF", 20)
font3 = pygame.font.Font("ARCADECLASSIC.TTF", 17)
start_snake = [[1, 1], [1, 1]] #line,place, line,place
start_direction = "right"
start_speed = 10
start_score = 0
start_fruit = 0
fruit_time = 25
running = True
interupt = False
interupt2 = False
huge_loop = True
start_new_walls = False
start_portals = False
pause = False
start_cheese = False
start_board = [
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
[4, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
]
new_walls = start_new_walls
board = start_board
speed = start_speed
snake = start_snake
direction = start_direction
score = start_score
fruit = start_fruit
portals = start_portals
cheese = start_cheese
high = len(board)
width = len(board[0])
high_score = 5
active = []
fruit_list = [2, 3, 4, 4, 4, 5, 5, 5, 6]
#hejjjjjj
#pickle.dump(high_score, open("data", "wb"))
high_score = pickle.load(open("data", "rb"))
#print(high_score)
def generate_board():
#print("board")
board_line = 0 # číslo momentální linie
for boardY in board: # boardY je seznam v seznamu board na pozici board_line
board_col = 0 # číslo sloupce, začínající 0
for boardX in boardY: # boardX je hodnota na pozici board[boardY][]
if boardX == 0:
pygame.draw.rect(screen, (128, 128, 128), pygame.Rect(board_col * cell2, board_line * cell2, cell, cell))
elif boardX == 1:
pygame.draw.rect(screen, (0, 0, 225), pygame.Rect(board_col * cell2, board_line * cell2, cell, cell))
elif boardX == 2:
pygame.draw.rect(screen, (0, 225, 0), pygame.Rect(board_col * cell2, board_line * cell2, cell, cell))
elif boardX == 3:
pygame.draw.rect(screen, (225, 0, 0), pygame.Rect(board_col * cell2, board_line * cell2, cell, cell))
elif boardX == 4:
pygame.draw.rect(screen, (70, 70, 70), pygame.Rect(board_col * cell2, board_line * cell2, cell, cell))
elif boardX == 5:
pygame.draw.rect(screen, (225, 165, 0), pygame.Rect(board_col * cell2, board_line * cell2, cell, cell))
elif boardX == 6:
pygame.draw.rect(screen, (139, 0, 225), pygame.Rect(board_col * cell2, board_line * cell2, cell, cell))
board_col = board_col + 1 # navýšení sloupce o jedna
board_line = board_line + 1 # navýšení linie o jedna
# print("board_end")
pygame.display.flip()
def random_two():
x = random.choice(range(0, width))
y = random.choice(range(0, high))
while board[y][x] != 0:
x = random.choice(range(0, width))
y = random.choice(range(0, high))
return(x, y)
def change(value):
if value == True:
return False
elif value == False:
return True
def input():
#print("zdravíčko")
for event in pygame.event.get(): #reactions on the keys
if event.type == pygame.KEYDOWN:
if event.type == pygame.QUIT:
return("quit")
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
print("jakože hej")
return(pygame.mouse.get_pos())
#------------------------start loop--------------------------
round = 0
while huge_loop == True:
round += 1
#-___________________________
if score > high_score:
high_score = score
print("new high score")
new_high = True
else:
new_high = False
screen.fill((0, 0, 0))
circle = 0
add_body = True
del_body = True
cheese = start_cheese
new_walls = start_new_walls
portals = start_portals
running = True
score = start_score
#board = start_board
speed = start_speed
#snake = start_snake
direction = start_direction
interupt2 = False
fruit = start_fruit
help = False
triple = False
penta = False
double = False
half = False
new_fruits = 5
fruit_circle = 0
fruitY = 0
fruitX = 0
active = []
snake = [[1, 2], [1, 1]]
board = [
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
]
while interupt2 == False:
#print("hej")
screen.fill((0, 0, 0))
if new_high:
text = font.render("Congratulation new high score", False, (225, 225, 225))
screen.blit(text, (20, 70))
elif round > 1:
text = font.render("Game over", False, (225, 225, 225))
screen.blit(text, (20, 70))
text = font.render("Press space to start", False, (225, 225, 225))
screen.blit(text, (20, 100))
text = font2.render("Press 1 for triple mode", False, (225, 225, 225))
screen.blit(text, (20, 132))
text = font2.render("Press 2 for penta mode", False, (225, 225, 225))
screen.blit(text, (20, 164))
text = font2.render("Press 3 for double speed", False, (225, 225, 225))
screen.blit(text, (20, 196))
text = font2.render("Press 4 for half speed", False, (225, 225, 225))
screen.blit(text, (20, 228))
text = font2.render("Press 5 for wall mode", False, (225, 225, 225))
screen.blit(text, (20, 260))
text = font2.render("Press 6 for portals mode", False, (225, 225, 225))
screen.blit(text, (20, 292))
text = font2.render("Press 7 for cheese mode", False, (225, 225, 225))
screen.blit(text, (20, 324))
text = font2.render("Press 0 delete of all modes", False, (225, 225, 225))
screen.blit(text, (20, 356))
text = font2.render("Press H for help", False, (225, 225, 225))
screen.blit(text, (385, 420))
text = font3.render("active modes"+str(active), False, (225, 225, 225))
screen.blit(text, (20, 388))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_KP_ENTER:
running = True
interupt2 = True
elif event.key == pygame.K_KP0 or event.key == pygame.K_0:
active = []
speed = start_speed
board[6][5] = 0
board[15][12] = 0
board[10][10] = 0
board[3][12] = 0
board[18][1] = 0
board[1][18] = 0
portals = False
new_walls = False
cheese = False
elif event.key == pygame.K_KP1 or event.key == pygame.K_1:
board[6][5] = 3
board[15][12] = 3
board[10][10] = 0
board[3][12] = 0
board[18][1] = 0
board[1][18] = 0
portals = False
tripple = True
if 1 not in active:
active.append(1)
if 6 in active:
active.remove(6)
if 2 in active:
active.remove(2)
elif event.key == pygame.K_KP2 or event.key == pygame.K_2:
board[6][5] = 3
board[15][12] = 3
board[10][10] = 3
board[3][12] = 3
board[18][1] = 0
board[1][18] = 0
portals = False
penta = True
if 2 not in active:
active.append(2)
if 1 in active:
active.remove(1)
if 6 in active:
active.remove(6)
elif event.key == pygame.K_KP3 or event.key == pygame.K_3:
if speed != start_speed:
speed = start_speed
speed = start_speed * 2
double = True
if 3 not in active:
active.append(3)
if 4 in active:
active.remove(4)
elif event.key == pygame.K_KP4 or event.key == pygame.K_4:
if speed != start_speed:
speed = start_speed * 0.5
speed = start_speed * 0.5
half = True
if 4 not in active:
active.append(4)
if 3 in active:
active.remove(3)
elif event.key == pygame.K_KP5 or event.key == pygame.K_5:
new_walls = True
board[18][1] = 0
board[1][18] = 0
portals = False
if 5 not in active:
active.append(5)
if 6 in active:
active.remove(6)
elif event.key == pygame.K_KP6 or event.key == pygame.K_6:
portals = True
if 6 not in active:
active.append(6)
if 1 in active:
active.remove(1)
if 2 in active:
active.remove(2)
if 5 in active:
active.remove(5)
elif event.key == pygame.K_KP7 or event.key == pygame.K_7:
cheese = True
if 7 not in active:
active.append(7)
elif event.key == pygame.K_h:
help = True
while help:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_h:
help = False
elif event.key == pygame.K_d:
high_score = 0
elif event.type == pygame.QUIT:
interupt2 = True
huge_loop = False
running = False
help = False
screen.fill((0, 0, 0))
text = font2.render("For quit press H", False, (225, 225, 225))
screen.blit(text, (380, 420))
text = font.render("This game was made by Tom", False, (225, 225, 225))
screen.blit(text, (20, 100))
text = font3.render("Use WASD or arrows for moving", False, (225, 225, 225))
screen.blit(text, (20, 130))
text = font3.render("for start a game press a space", False, (225, 225, 225))
screen.blit(text, (20, 150))
text = font3.render("if you want to choose a press the number and than press a space", False, (225, 225, 225))
screen.blit(text, (20, 170))
text = font3.render("you can choose more that one", False, (225, 225, 225))
screen.blit(text, (20, 190))
text = font3.render("during the game press p for pause and again for resume", False, (225, 225, 225))
screen.blit(text, (20, 210))
text = font3.render("for delete of high score of high score press d", False, (225, 225, 225))
screen.blit(text, (20, 230))
pygame.display.flip()
elif event.type == pygame.QUIT:
interupt2 = True
huge_loop = False
running = False
if portals == True:
board[6][5] = 0
board[15][12] = 0
board[10][10] = 0
board[3][12] = 0
board[7][9] = 0
board[18][1] = 6
board[1][18] = 6
portA = [18, 1]
portB = [1, 18]
if cheese:
snake = [[1, 2]]
# print(snake)
# print(snake[0])
snake_body = [[1, 2]]
old_snake = snake[0]
#____________________
screen.fill((0, 0, 0))
pygame.display.flip()
#-----------------------loop------------------
while running:
#print("start")
circle += 1 #number of running loop
generate_board()
old_direction = direction
for event in pygame.event.get(): #reactions on the keys
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a or event.key == pygame.K_LEFT:
if old_direction != "right":
direction = "left"
#print("left")
elif event.key == pygame.K_d or event.key == pygame.K_RIGHT:
if old_direction != "left":
direction = "right"
#print("right")
elif event.key == pygame.K_w or event.key == pygame.K_UP:
if old_direction != "down":
direction = "up"
#print("up")
elif event.key == pygame.K_s or event.key == pygame.K_DOWN:
if old_direction != "up":
direction = "down"
#print("down")
elif event.key == pygame.K_q:
running = False
elif event.key == pygame.K_p: #pause - loop that end, when p is pressed again
pause = True
while pause:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_p:
pause = False
clock.tick(speed)
if cheese:
#print(snake)
nowLine = snake[-1][0]
nowPlace = snake[-1][1]
else:
#print(snake)
nowLine = snake[-1][0] #coordinates of head
nowPlace = snake[-1][1]
if direction == "left":
snake.append([nowLine, nowPlace-1])
elif direction == "right":
#print("hej")
#print(snake)
snake.append([nowLine, nowPlace+1])
#print(snake)
elif direction == "up":
snake.append([nowLine-1, nowPlace])
elif direction == "down":
snake.append([nowLine+1, nowPlace])
if board[snake[-1][0]][snake[-1][1]] == 3:
score += 1
fruit += 1
x, y = random_two()
board[y][x] = 3
if fruit >= new_fruits and board[fruitY][fruitX] != 5:
x, y = random_two()
board[y][x] = 5
fruitX = x
fruitY = y
fruit_circle = circle
new_fruits = random.choice(fruit_list)
if new_walls == True:
x, y = random_two()
board[y][x] = 4
if cheese:
del_body = False
elif board[snake[-1][0]][snake[-1][1]] == 4:
running = False
elif board[snake[-1][0]][snake[-1][1]] == 1:
running = False
elif board[snake[-1][0]][snake[-1][1]] == 5:
score += 5
fruit = 0
#x, y = random_two()
#board[y][x] = 3
elif board[snake[-1][0]][snake[-1][1]] == 6:
#print("2portA: " + str(portA))
#print("2portB: " + str(portB))
score += 1
if snake[-1] == portA:
snake.append(portB)
elif snake[-1] == portB:
snake.append(portA)
else:
#print("3portA: "+str(portA))
#print("3portB: "+str(portB))
print("hej")
x, y = random_two()
board[y][x] = 6
portA = [y, x]
if cheese == True:
del_body = False
#print("1portA: "+str(portA))
x, y = random_two()
board[y][x] = 6
portB = [y, x]
#print("1portB: " + str(portB))
#print(snake)
board[snake[-3][0]][snake[-3][1]] = 1
#board[snake[-1][0]][snake[-1][1]] = 1
board[snake[0][0]][snake[0][1]] = 0
del snake[0]
#board[snake[0][0]][snake[0][1]] = 0
#del snake[0]
#print(snake)
elif cheese:
pass
else:
board[snake[0][0]][snake[0][1]] = 0
del snake[0]
if cheese:
if len(snake) > 1:
board[snake[-1][0]][snake[-1][1]] = 2
board[snake[0][0]][snake[0][1]] = 0
del snake[0]
add_body = change(add_body)
if add_body == False:
old_snake = snake[-1]
elif add_body == True:
snake_body.append(old_snake)
#board[snake_body[-2][0]][snake_body[-2][1]] = 0
board[snake_body[-1][0]][snake_body[-1][1]] = 1
#old_snake = snake[-1]
if del_body == True:
#print("jaja")
board[snake_body[0][0]][snake_body[0][1]] = 0
del (snake_body[0])
del_body = True
elif del_body == False:
del_body = True
else:
print("hej2")
else:
board[snake[-1][0]][snake[-1][1]] = 2
board[snake[-2][0]][snake[-2][1]] = 1
if board[fruitY][fruitX] == 5:
if circle - fruit_circle > fruit_time:
board[fruitY][fruitX] = 0
fruit = 0
screen.fill((0, 0, 0))
text = font.render("score", False, (225, 225, 225))
screen.blit(text, (20 * cell2 + 4, 10))
text = font.render(str(score), False, (225, 225, 225))
screen.blit(text, (20*cell2 + 4, 40))
text = font.render("high", False, (225, 225, 225))
screen.blit(text, (20 * cell2 + 4, 70))
text = font.render(str(high_score), False, (225, 225, 225))
screen.blit(text, (20 * cell2 + 4, 100))
generate_board()
clock.tick(speed)
#-------------------------------end of loop------------------------------------------
#print(high_score)
pickle.dump(high_score, open("data", "wb"))
#print(pickle.load(open("data", "rb")))
#print("Loops ended")
"""
screen.fill((0, 0, 0))
cheese = start_cheese
new_walls = start_new_walls
portals = start_portals
running = True
score = start_score
#board = start_board
speed = start_speed
#snake = start_snake
direction = start_direction
interupt2 = False
fruit = start_fruit
snake = [[1, 2], [1, 1]]
board = [
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
]
while interupt2 == False:
#print("hej")
screen.fill((0, 0, 0))
text = font.render("Game over", False, (225, 225, 225))
screen.blit(text, (20, 70))
text = font.render("Press space to start", False, (225, 225, 225))
screen.blit(text, (20, 100))
text = font2.render("Press 1 for triple mode", False, (225, 225, 225))
screen.blit(text, (20, 132))
text = font2.render("Press 2 for penta mode", False, (225, 225, 225))
screen.blit(text, (20, 164))
text = font2.render("Press 3 for double speed", False, (225, 225, 225))
screen.blit(text, (20, 196))
text = font2.render("Press 4 for half speed", False, (225, 225, 225))
screen.blit(text, (20, 228))
text = font2.render("Press 5 for wall mode", False, (225, 225, 225))
screen.blit(text, (20, 260))
text = font2.render("Press 6 for portals mode", False, (225, 225, 225))
screen.blit(text, (20, 292))
text = font2.render("Press 7 for cheese mode", False, (225, 225, 225))
screen.blit(text, (20, 324))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_KP_ENTER:
running = True
interupt2 = True
elif event.key == pygame.K_KP1:
board[6][5] = 3
board[15][12] = 3
elif event.key == pygame.K_KP2:
board[6][5] = 3
board[15][12] = 3
board[10][10] = 3
board[3][12] = 3
elif event.key == pygame.K_KP3:
if speed != start_speed:
speed = start_speed
speed = start_speed * 2
elif event.key == pygame.K_KP4:
if speed == start_speed:
speed = start_speed * 0.5
else:
speed = start_speed
elif event.key == pygame.K_KP5:
new_walls = True
elif event.key == pygame.K_KP6:
portals = True
elif event.key == pygame.K_KP7:
cheese = True
elif event.type == pygame.QUIT:
interupt2 = True
huge_loop = False
if portals == True:
board[6][5] = 0
board[15][12] = 0
board[10][10] = 0
board[3][12] = 0
board[7][9] = 0
board[18][1] = 6
board[1][18] = 6
portA = [18, 1]
portB = [1, 18]
if cheese:
snake = [[1, 2]]
# print(snake)
# print(snake[0])
snake_body = [[1, 2]]
old_snake = snake[0]
while interupt == True:
screen.fill((0, 0, 0)) #render text with options
text = font.render("Press space to start", False, (225, 225, 225))
screen.blit(text, (20, 100))
text = font2.render("Press 1 for triple mode", False, (225, 225, 225))
screen.blit(text, (20, 132))
text = font2.render("Press 2 for penta mode", False, (225, 225, 225))
screen.blit(text, (20, 164))
text = font2.render("Press 3 for double speed", False, (225, 225, 225))
screen.blit(text, (20, 196))
text = font2.render("Press 4 for half speed", False, (225, 225, 225))
screen.blit(text, (20, 228))
text = font2.render("Press 5 for wall mode", False, (225, 225, 225))
screen.blit(text, (20, 260))
text = font2.render("Press 6 for portals mode", False, (225, 225, 225))
screen.blit(text, (20, 292))
text = font2.render("Press 7 for cheese mode", False, (225, 225, 225))
screen.blit(text, (20, 324))
pygame.display.flip()
for event in pygame.event.get(): #reaction on the keys
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE or event.key == pygame.K_KP_ENTER:
interupt = True
elif event.key == pygame.K_KP1:
board[6][5] = 3
board[15][12] = 3
elif event.key == pygame.K_KP2:
board[6][5] = 3
board[15][12] = 3
board[10][10] = 3
board[3][12] = 3
elif event.key == pygame.K_KP3:
if speed != start_speed:
speed = start_speed
speed = start_speed * 2
elif event.key == pygame.K_KP4:
if speed == start_speed:
speed = start_speed * 0.5
else:
speed = start_speed
elif event.key == pygame.K_KP5:
new_walls = True
elif event.key == pygame.K_KP6:
portals = True
elif event.key == pygame.K_KP7:
cheese = True
#pass
elif event.type == pygame.QUIT:
interupt = True
huge_loop = False
if portals == True: #in portals mode is everything else zero
board[6][5] = 0
board[15][12] = 0
board[10][10] = 0
board[3][12] = 0
board[7][9] = 0
board[18][1] = 6
board[1][18] = 6
portA = [18, 1]
portB = [1, 18]
if cheese:
snake = [[1, 2]]
#print(snake)
#print(snake[0])
snake_body = [[1, 2]]
old_snake = snake[0]
screen.fill((0, 0, 0))
pygame.display.flip()
"""