-
Notifications
You must be signed in to change notification settings - Fork 0
/
snake.py
1701 lines (1392 loc) · 91 KB
/
snake.py
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
# imports all required libaries
import pygame
import sys
import os
from pygame.image import load
from pygame.draw import rect
from pygame.font import Font
from pygame.math import Vector2
from pygame import Rect
from random import randint
from segments import SEGMENTS
from data import DATA
from sqlite3 import Error
import socket
import cProfile
# sets the starting colours for the difficulty buttons
BLACK = (0,0,0)
EASY = (27, 206, 25)
MED = (27, 30, 25)
HARD = (254, 6, 0)
BOUND = (0,0,155)
BOUND_TEXT = "BOUNDARIES OFF" # sets the boundries text to OFF
class SNAKE: # creates a class called 'SNAKE'
def __init__(self):
self.reset()
self.adding_segments = False
def set_img(self):
# set's the different orientations for the head as variables
self.head_up = load('Graphics/head_up.png').convert_alpha()
self.head_down = load('Graphics/head_down.png').convert_alpha()
self.head_right = load('Graphics/head_right.png').convert_alpha()
self.head_left = load('Graphics/head_left.png').convert_alpha()
# set's the different orientations for the head as variables
self.tail_up = load('Graphics/tail_up.png').convert_alpha()
self.tail_down = load('Graphics/tail_down.png').convert_alpha()
self.tail_right = load('Graphics/tail_right.png').convert_alpha()
self.tail_left = load('Graphics/tail_left.png').convert_alpha()
# set's the different orientations for body as variables
self.body_vertical = load('Graphics/body_vertical.png').convert_alpha()
self.body_horizontal = load('Graphics/body_horizontal.png').convert_alpha()
# set's the different corners for the body as variables
self.body_tr = load('Graphics/body_tr.png').convert_alpha()
self.body_tl = load('Graphics/body_tl.png').convert_alpha()
self.body_br = load('Graphics/body_br.png').convert_alpha()
self.body_bl = load('Graphics/body_bl.png').convert_alpha()
# put's the snakes segemnt images into a list
self.segments = [self.head_up, self.head_down, self.head_right, self.head_left,self.tail_up ,self.tail_down,self.tail_right,self.tail_left ,self.body_vertical ,self.body_horizontal ,self.body_tr ,self.body_tl ,self.body_br,self.body_bl]
def colour(self):
if self.celebrate == True: # if celebrate is True
for index,segment in enumerate(self.segments): # for every segment in the segments list enumerate two variables, index and the segment
self.coloured_segment = SEGMENTS.colorize(segment, self.colours) # colour the segment to the new dedicated colour
self.segments[index] = self.coloured_segment # replace the old segment with the coloured one
self.celebrate = False # set celebrate to false
def draw_snake(self):
self.update_head_graphics(),self.update_tail_graphics() # get the direction of the head and tail
for index,block in enumerate(self.body): # for every element in self.body (snake's body) enumerate the elements (segments) in the list with a corresponding index
x_pos = int(block.x * cell_size) # set's the x position of the snake to the integer of the multiplication of the x value of block and the cell_size
y_pos = int(block.y * cell_size) # set's the y position of the snake to the integer of the multiplication of the y value of block and the cell_size
block_rect = Rect(x_pos,y_pos,cell_size,cell_size) # creats a rectangle with the parameters of the x,y values and the dimensions of each cell (block)
if index == 0: screen.blit(self.head,block_rect) # finds the head of the snake and draws the head of the snake
elif index == len(self.body) - 1: screen.blit(self.tail,block_rect) # finds the tail of the snake (the last part/segment) and draws the tail of the snake
else: # for every other body part
previous_block = self.body[index + 1] - block # set's a previous block by adding to the current index in the loop and subtracting the block to get the last block
next_block = self.body[index - 1] - block # set's the previous block by subtracting 1 from the current index and subracting the block
if previous_block.x == next_block.x: screen.blit(self.segments[8],block_rect)# if thev x value of the previous block is equal to the x value next block then if the snake is moving up or down as the x value is the same so display a vertical body part/segment
elif previous_block.y == next_block.y: screen.blit(self.segments[9],block_rect) # if thev y value of the previous block is equal to the y value next block then if the snake is moving left or right as the y value is remaining the same so display a horizontal body part/segment
else: # else if the snake is not moving up,down,left or right it must have turned (as the x and y values are not consistant) so display a corner / turning body part/segment
if previous_block.x == -1 and next_block.y == -1 or previous_block.y == -1 and next_block.x == -1: screen.blit(self.segments[11],block_rect) # if the snake is going right and turns left/up or if the snake is going down and turns right (in proportion to snakes direction (left if looking at screen)), display the corner segment that relates to the turn (also refered to as a top left turn as reference in a vector dimentions graph)
elif previous_block.x == -1 and next_block.y == 1 or previous_block.y == 1 and next_block.x == -1: screen.blit(self.segments[13],block_rect) # if the snake is going right and turns right/down or if the snake is going up and turns left, display the corner segment that relates to the turn (also refered to as a bottom left turn as reference in a vector dimentions graph)
elif previous_block.x == 1 and next_block.y == -1 or previous_block.y == -1 and next_block.x == 1: screen.blit(self.segments[10],block_rect) # if the snake is going in the left direction and turns right/up or if the snake is going down and turns left (in proportion to snakes direction (right if looking at screen)), display the corner segment that relates to the turn (also refered to as a top right turn as reference in a vector dimentions graph)
elif previous_block.x == 1 and next_block.y == 1 or previous_block.y == 1 and next_block.x == 1: screen.blit(self.segments[12],block_rect) # if the snake is going left and turns left/down or if the snake is going up and turns right, displat the corner segment that relates to the turn (also refered to as a bottom right turn as reference in a vector dimentions graph)
pygame.display.update
def update_head_graphics(self): # will have to change and put into draw_snake()
head_relation = self.body[1] - self.body[0] # set the variable head_relation to the second element in the array - the first elemnt
if head_relation == Vector2(1,0):self.head = self.segments[3] # if head realtion is equal to vector(1,0) or moving left in accordance to typical vector dimentions hen set the head to head_left
elif head_relation == Vector2(-1,0):self.head = self.segments[2] # if the head relation is equal to vector(-1,0) or moving right then set the head to head_right
elif head_relation == Vector2(0,1):self.head = self.segments[0] # if the head relation is equal to vector(0,1) or moving up then set the head to head_up
elif head_relation == Vector2(0,-1):self.head = self.segments[1] # if the head relation is equal to vector(0,1) or moving down then set the head to head_down
def update_tail_graphics(self):
tail_relation = self.body[-2] - self.body[-1] # set the variable tail_relation to the second last element in the array - the last elemnt
if tail_relation == Vector2(1,0):self.tail = self.segments[7] # if the tails relation is equal to vector(1,0) or moving left in accordance to vector dimentions then set the tail to tail_left
elif tail_relation == Vector2(-1,0):self.tail = self.segments[6] # if the tails relation is equal to vector(-1,0) or moving right then set the tail to tail_right
elif tail_relation == Vector2(0,1):self.tail = self.segments[4] # if the tails relation is equal to vector(0,1) or moving up then set the tail to tail_up
elif tail_relation == Vector2(0,-1):self.tail = self.segments[5] # if the tails relation is equal to vector(0,1) or moving down then set the tail to tail_down
def move_snake(self):
if self.new_block == True and self.i < self.amount: # if new_block is True and i is less than the amount that needs to be added or subracted
self.adding_segments = True
if self.operator == "+": # if the snake's operator is +
body_copy = self.body[:] # create a copy of the list of snake segments
if main_game.machine == True: main_game.ai_snake.append(main_game.ai_grid[main_game.ai_current.x][main_game.ai_current.y])
body_copy.insert(0,body_copy[0] + self.direction) # insert a segment in the same directionas the other parts
self.body = body_copy[:] # set the snakes body to the edited copy
else: # if the snake's operator is -
try: # if there is enough segments to subtract
if main_game.machine == True: main_game.ai_snake.pop(0)
self.adding_segments = True
body_copy = self.body[:-2] # make a copy of the snakes segments, subtracting the last two segments
body_copy.insert(0,body_copy[0] + self.direction) # add a segment
self.body = body_copy[:] # set the snakes body to the edited copy
except: main_game.game_over() # if there is not enough segments left, end the game
self.i=self.i+1 # add 1 to i
elif self.new_block == True and self.i >= self.amount: # if new_block is true but i is more or equal to the amount
self.adding_segments = False
self.i=0 # set i to 0
self.amount = 0 # set amount to 0
self.new_block = False # set new_block to false
else: # if new_block if false
self.adding_segments = False
body_copy = self.body[:-1] # creates a copy of self.body but subracts the last element in the array
body_copy.insert(0,body_copy[0] + self.direction) # inserts a body segment with the x pos of 0 and the y pos of the position of the snakes head (the very first array in body_copy (body_copy[0])) plus (+) the direction
self.body = body_copy[:] # sets self.body to the copy of the array
def add_block(self, amount):
self.new_block = True # if the snake gets an apple then new_block is set to True
self.amount = self.amount + amount # add the amount to the existing amount that needs to be added or subracted
def reset(self):
self.operator = '+' # set's the snakes operation to +
self.body = [Vector2(5,10),Vector2(4,10),Vector2(3,10)] # Array of snakes body parts
self.direction = Vector2(0,0) # set's the direction of the snake
self.set_img() # declaire the images of the snakes segments
self.new_block = False # set's new_block to False
self.amount = 0 # set's amount to 0
self.i = 0 # sets i to 0
self.celebrate = False # set's celebrate t false
try: main_game.score = 0 # try to reset the score
except: pass
class OPERATIONS:
def __init__(self):
try: self.numbers = NUMBERS()
except: pass
self.plus = ['+',load('Graphics/plus.png').convert_alpha()] # declairs the variable plus as the symbol and image
self.minus = ['-',load('Graphics/minus.png').convert_alpha()] # declairs the variable minus as the symbol and image
self.operators = [(self.plus,(self.randomise())), (self.minus,(self.randomise())), (self.plus,(self.randomise())), (self.minus,(self.randomise()))] # creates a list of all the operators and their locations, symbol and image
self.check_doubles() # check if the locations have doubled up
def draw_operations(self):
for index, operation in enumerate(self.operators): # for every operation in operators
operation_rect = Rect(int(operation[1].x * cell_size),int(operation[1].y * cell_size),cell_size,cell_size) # operators demensions
screen.blit(operation[0][1],operation_rect) # visually inputs the operators on the sceen
def randomise(self):
self.x = randint(0, cell_number - 1) # get the new x position by picking a random number between 0 and 15 (the max width)
self.y = randint(1, cell_number - 1) # get the new y position by picking a random number between 0 and 15 (the max width)
self.pos= Vector2(self.x,self.y) # uses vector2 to creat a 2 demensional vector using the two new positions and set's it as the new position of the operator
try:
for j in range(0,len(self.numbers.numbers)): # for every number between 1 and the amount of operators plus 1
if self.pos.x == self.numbers.numbers[j][1][0] and self.pos.y == self.numbers.numbers[j][1][1]: # if the position of the number equals the position of a operator
print(self.pos, '==', self.numbers.numbers[j][1])
self.randomise() # get a new position
break # break the loop
else: pass
return self.pos # return the position
except: return self.pos # return the position
def check_doubles(self):
for i in range(1,len(self.operators)+1): # for every number from 1 to the number of operators + 1
for j in range(i+1,len(self.operators)+1): # for every number from i+1 to the number of operators + 1
if self.operators[i-1][1] == self.operators[j-1][1]: # if any two operators' positions are equal
pos = self.randomise() # get a new position
self.operators[i-1][1][0] = pos.x # set the new x position of the operator
self.operators[i-1][1][1] = pos.y # set the new y position of the operator
self.check_doubles() #maybe
else: pass# if they don't match pass
class NUMBERS:
def __init__(self):
self.operations = OPERATIONS() # set operations as the class, OPERATIONS()
self.snake = SNAKE() # set snake as the class SNAKE
self.numbers = [] # create an empty list called numbers
for i in range(0,10): self.numbers.append([randint(1,9),self.randomise()]) # for numbers 0 to 10 (amount of numbers wanted), append a random number between 1,9 and a random position to the list
self.check_doubles() # check if the locations double up
def draw_numbers(self):
i=0 # set i to 0
while i < len(self.numbers): # while i is less than the amount of elements in the lsit
number_surface = game_font.render(str(self.numbers[i][0]),True,BLACK) # render the value of the element
number_rect = number_surface.get_rect(center = (int(cell_size * self.numbers[i][1][0])+20,int(cell_size * self.numbers[i][1][1])+20)) # create dimentions of the rectangle that change with the size of the number
screen.blit(number_surface,number_rect) # show the number on the screen
number_rect = Rect(int(self.numbers[i][1][0] * cell_size+5),int(self.numbers[i][1][1] * cell_size+5),cell_size-10,cell_size-10) # create a surrounding rectange
rect(screen,(27, 30, 25),number_rect,3) # draw the surrounding rectangle
i=i+1 # plus 1 to i
def randomise(self):
self.x = randint(0, cell_number - 1) # get the new x position by picking a random number between 0 and 15 (the max width)
self.y = randint(1, cell_number - 1) # get the new y position by picking a random number between 0 and 15 (the max width)
self.pos= Vector2(self.x,self.y) # uses vector2 to creat a 2 demensional vector using the two new positions and set's it as the new position of the number
for j in range(0,len(self.operations.operators)): # for every number between 1 and the amount of operators plus 1
if self.pos.x == self.operations.operators[j][1][0] and self.pos.y == self.operations.operators[j][1][1]: # if the position of the number equals the position of a operator
print(self.pos, '==', self.operations.operators[j][1])
self.randomise() # get a new position
break # break the loop
else: pass
return self.pos # return the position
def check_doubles(self):
for i in range(1,len(self.numbers)+1): # for every number between 1 and the amount of numbers in the list + 1
for j in range(i+1,len(self.numbers)+1): # for every number between i + 1 and the amount of numbers in the list + 1
if self.numbers[i-1][1] == self.numbers[j-1][1]: # if two numbers have the same location
pos = self.randomise() # get a new postion
self.numbers[i-1][1][0] = pos.x # set the new x position of the number
self.numbers[i-1][1][1] = pos.y # set the new y position of the number
self.check_doubles() #check
else: pass
class Spot:
def __init__(self, x, y):
self.x = x
self.y = y
self.f = 0
self.g = 0
self.h = 0
self.neighbours = []
self.obstacle = False
self.camefrom = []
def add_neighbours(self, grid):
if self.x > 0:
self.neighbours.append(grid[self.x - 1][self.y])
if self.y > 0:
self.neighbours.append(grid[self.x][self.y - 1])
if self.x < cell_number - 1:
self.neighbours.append(grid[self.x + 1][self.y])
if self.y < cell_number - 1:
self.neighbours.append(grid[self.x][self.y + 1])
if bound == False:
if self.x == 0:
self.neighbours.append(grid[cell_number-1][self.y])
if self.y == 0:
self.neighbours.append(grid[self.x][cell_number-1])
if self.x == cell_number - 1:
self.neighbours.append(grid[0][self.y])
if self.y == cell_number - 1:
self.neighbours.append(grid[self.x][0])
if self.x == 0 and self.y == cell_number - 1:
self.neighbours.append(grid[cell_number-1][self.y])
self.neighbours.append(grid[self.x][0])
if self.x == cell_number - 1 and self.y == cell_number - 1:
self.neighbours.append(grid[0][self.y])
self.neighbours.append(grid[self.x][0])
if self.x == cell_number - 1 and self.y == 0:
self.neighbours.append(grid[0][self.y])
self.neighbours.append(grid[self.x][cell_number-1])
if self.x == 0 and self.y == 0:
self.neighbours.append(grid[cell_number-1][self.y])
self.neighbours.append(grid[self.x][cell_number-1])
class MAIN:
def __init__(self):
self.snake = SNAKE() # set's snake to the class SNAKE
self.operations = OPERATIONS() # set's operations to class OPERATION
self.numbers = NUMBERS() # set's numbers to class NUMBERS
self.title_font = Font('Font/PoetsenOne-Regular.ttf', 70) # declairs the font used for the titles
self.score = 0 # set's the players score to 0
self.target = randint(2,20) # sets a random target for the player to achieve
if self.target == 3: self.target = randint(2,20)
self.data = DATA()
self.db_updated = False
self.begin = False
self.done = False
self.reset_password = False
self.leaderboard = False
self.username = 'username'
self.password = 'password'
self.confirm_password = 'password'
self.hostname = ''
self.ip_address = ''
self.problem = ''
self.goal_array = []
self.machine = False
self.reset_ai()
# self.c = self.leaderboard_db.conn_db.cursor()
def get_ip(self):
# getting the hostname by socket.gethostname() method
hostname = socket.gethostname()
# getting the IP address using socket.gethostbyname() method
ip_address = socket.gethostbyname(hostname)
# printing the hostname and ip_address
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
return hostname, ip_address
def check_user_ip(self, conn_db):
hostname, ip_address = self.get_ip()
cursor = conn_db.execute('''select * from sqlite_master''')
usernames = [username[0] for username in cursor.execute("SELECT username FROM users")]
passwords = [password[0] for password in cursor.execute("SELECT user_password FROM users")]
users_hostname = [device_name[0] for device_name in cursor.execute("SELECT user_device_name FROM users")]
users_ip = [ip[0] for ip in cursor.execute("SELECT ip FROM users")]
for i in range(0,len(users_ip)): users_ip[i] = users_ip[i].split()
print(users_ip)
new_user = True
for i in range(0,len(users_hostname)):
if users_hostname[i] == hostname:
for j in range(0,len(users_ip[i])):
if users_ip[i][j] == ip_address:
self.username = usernames[i]
self.password = passwords[i]
new_user = False
self.done = True
conn_db.close()
break
if self.done == False:
users_ip[i].append(ip_address)
user_ip_adress = ''
for x in range(0,len(users_ip[i])): user_ip_adress = user_ip_adress + ' ' + str(users_ip[i][x])
conn_db.execute("UPDATE users SET ip = (?) where user_device_name = (?)", (user_ip_adress, hostname))
conn_db.commit()
self.problem = 'ip could not be identified'
self.done = False
new_user = False
break
else: pass
return hostname, ip_address, new_user
def check_user(self, conn_db, new_user):
print('check password')
cursor = conn_db.execute('''select * from sqlite_master''')
usernames = [username[0] for username in cursor.execute("SELECT username FROM users")]
passwords = [password[0] for password in cursor.execute("SELECT user_password FROM users")]
invalid = [',','_', '-', '\'', ']','[','(',')','*','&','^','#', ' ','@','!','$','/','.','|','+','=']
if new_user == True:
for i in range(0,len(usernames)):
if self.username == usernames[i]: return 'username already in use'
else: pass
if self.username == 'username': return "Invalid Username"
elif self.password == 'password': return "Invalid Password"
else:
if len(self.username) <= 3: return "Username entered is too short"
elif len(self.password) <= 3: return "Password entered is too short"
else:
if len(self.username) > 15: return "Username entered is too long"
elif len(self.password) > 15: return "password entered is too long"
else:
for i in range(0,len(self.username)):
if self.username[i] in invalid: return 'invalid character in username'
for i in range(0,len(self.password)):
if self.password[i] in invalid: return 'invalid character in password'
if self.username == self.password: return 'username and password are the same'
else:
conn_db.execute("INSERT INTO users VALUES (?,?,?,?)", (self.username, self.password, self.hostname, self.ip_address))
conn_db.commit()
self.done = True
conn_db.close()
return None
else:
for i in range(0,len(usernames)):
if self.username == usernames[i]:
if self.password == passwords[i]:
self.done = True
conn_db.close()
return None
else: return 'password is incorrect'
return 'username not found'
def reset_password_check(self, conn_db):
print('reset password')
cursor = conn_db.execute('''select * from sqlite_master''')
usernames = [username[0] for username in cursor.execute("SELECT username FROM users")]
passwords = [password[0] for password in cursor.execute("SELECT user_password FROM users")]
invalid = [',','_', '-', '\'', ']','[','(',')','*','&','^','#', ' ','@','!','$','/','.','|','+','=']
if self.username not in usernames: return 'username not found'
elif self.password != self.confirm_password: return 'passwords do not match'
else:
for i in range(0,len(usernames)):
if self.username == usernames[i]:
if self.password == passwords[i]: return 'password already in use'
if self.password == 'password': return "Invalid Password"
else:
if len(self.password) <= 3: return "Password entered is too short"
elif len(self.password) > 15: return "password entered is too long"
else:
for i in range(0,len(self.password)):
if self.password[i] in invalid: return 'invalid character in password'
if self.username == self.password: return 'username and password are the same'
else:
conn_db.execute("UPDATE users SET user_password = (?) where username = (?)", (self.password, self.username))
conn_db.commit()
self.reset_password = False
conn_db.close()
return None
def forgot_screen_display(self):
screen.fill((58, 133, 33))
title_surface = self.title_font.render("RESET PASSWORD",True,(27, 30, 25))
username_surface = game_font.render("USERNAME",True,(27, 30, 25))
new_password_surface = game_font.render("NEW PASSWORD",True,(27, 30, 25))
confirm_surface = game_font.render("CONFIRM PASSWORD",True,(27, 30, 25))
reset_surface = game_font.render("RESET",True,(27, 30, 25))
quit_surface = game_font.render("QUIT",True,(27, 30, 25))
first_x = int(cell_size * cell_number/2)
title_y = int(cell_size * cell_number - (cell_size * cell_number - 70))
username_y = int(cell_size * cell_number - (cell_size * cell_number - 175))
new_passowrd_y = int(cell_size * cell_number - (cell_size * cell_number - 300))
confirm_y = int(cell_size * cell_number - (cell_size * cell_number - 425))
reset_x = int(cell_size * cell_number/3)
quit_x = int(cell_size * cell_number/3 + cell_size * cell_number/3)
third_y = int(cell_size * cell_number - (cell_size * cell_number - 575))
title_rect = title_surface.get_rect(center = (first_x,title_y))
username_rect = username_surface.get_rect(center = (first_x,username_y))
new_password_rect = new_password_surface.get_rect(center = (first_x,new_passowrd_y))
confirm_rect = confirm_surface.get_rect(center = (first_x,confirm_y))
reset_rect = reset_surface.get_rect(center = (reset_x,third_y))
quit_rect = quit_surface.get_rect(center = (quit_x,third_y))
screen.blit(title_surface,title_rect)
screen.blit(username_surface,username_rect)
screen.blit(new_password_surface,new_password_rect)
screen.blit(confirm_surface,confirm_rect)
screen.blit(reset_surface, reset_rect)
screen.blit(quit_surface, quit_rect)
reset_rect = reset_surface.get_rect(size=(100,50), center=(reset_x,third_y))
quit_rect = quit_surface.get_rect(size=(100,50), center=(quit_x,third_y))
# draws the rectangles
rect(screen,(27, 30, 25),reset_rect,3)
rect(screen,(27, 30, 25),quit_rect,3)
return first_x, quit_rect, reset_rect, confirm_rect
def forgot_password_func(self):
problem = None
conn_db = self.data.create_db_connection(self.data.database)
first_x, quit_rect, reset_rect, confirm_rect = self.forgot_screen_display()
username_active = True
new_password_active = False
confirm_active = False
font = Font(None, 40)
font_username = Font(None, 25)
while self.reset_password:
first_x, quit_rect, reset_rect, confirm_rect = self.forgot_screen_display()
if problem is not None: #check if works after getting password wrong on login page
first_x, quit_rect, reset_rect, confirm_rect = self.forgot_screen_display()
problem_surface = font.render(problem, True, (155,0,0))
problem_y = int(cell_size * cell_number - (cell_size * cell_number - 125))
problem_rect = problem_surface.get_rect(center = (first_x,problem_y))
screen.blit(problem_surface,problem_rect)
username_surface = font_username.render(self.username[:15] if len(self.username) <= 15 else self.username[:15] + '...', True, (255,255,255))
username_rect = username_surface.get_rect(topleft = (320,225))
username_rect = username_surface.get_rect(size=(username_rect.width + 10, username_rect.height+20),topleft = (310 - username_rect.width/2,215))
rect(screen, (0,0,0), username_rect)
screen.blit(username_surface, (320 - username_rect.width/2, 225))
password_surface = font.render('*'*len(self.password[:15]), True, (255,255,255))
new_password_rect = password_surface.get_rect(topleft = (320,360))
new_password_rect = password_surface.get_rect(size=(new_password_rect.width + 10, new_password_rect.height+10),topleft = (310 - new_password_rect.width/2,347))
rect(screen, (0,0,0), new_password_rect)
screen.blit(password_surface, (320 - new_password_rect.width/2, 360))
confirm_password_surface = font.render('*'*len(self.confirm_password[:15]), True, (255,255,255))
confirm_password_rect = confirm_password_surface.get_rect(topleft = (320,485))
confirm_password_rect = confirm_password_surface.get_rect(size=(confirm_password_rect.width + 10, confirm_password_rect.height+10),topleft = (310 - confirm_password_rect.width/2,472))
rect(screen, (0,0,0), confirm_password_rect)
screen.blit(confirm_password_surface, (320 - confirm_password_rect.width/2, 485))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if username_rect.collidepoint(pos):
new_password_active = False
confirm_active = False
username_active = True
elif new_password_rect.collidepoint(pos):
username_active = False
confirm_active = False
new_password_active = True
elif confirm_rect.collidepoint(pos):
username_active = False
new_password_active = False
confirm_active = True
elif reset_rect.collidepoint(pos):
problem = self.reset_password_check(conn_db)
elif quit_rect.collidepoint(pos):
pygame.quit()
sys.exit()
else:
confirm_active = True
new_password_active = False
username_active = False
elif event.type == pygame.KEYDOWN and new_password_active == True:
if event.key == pygame.K_BACKSPACE:
self.password=self.password[:-1]
else:
self.password += event.unicode
elif event.type == pygame.KEYDOWN and confirm_active == True:
if event.key == pygame.K_RETURN:
print(self.username, ' -- ', self.password)
problem = self.reset_password_check(conn_db)
elif event.key == pygame.K_BACKSPACE:
self.confirm_password=self.confirm_password[:-1]
else:
self.confirm_password += event.unicode
elif event.type == pygame.KEYDOWN and username_active == True:
if event.key == pygame.K_BACKSPACE:
self.username=self.username[:-1]
else:
self.username += event.unicode
pygame.display.update()
clock.tick(30)
def log_in_display(self):
screen.fill((58, 133, 33))
forgot_font = Font('Font/PoetsenOne-Regular.ttf', 20)
seccond_title_font = Font('Font/PoetsenOne-Regular.ttf', 50)
welcome_surface = seccond_title_font.render("WELCOME TO",True,(27, 30, 25))
title_surface = self.title_font.render("SNAKEY MATH",True,(27, 30, 25))
username_surface = game_font.render("USERNAME",True,(27, 30, 25))
password_surface = game_font.render("PASSWORD",True,(27, 30, 25))
forgot_password_surface = forgot_font.render("FORGOT PASSWORD?",True,(155,0,0))
enter_surface = game_font.render("ENTER",True,(27, 30, 25))
quit_surface = game_font.render("QUIT",True,(27, 30, 25))
first_x = int(cell_size * cell_number/2)
welcome_y = int(cell_size * cell_number - (cell_size * cell_number - 75))
title_y = int(cell_size * cell_number - (cell_size * cell_number - 130))
seccond_x = int(3*(cell_size * cell_number/4))
username_y = int(cell_size * cell_number - (cell_size * cell_number - 275))
passowrd_y = int(cell_size * cell_number - (cell_size * cell_number - 400))
forgot_y = int(cell_size * cell_number - (cell_size * cell_number - 500))
enter_x = int(cell_size * cell_number/3)
quit_x = int(cell_size * cell_number/3 + cell_size * cell_number/3)
third_y = int(cell_size * cell_number - (cell_size * cell_number - 575))
welcome_rect = welcome_surface.get_rect(center = (first_x,welcome_y))
title_rect = title_surface.get_rect(center = (first_x,title_y))
username_rect = title_surface.get_rect(center = (seccond_x,username_y))
password_rect = title_surface.get_rect(center = (seccond_x,passowrd_y))
forgot_rect = forgot_password_surface.get_rect(center = (first_x,forgot_y))
enter_rect = enter_surface.get_rect(center = (enter_x,third_y))
quit_rect = quit_surface.get_rect(center = (quit_x,third_y))
screen.blit(welcome_surface,welcome_rect)
screen.blit(title_surface,title_rect)
screen.blit(username_surface,username_rect)
screen.blit(password_surface,password_rect)
screen.blit(forgot_password_surface,forgot_rect)
screen.blit(enter_surface, enter_rect)
screen.blit(quit_surface, quit_rect)
forgot_rect = forgot_password_surface.get_rect(size=(220,50), center=(first_x,forgot_y))
enter_rect = enter_surface.get_rect(size=(100,50), center=(enter_x,third_y))
quit_rect = quit_surface.get_rect(size=(100,50), center=(quit_x,third_y))
# draws the rectangles
rect(screen,(27, 30, 25),forgot_rect,3)
rect(screen,(27, 30, 25),enter_rect,3)
rect(screen,(27, 30, 25),quit_rect,3)
return first_x, enter_rect, quit_rect, forgot_rect
def log_in_screen(self):
self.problem = 'Please enter a username and password'
conn_db = self.data.create_db_connection(self.data.database)
first_x, enter_rect, quit_rect, forgot_rect = self.log_in_display()
self.hostname, self.ip_address, new_user = self.check_user_ip(conn_db)
first_x, enter_rect, quit_rect, forgot_rect = self.log_in_display()
problem_y = int(cell_size * cell_number - (cell_size * cell_number - 200))
username_active = True
password_active = False
font = Font(None, 40)
font_username = Font(None, 25)
while not self.done:
first_x, enter_rect, quit_rect, forgot_rect = self.log_in_display()
if self.problem != 'Please enter a username and password':
problem_surface = font.render('', True, (155,0,0))
problem_surface = font.render(self.problem, True, (155,0,0))
problem_rect = problem_surface.get_rect(center = (first_x,problem_y))
screen.blit(problem_surface,problem_rect)
else:
problem_surface = font.render(self.problem, True, (27, 30, 25))
problem_rect = problem_surface.get_rect(center = (first_x,problem_y))
screen.blit(problem_surface,problem_rect)
username_surface = font_username.render(self.username[:15] if len(self.username) <= 15 else self.username[:15] + '...', True, (255,255,255))
username_rect = username_surface.get_rect(topleft = (320,295))
username_rect = username_surface.get_rect(size=(username_rect.width + 10, username_rect.height+20),topleft = (310 - username_rect.width/2,285))
rect(screen, (0,0,0), username_rect)
screen.blit(username_surface, (320 - username_rect.width/2, 295))
password_surface = font.render('*'*len(self.password[:15]), True, (255,255,255))
password_rect = password_surface.get_rect(topleft = (320,420))
password_rect = password_surface.get_rect(size=(password_rect.width + 10, password_rect.height+10),topleft = (310 - password_rect.width/2,408))
rect(screen, (0,0,0), password_rect)
screen.blit(password_surface, (320 - password_rect.width/2, 420))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if username_rect.collidepoint(pos):
password_active = False
username_active = True
elif password_rect.collidepoint(pos):
username_active = False
password_active = True
elif enter_rect.collidepoint(pos):
self.problem = self.check_user(conn_db, new_user)
elif quit_rect.collidepoint(pos):
pygame.quit()
sys.exit()
elif forgot_rect.collidepoint(pos):
conn_db.close()
self.done = True
self.reset_password = True
else:
password_active = False
username_active = False
elif event.type == pygame.KEYDOWN and password_active == True:
if event.key == pygame.K_RETURN:
print(self.username, ' -- ', self.password)
self.problem = self.check_user(conn_db, new_user)
elif event.key == pygame.K_BACKSPACE:
self.password=self.password[:-1]
else:
self.password += event.unicode
elif event.type == pygame.KEYDOWN and username_active == True:
if event.key == pygame.K_BACKSPACE:
self.username=self.username[:-1]
else:
self.username += event.unicode
pygame.display.update()
clock.tick(30)
def leaderboard_screen(self):
conn_db = self.data.create_db_connection(self.data.database)
screen.fill((58, 133, 33)) # fills the screen with a green colour
title_surface = self.title_font.render("LEADERBOARD",True,(27, 30, 25)) # renders the title
first_x = int(cell_size * cell_number/2)
title_y = int(cell_size * cell_number - (cell_size * cell_number - 75))
title_rect = title_surface.get_rect(center = (first_x,title_y))
screen.blit(title_surface,title_rect)
place_surface = game_font.render("Placement",True,(27, 30, 25))
usern_surface = game_font.render("Username",True,(27, 30, 25))
scor_surface = game_font.render("Score",True,(27, 30, 25))
place_x = int(cell_size * cell_number/4)
username_x = int(cell_size * cell_number/2)
score_x = int(cell_size * cell_number / 4 *3)
seccond_y = int(cell_size * cell_number - (cell_size * cell_number - 160))
place_rect = place_surface.get_rect(center = (place_x,seccond_y))
usern_rect = usern_surface.get_rect(center = (username_x,seccond_y))
scor_rect = scor_surface.get_rect(center = (score_x,seccond_y))
cursor = conn_db.execute('''select * from sqlite_master''')
usernames = [username[0] for username in cursor.execute("SELECT username FROM high_scores")]
placements = [placement[0] for placement in cursor.execute("SELECT placement FROM high_scores")]
scores = [score[0] for score in cursor.execute("SELECT score FROM high_scores")]
ten_users = []
not_top_ten = True
for i in range(0, len(placements)):
if int(placements[i]) <= 10 and len(ten_users) < 12: ten_users.append([placements[i], usernames[i], scores[i]])
for i in ten_users:
if self.username in i and len(ten_users) > 0: not_top_ten = False
bg_rect = Rect(place_rect.left-9,place_rect.top-3,(place_rect.width+6 + usern_rect.width + 12 + scor_rect.width + 6)*1.33,(scor_rect.height+3) * (12 if not_top_ten == True or len(ten_users) > 10 else 10.5))
rect(screen,(0,155,0),bg_rect)
bg_rect = Rect(place_rect.left-12,place_rect.top-6,(place_rect.width+9 + usern_rect.width + 11 + scor_rect.width + 9)*1.33,(scor_rect.height+3 + (1/3 if not_top_ten == True or len(ten_users) > 10 else 1/1.5)) * (12 if not_top_ten == True or len(ten_users) > 10 else 10.5))
rect(screen,(27, 30, 25),bg_rect, 3)
screen.blit(place_surface,place_rect)
screen.blit(usern_surface,usern_rect)
screen.blit(scor_surface,scor_rect)
height = 170 #150
for i in range(0, len(ten_users)):
height = height + 30
if ten_users[i][1] == self.username: colour = (0,0,0)
else: colour = (27, 30, 25)
placement_surface = game_font.render(str(ten_users[i][0]),True,colour) # renders the title
user_surface = game_font.render(str(ten_users[i][1]),True,colour)
score_surface = game_font.render(str(ten_users[i][2]),True,colour)
temp_y = int(cell_size * cell_number - (cell_size * cell_number - height))
placement_rect = placement_surface.get_rect(center = (place_x,temp_y))
user_rect = user_surface.get_rect(center = (username_x,temp_y))
score_rect = score_surface.get_rect(center = (score_x,temp_y))
screen.blit(placement_surface,placement_rect)
screen.blit(user_surface,user_rect)
screen.blit(score_surface,score_rect)
if i == 0 and not_top_ten == False and len(ten_users) == 0: #issue
colour = (0,0,0)
placement_surface = game_font.render("1",True,colour)
user_surface = game_font.render(str(self.username),True,colour)
score_surface = game_font.render(str(self.score),True,colour)
temp_y = int(cell_size * cell_number - (cell_size * cell_number - height))
placement_rect = placement_surface.get_rect(center = (place_x,temp_y))
user_rect = user_surface.get_rect(center = (username_x,temp_y))
score_rect = score_surface.get_rect(center = (score_x,temp_y))
screen.blit(placement_surface,placement_rect)
screen.blit(user_surface,user_rect)
screen.blit(score_surface,score_rect)
i = 1
i = i + 1 #test
if i < 9:
colour = (27, 30, 25)
for j in range(i, 10): #test
i=i+1
height = height + 30
placement_surface = game_font.render(str(i),True,colour)
temp_y = int(cell_size * cell_number - (cell_size * cell_number - height))
placement_rect = placement_surface.get_rect(center = (place_x,temp_y))
screen.blit(placement_surface,placement_rect)
if not_top_ten == True and len(usernames) > 1:
height = height + 30
colour = (0,0,0)
for i in range(0, len(usernames)):
if self.username == usernames[i]:
temp_score = scores[i]
temp_place = placements[i]
try:
print(temp_score)
except:
temp_score = 0
temp_place = '--'
placement_surface = game_font.render(str(temp_place),True,colour) # renders the title
user_surface = game_font.render(str(self.username),True,colour)
score_surface = game_font.render(str(temp_score),True,colour)
temp_y = int(cell_size * cell_number - (cell_size * cell_number - height))
placement_rect = placement_surface.get_rect(center = (place_x,temp_y))
user_rect = user_surface.get_rect(center = (username_x,temp_y))
score_rect = score_surface.get_rect(center = (score_x,temp_y))
bg_rect = Rect(placement_rect.left-9,placement_rect.top,(placement_rect.width+6 + user_rect.width + 6 + score_rect.width)*2,score_rect.height+3)
rect(screen,(167,209,61),bg_rect)
screen.blit(placement_surface,placement_rect)
screen.blit(user_surface,user_rect)
screen.blit(score_surface,score_rect)
return_surface = game_font.render("RETURN",True,MED)
return_x = int(cell_size * cell_number/2)
third_y = int(cell_size * cell_number - (cell_size * cell_number - 590))
return_rect = return_surface.get_rect(center = (return_x,third_y))
screen.blit(return_surface, return_rect)
return_rect = return_surface.get_rect(size =(100,50), center=(return_x,third_y))
rect(screen,(27, 30, 25),return_rect,3)
def start_screen(self):
conn_db = self.data.create_db_connection(self.data.database)
cursor = conn_db.execute('''select * from sqlite_master''')
usernames = [username[0] for username in cursor.execute("SELECT username FROM high_scores")]
placements = [placement[0] for placement in cursor.execute("SELECT placement FROM high_scores")]
scores = [score[0] for score in cursor.execute("SELECT score FROM high_scores")]
for i in range(0, len(usernames)):
if self.username == usernames[i]:
temp_h_score = scores[i]
temp_place = placements[i]
try:
temp_h_score = temp_h_score
except:
temp_h_score = 0
temp_place = '--'
screen.fill((58, 133, 33)) # fills the screen with a green colour
seccond_title_font = Font('Font/PoetsenOne-Regular.ttf', 50)
welcome_surface = seccond_title_font.render("WELCOME TO",True,(27, 30, 25))
title_surface = self.title_font.render("SNAKEY MATH",True,(27, 30, 25)) # renders the title
# renders the text for each button
leader_surface = game_font.render("LEADERBOARD",True,(155,155,0))
easy_surface = game_font.render("EASY",True,EASY)
med_surface = game_font.render("MED",True,MED)
hard_surface = game_font.render("HARD",True,HARD)
play_surface = game_font.render("PLAY",True,(27, 30, 25))
quit_surface = game_font.render("QUIT",True,(27, 30, 25))
demo_surface = game_font.render("PLAY DEMO",True,(30,60,155))
bound_surface = game_font.render(BOUND_TEXT,True,BOUND)
# set's the position for each button and for the title
first_x = int(cell_size * cell_number/2)
welcome_y = int(cell_size * cell_number - (cell_size * cell_number - 75))
title_y = int(cell_size * cell_number - (cell_size * cell_number - 130))
leader_x = int(cell_size * cell_number/3) - 10
leader_y = int(cell_size * cell_number - (cell_size * cell_number - 215))
easy_x = int(cell_size * cell_number/5)
med_x = int(cell_size * cell_number/2)
hard_x = int((cell_size * cell_number/5)*4)
second_y = int(cell_size * cell_number - (cell_size * cell_number - 300))
play_x = int(cell_size * cell_number/3)
quit_x = int(cell_size * cell_number/3 + cell_size * cell_number/3)
third_y = int(cell_size * cell_number - (cell_size * cell_number - 520))
fourth_y = int(cell_size * cell_number - (cell_size * cell_number - 595))
bound_x = int((cell_size * cell_number/3) + (cell_size * cell_number/3)) + 10
# creates a rectangle for each button and for the title
welcome_rect = welcome_surface.get_rect(center = (first_x,welcome_y))
title_rect = title_surface.get_rect(center = (first_x,title_y))
leader_rect = leader_surface.get_rect(center = (leader_x,leader_y))
easy_rect = play_surface.get_rect(center = (easy_x,second_y))
med_rect = play_surface.get_rect(center = (med_x,second_y))
hard_rect = play_surface.get_rect(center = (hard_x,second_y))
play_rect = play_surface.get_rect(center = (play_x,third_y))
quit_rect = quit_surface.get_rect(center = (quit_x,third_y))
demo_rect = demo_surface.get_rect(center = (med_x,fourth_y))
# checks if boundries are on or off
if bound == False:
bound_rect = quit_surface.get_rect(center = (bound_x-69,leader_y))
else:
bound_rect = quit_surface.get_rect(center = (bound_x-67,leader_y))
# displays both the text using the rectange for positioning
screen.blit(welcome_surface,welcome_rect)
screen.blit(title_surface,title_rect)
screen.blit(leader_surface, leader_rect)
screen.blit(easy_surface, easy_rect)
screen.blit(med_surface, med_rect)
screen.blit(hard_surface, hard_rect)
screen.blit(play_surface, play_rect)
screen.blit(quit_surface, quit_rect)
screen.blit(bound_surface, bound_rect)
screen.blit(demo_surface, demo_rect)
# creates a rectangle to surround the text to create the button
leader_rect = play_surface.get_rect(size =(220,50), center=(leader_x,leader_y))
easy_rect = play_surface.get_rect(size =(100,50), center=(easy_x,second_y))
med_rect = play_surface.get_rect(size =(100,50), center=(med_x,second_y))
hard_rect = play_surface.get_rect(size =(100,50), center=(hard_x,second_y))
play_rect = play_surface.get_rect(size =(100,50), center=(play_x,third_y))
quit_rect = quit_surface.get_rect(size =(100,50), center=(quit_x,third_y))
bound_rect = quit_surface.get_rect(size =(220,50), center=(bound_x,leader_y))
demo_rect = demo_surface.get_rect(size =(150,50), center=(med_x,fourth_y))
# draws the rectangles
rect(screen,(27, 30, 25),leader_rect,3)
rect(screen,(27, 30, 25),easy_rect,3)
rect(screen,(27, 30, 25),med_rect,3)
rect(screen,(27, 30, 25),hard_rect,3)
rect(screen,(27, 30, 25),play_rect,3)
rect(screen,(27, 30, 25),quit_rect,3)
rect(screen,(27, 30, 25),bound_rect,3)
rect(screen,(27, 30, 25),demo_rect,3)
place_surface = game_font.render("Placement",True,(27, 30, 25))
usern_surface = game_font.render("Username",True,(27, 30, 25))
scor_surface = game_font.render("Score",True,(27, 30, 25))
place_x = int(cell_size * cell_number/4)
username_x = int(cell_size * cell_number/2)
score_x = int(cell_size * cell_number / 4 *3)
leaderboard_y = int(cell_size * cell_number - (cell_size * cell_number - 380))
place_rect = place_surface.get_rect(center = (place_x,leaderboard_y))
usern_rect = usern_surface.get_rect(center = (username_x,leaderboard_y))
scor_rect = scor_surface.get_rect(center = (score_x,leaderboard_y))
placement_surface = game_font.render(str(temp_place),True,(0,0,0)) # renders the title
user_surface = game_font.render(str(self.username),True,(0,0,0))
score_surface = game_font.render(str(temp_h_score),True,(0,0,0))
temp_y = int(cell_size * cell_number - (cell_size * cell_number - 430))
placement_rect = placement_surface.get_rect(center = (place_x,temp_y))
user_rect = user_surface.get_rect(center = (username_x,temp_y))
score_rect = score_surface.get_rect(center = (score_x,temp_y))