-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorGame.py
More file actions
1224 lines (1061 loc) · 35.6 KB
/
Copy pathCalculatorGame.py
File metadata and controls
1224 lines (1061 loc) · 35.6 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
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
#Importing libaries
from inputimeout import inputimeout, TimeoutOccurred
import os
import sys
import time
import random
from colorama import init, Fore, Style
from subprocess import call
import platform
init()
def flush_input():
try:
import msvcrt
while msvcrt.kbhit():
msvcrt.getch()
except ImportError:
import sys, termios #for linux/unix
termios.tcflush(sys.stdin, termios.TCIOFLUSH)
nameCheck = []
oS = platform.system()
#Creating the clearconsole function
if oS == 'Windows':
clearConsole = lambda: os.system('cls')
else:
clearConsole = lambda: os.system('clear')
#prints the highest score
clearConsole()
print(Fore.YELLOW + "UPDATE(2.7):x2 Streak powers!",Fore.BLUE + "││",Fore.YELLOW + "Current version(2.8)")
print()
print(Fore.RED + "Hard maintainability: if someone takes your spot from the leaderboard,")
print("then you will be erased from the leaderboard entirely! ")
print()
time.sleep(0.8)
print(Fore.MAGENTA + "High Scores:")
time.sleep(0.1)
readScore1st = open("1stScore.txt", "r")
readName1st = open("1stName.txt", "r")
readDifficulty1st = open("1stDifficulty.txt", "r")
readDifficultyVari1st = readDifficulty1st.read()
readScoreVari1st = readScore1st.read()
readNameVari1st = readName1st.read()
print(Fore.WHITE + "─────────│─────────────────────────────────────────────────────────────────│")
print(Fore.YELLOW + "Rank no.1" + Fore.WHITE + "│", Fore.YELLOW + readScoreVari1st, "point(s) by", readNameVari1st,"- Difficulty:",readDifficultyVari1st)
print(Fore.WHITE + "─────────│─────────────────────────────────────────────────────────────────│")
time.sleep(0.05)
readScore1st.close()
readName1st.close()
#prints the next highest score
readScore2nd = open("2ndScore.txt", "r")
readName2nd = open("2ndName.txt", "r")
readDifficulty2nd = open("2ndDifficulty.txt", "r")
readScoreVari2nd = readScore2nd.read()
readNameVari2nd = readName2nd.read()
readDifficultyVari2nd = readDifficulty2nd.read()
print(Style.BRIGHT + Fore.RED + "Rank no.2" + Fore.WHITE + "│", Fore.RED + readScoreVari2nd, "point(s) by", readNameVari2nd, "- Difficulty:",readDifficultyVari2nd)
print(Fore.WHITE + Style.NORMAL + "─────────│─────────────────────────────────────────────────────────────────│")
time.sleep(0.05)
readScore2nd.close()
readName2nd.close()
readDifficulty2nd.close()
#prints the next highest score
readScore3rd = open("3rdScore.txt", "r")
readName3rd = open("3rdName.txt", "r")
readDifficulty3rd = open("3rdDifficulty.txt", "r")
readScoreVari3rd = readScore3rd.read()
readNameVari3rd = readName3rd.read()
readDifficultyVari3rd = readDifficulty3rd.read()
print(Fore.CYAN + "Rank no.3" + Fore.WHITE + "│",Fore.CYAN + readScoreVari3rd, "point(s) by", readNameVari3rd,"- Difficulty:",readDifficultyVari3rd)
print(Fore.WHITE + Style.NORMAL + "─────────│─────────────────────────────────────────────────────────────────│")
time.sleep(0.05)
readScore3rd.close()
readName3rd.close()
readDifficulty3rd.close()
#prints the next highest score
readScore4th = open("4thScore.txt", "r")
readName4th = open("4thName.txt", "r")
readDifficulty4th = open("4thDifficulty.txt", "r")
readScoreVari4th = readScore4th.read()
readNameVari4th = readName4th.read()
readDifficultyVari4th = readDifficulty4th.read()
print("Rank no.4" + Fore.WHITE + "│", readScoreVari4th, "point(s) by", readNameVari4th,"- Difficulty:",readDifficultyVari4th)
print(Fore.WHITE + "─────────│─────────────────────────────────────────────────────────────────│")
time.sleep(0.05)
readScore4th.close()
readName4th.close()
readDifficulty4th.close()
#prints the next highest score
readScore5th = open("5thScore.txt", "r")
readName5th = open("5thName.txt", "r")
readDifficulty5th = open("5thDifficulty.txt", "r")
readScoreVari5th = readScore5th.read()
readNameVari5th = readName5th.read()
readDifficultyVari5th = readDifficulty5th.read()
print("Rank no.5│", readScoreVari5th, "point(s) by", readNameVari5th,"- Difficulty:",readDifficultyVari5th)
print(Fore.WHITE + "─────────│─────────────────────────────────────────────────────────────────│")
time.sleep(0.1)
print()
readScore5th.close()
readName5th.close()
readDifficulty5th.close()
#prints the instructions of the game with adequete delays.
import time
print(Fore.GREEN + "This is a game where you have to find the correct operation that caused the first two numbers to turn into the last.")
time.sleep(0.3)
print()
print("Getting an answer correct gives you points but getting one incorrect takes points away.")
time.sleep(0.3)
print()
print("If you don't answer a question in time, you will lose points (affected by difficulty).")
time.sleep(0.3)
print()
print("Score as high as you can in 5 rounds. Also changing the difficulty changes how hard each question is. ")
time.sleep(0.3)
print()
print(Fore.CYAN + "If you answer all the questions correctly in a game, you will gain and lose more points next game (streak multiplier).")
print("And also activate streak powers which helps you in various ways (mostly)")
print()
while True:
try:
flush_input()
which = input(Fore.MAGENTA + "View challenger leaderboard (y/n): ").lower()
if which == "y" or which == "n":
break
else:
which = int("f")
except:
print(Fore.RED + "Invalid")
if which == "y":
clearConsole()
try:
call(["python", "chalLeader.py"])
except FileNotFoundError:
call(["python3", "chalLeader.py"])
turns = "y"
streak = 1
startReady = "p"
while turns == "y":
tries = 6
# creates each operation to be used multiple times.
def getSum(num1, num2):
return(num1 + num2)
def getDifference(num1, num2):
return(num1 - num2)
def getProduct(num1, num2):
return(num1 * num2)
def getQuotient(num1, num2):
return(num1 / num2)
clearConsole()
if startReady == "p":
print(Fore. GREEN + "1 = Easy")
time.sleep(0.2)
print(Fore.YELLOW + Style.DIM + "2 = Medium")
time.sleep(0.2)
print(Fore.RED + Style.NORMAL + "3 = Hard",Fore.GREEN + "")
time.sleep(0.2)
#asks for a difficulty to be selected with checks in place
if startReady == "p":
while True:
try:
flush_input()
difficulty = int(input("Choose a difficultly level: "))
if difficulty > 3 or difficulty < 1:
difficulty = int("f")
break
except ValueError:
print(Fore.RED + "")
print("Invalid, try again", Fore.GREEN + "")
print()
clearConsole()
# determines the reduction and gain of points
points = 500 * streak
reduction = 50 * streak
gain = 75 * streak
#displays the difficulty
print(Fore.MAGENTA + "Streak multiplier:",Fore.CYAN + str(streak))
print()
if streak == 1:
print(Fore.MAGENTA + "This is where you gain and lose points based on the number above.")
print("For example, seeing a 2 will cause your point gain and reduction to double")
print("This number increases every time you press play again but resets back to 1 if you get an answer incorrect.")
print("This only applies to normal mode")
time.sleep(0.2)
elif streak == 10:
print("You have reached maxium streak")
time.sleep(0.2)
print()
if difficulty == 1:
print(Fore.GREEN + "Difficulty 'easy' has been selected;")
time.sleep(0.2)
print(Fore.BLUE + "")
print("Or type 'p' to practice")
time.sleep(0.2)
elif difficulty == 2:
print(Fore.YELLOW + "Difficulty 'medium' has been selected")
time.sleep(0.2)
print(Fore.BLUE + "")
print("Or type 'p' to practice")
time.sleep(0.2)
elif difficulty == 3:
print(Fore.RED + "Difficulty 'hard' has been selected")
print()
time.sleep(1)
print("Type 'c' to play the hardest difficulty (if you dare)")
print("This contains harder points to gain and a short time to answer")
print(Fore.BLUE + "")
time.sleep(0.2)
print("Or type 'p' to practice")
time.sleep(0.2)
else:
print(Fore.RED + "Difficulty 'challenger' has been selected")
time.sleep(0.2)
print(Fore.BLUE + "")
print("Or type 'p' to practice")
time.sleep(0.5)
startingPoints = points
other1 = 0
other2 = 0
correct = 0
incorrect = 0
randStreak = 0
#starts countdown sequence when something is typed
print()
if startReady == "c":
difficulty = 4
flush_input()
startReady = input(Fore.YELLOW + "Press enter to play normally (normal mode) or type in one of the above options: ").lower()
clearConsole()
if startReady == "c" and streak == 1:
difficulty = 4
clearConsole()
print("Get ready challenger")
time.sleep(1.5)
elif startReady == "p":
clearConsole()
print("practice mode enabled")
print()
print("Answer as many questions as you want with no time limit")
time.sleep(1)
elif startReady == "c" and difficulty != 4:
clearConsole()
print(Fore.RED + "Access denied due to your streak being too high")
if streak > 1:
randStreak = random.randint(13, 14) #1, 20
if randStreak > 0 and randStreak < 7:
print(Fore.GREEN + "You found a common streak power!")
print()
randC = random.randint(1,2)
if randC == 1:
print("+ 50 points per each correct answer")
gain += 50
elif randC == 2:
print("+ 15% points per each correct answer")
gain += (gain / 100) * 15
elif randStreak > 6 and randStreak < 10:
print(Fore.BLUE + "You found a rare streak power!")
print()
randR = random.randint(1,2)
if randR == 1:
print("Your streak is increased by one")
streak += 1
elif randR == 2:
print("Timeout length is increased by 3 seconds")
elif randStreak == 10 or randStreak == 11:
print(Fore.MAGENTA + "You found an epic streak power!")
print()
randE = random.randint(1,2)
if randE == 1:
print("Your streak is protected even if you get an answer incorrect")
incorrect = -5
elif randE == 2:
print("+ 500 points per correct answer")
gain += 100
elif randStreak == 12:
print(Fore.YELLOW + "You found a legendary streak power!!")
print()
randL = random.randint(1,2)
if randL == 1:
print("There is no timer for this round!")
time.sleep(0.75)
print("And start with double the amount of points!")
points *= 2
elif randL == 2:
print("All questions in one!")
time.sleep(0.75)
print("And gain a bonus 30% of your points gained")
gain += (gain / 100) * 30
gain *= 5
tries = 2
elif randStreak == 13 or randStreak == 14:
print(Fore.RED + "Uh oh, you found a corrupt streak power")
print()
randC = random.randint(1,2)
if randC == 1:
print("Quick! Your max time per quesion is halved!")
elif randC == 2:
setback = random.randint(1,streak - 1)
print("Setback your streak has been reduced by:",setback)
streak -= setback
else:
print(Fore.RED + "No streak power found for this round")
time.sleep(2.5)
print()
else:
print(Fore.CYAN + "Gain a streak above 1 to have a chance to get a streak power")
print()
time.sleep(2.5)
print(Fore.YELLOW + "3")
print()
time.sleep(0.4)
print("2")
print()
time.sleep(0.4)
print("1")
print()
time.sleep(0.4)
print("Go!")
time.sleep(0.7)
if startReady == "p":
tries = 0
points = 0
clearConsole()
try:
call(["python", "practice.py"])
except FileNotFoundError:
call(["python3", "practice.py"])
# determines number range based on difficultly
while tries > 1:
operationFinal = random.randint(0, 3)
if difficulty == 1:
num1 = random.randint(25,100)
num2 = random.randint(1,25)
timer = 11
elif difficulty == 2:
num1 = random.randint(25, 150)
num2 = random.randint(-25, 25)
timer = 8.5
elif difficulty == 3:
num1 = random.randint(-50, 150)
num2 = random.randint(-100, -50)
timer = 6
else:
num1 = random.randint(-50, 150)
num2 = random.randint(-100, -50)
timer = 4
if randStreak > 6 and randStreak < 10 and randR == 2:
timer += 3
randStreak = 0
elif randStreak == 13 or randStreak == 14 and randC == 1:
timer /= 2
randStreak = 0
# checks for / by 0 error and changes values of nums if this is true
if num1 == 0 or num2 == 0:
while num1 == 0 or num2 == 0:
operationFinal = random.randint(0, 3)
if difficulty == 1:
num1 = random.randint(25,100)
num2 = random.randint(1,25)
elif difficulty == 2:
num1 = random.randint(25, 150)
num2 = random.randint(-25, 25)
elif difficulty == 3:
num1 = random.randint(-50, 150)
num2 = random.randint(-100, -50)
else:
num1 = random.randint(-50, 150)
num2 = random.randint(-100, -50)
# creates an answer based on what random operation has been picked
if operationFinal == 0:
corAns = "addition"
answer = getSum(num1, num2)
elif operationFinal == 1:
corAns = "subtraction"
answer = getDifference(num1, num2)
elif operationFinal == 2:
corAns = "multiplication"
answer = getProduct(num1, num2)
elif operationFinal == 3:
corAns = "division"
answer = getQuotient(num1, num2)
answer = round(answer)
#outputs all of the nessesery info to the user and also decreases the remaining rounds
tries -= 1
print(Fore.YELLOW)
clearConsole()
print(tries,"question(s) remaining",Fore.GREEN + " Streak:",streak)
print()
print("Your current amount of points:",points)
print(Fore.CYAN + "------------------------------------------------------------------")
print(Fore.YELLOW + "The numbers",num1, "and", num2, "turn into the number", answer)
print()
print(Fore.CYAN + "1 = addition")
print("2 = subtraction")
print("3 = multiplication")
print("4 = division (to nearest integer)")
#asks the user to guess which operation has happened (error handling in place)
while True:
try:
print()
flush_input()
if randStreak == 12:
choice = int(input(Fore.MAGENTA + "What operation has happened here: "))
else:
choice = int(inputimeout(prompt = Fore.MAGENTA + "What operation has happened here: ", timeout = timer))
if choice > 4 or choice < 1:
choice = int("f")
break
except ValueError:
print(Fore.RED + "Invalid")
time.sleep(0.5)
choice = 7
break
except TimeoutOccurred:
choice = 6
print()
print("timed out")
time.sleep(0.5)
break
#checks whether the user is correct
if choice == 1:
choice = choice - 1
if choice == operationFinal:
clearConsole()
print(Fore.GREEN + " Correct!")
correct += 1
print()
time.sleep(0.2)
print(" +",gain,"points")
time.sleep(1.25)
points = points + gain
else:
clearConsole()
print(Fore.RED + " Incorrect")
incorrect += 1
print()
time.sleep(0.2)
print(" -", reduction,"points")
time.sleep(0.8)
print()
print(Fore.GREEN + "Correct answer:", corAns)
time.sleep(1.7)
points = points - reduction
elif choice == 2:
choice = choice - 1
if choice == operationFinal:
clearConsole()
print(Fore.GREEN + " Correct!")
correct += 1
print()
time.sleep(0.2)
print(" +",gain,"points")
time.sleep(1.25)
points = points + gain
else:
clearConsole()
print(Fore.RED + " Incorrect")
incorrect += 1
print()
time.sleep(0.2)
print(" -", reduction,"points")
time.sleep(0.8)
print()
print(Fore.GREEN + "Correct answer:", corAns)
time.sleep(1.7)
points = points - reduction
elif choice == 3:
choice = choice - 1
if choice == operationFinal:
clearConsole()
print(Fore.GREEN +" Correct!")
correct += 1
print()
time.sleep(0.2)
print(" +",gain,"points")
time.sleep(1.25)
points = points + gain
else:
clearConsole()
print(Fore.RED + " Incorrect")
incorrect += 1
print()
time.sleep(0.2)
print(" -", reduction,"points")
time.sleep(0.8)
print()
print(Fore.GREEN + "Correct answer:", corAns)
time.sleep(1.7)
points = points - reduction
elif choice == 4:
choice = choice - 1
if choice == operationFinal:
clearConsole()
print(Fore.GREEN + " Correct!")
correct += 1
print()
time.sleep(0.2)
print(" +",gain,"points")
time.sleep(1.25)
points = points + gain
else:
clearConsole()
print(Fore.RED + " Incorrect")
incorrect += 1
print()
time.sleep(0.2)
print(" -", reduction,"points")
time.sleep(0.8)
print()
print(Fore.GREEN + "Correct answer:", corAns)
time.sleep(1.7)
points = points - reduction
elif choice == 6:
clearConsole()
print(Fore.RED + " Timed out!")
print()
time.sleep(0.2)
print(" - 10 points")
time.sleep(0.8)
print()
print(Fore.GREEN + "Correct answer:", corAns)
time.sleep(1.7)
points = points - (10 * streak)
other1 += 1
elif choice == 7:
clearConsole()
print(Fore.RED + "Invalid")
print()
time.sleep(0.2)
print(" - 5 points")
time.sleep(1.25)
points = points - (5 * streak)
other2 +=1
#displays the final amount of points and checks if the user is on hard difficlulty for the leaderboard.
clearConsole()
print(Fore.YELLOW + "You earned",points,"Points! Well done")
print()
while True:
try:
flush_input()
viewPoints = input(Fore.MAGENTA + "View how you earned these points (y/n): ").lower()
if viewPoints == "y" or viewPoints == "n":
break
else:
viewPoints = int("f")
except:
print(Fore.RED + "Invalid")
if viewPoints == "y" and startReady != "p":
clearConsole()
print(Fore.YELLOW + "Started with:",startingPoints)
print()
time.sleep(0.1)
print(Fore.RED + "But lost",incorrect*reduction,"points to incorrect answers" )
print()
time.sleep(0.1)
print("And also lost",(other1*10)+(other2*5),"points to other sources")
time.sleep(0.1)
print()
print(Fore.GREEN + "But gained",correct*gain,"points")
time.sleep(0.1)
print()
print(Fore.YELLOW + "And so earned a total of",points,"points")
flush_input()
enter = input("Press enter to continue: ")
clearConsole()
elif viewPoints == "y" and startReady == "p":
print()
print(Fore.RED + "To view points, play a game in 'normal' mode by pressing play again")
time.sleep(4)
clearConsole()
clearConsole()
incorrect = incorrect + other1 + other2
#opens all the text files storing the high score details and assigns the content of each to a different variable
scoreFile5th = open("5thScore.txt", "r")
potNewScore5th = float(scoreFile5th.readline())
scoreFile4th = open("4thScore.txt", "r")
potNewScore4th = float(scoreFile4th.readline())
scoreFile3rd = open("3rdScore.txt", "r")
potNewScore3rd = float(scoreFile3rd.readline())
scoreFile2nd = open("2ndScore.txt", "r")
potNewScore2nd = float(scoreFile2nd.readline())
scoreFile1st = open("1stScore.txt", "r")
potNewScore1st = float(scoreFile1st.readline())
scoreFileChallenger1st = open("challengerScore1st.txt", "r")
potNewScoreChallenger1st = float(scoreFileChallenger1st.readline())
scoreFileChallenger2nd = open("challengerScore2nd.txt", "r")
potNewScoreChallenger2nd = float(scoreFileChallenger2nd.readline())
scoreFileChallenger3rd = open("challengerScore3rd.txt", "r")
potNewScoreChallenger3rd = float(scoreFileChallenger3rd.readline())
scoreFileChallenger4th = open("challengerScore4th.txt", "r")
potNewScoreChallenger4th = float(scoreFileChallenger4th.readline())
scoreFileChallenger5th = open("challengerScore5th.txt", "r")
potNewScoreChallenger5th = float(scoreFileChallenger5th.readline())
scoreFile5th.close()
scoreFile4th.close()
scoreFile3rd.close()
scoreFile2nd.close()
scoreFile1st.close()
scoreFileChallenger1st.close()
scoreFileChallenger2nd.close()
scoreFileChallenger3rd.close()
scoreFileChallenger4th.close()
scoreFileChallenger5th.close()
if difficulty == 1:
difficulty = "easy"
elif difficulty == 2:
difficulty = "medium"
elif difficulty == 3:
difficulty = "hard"
else:
difficulty = "challenger"
#checks if the amount of points is high enough for each rank on the highscore leaderboard
#also if the above is true, then asks the user to enter their name (error handling in place)
#it is then written to each file, overriding what there was there before.
if difficulty == "challenger":
if points > potNewScoreChallenger5th:
if points > potNewScoreChallenger4th:
if points > potNewScoreChallenger3rd:
if points > potNewScoreChallenger2nd:
if points > potNewScoreChallenger1st:
points = str(points)
f = open("ChallengerScore1st.txt", "w")
f.write(points)
x = open("ChallengerName1st.txt", "w")
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the CHALLENGER leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
x.close()
f.close()
else:
points = str(points)
f = open("ChallengerScore2nd.txt", "w")
f.write(points)
x = open("ChallengerName2nd.txt", "w")
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the CHALLENGER leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
x.close()
f.close()
else:
points = str(points)
f = open("ChallengerScore3rd.txt", "w")
f.write(points)
x = open("ChallengerName3rd.txt", "w")
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the CHALLENGER leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
x.close()
f.close()
else:
points = str(points)
f = open("ChallengerScore4th.txt", "w")
f.write(points)
x = open("ChallengerName4th.txt", "w")
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the CHALLENGER leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
x.close()
f.close()
else:
points = str(points)
f = open("ChallengerScore5th.txt", "w")
f.write(points)
x = open("ChallengerName5th.txt", "w")
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the CHALLENGER leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
x.close()
f.close()
elif points > potNewScore5th:
if points > potNewScore4th:
if points > potNewScore3rd:
if points > potNewScore2nd:
if points > potNewScore1st:
points = str(points)
f = open("1stScore.txt", "w")
f.write(points)
x = open("1stName.txt", "w")
y = open("1stDifficulty.txt","w")
y.write(difficulty)
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
f.close()
x.close()
y.close()
else:
points = str(points)
f = open("2ndScore.txt", "w")
f.write(points)
x = open("2ndName.txt", "w")
y = open("2ndDifficulty.txt","w")
y.write(difficulty)
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
f.close()
x.close()
y.close()
else:
points = str(points)
f = open("3rdScore.txt", "w")
f.write(points)
x = open("3rdName.txt", "w")
y = open("3rdDifficulty.txt","w")
y.write(difficulty)
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
f.close()
x.close()
y.close()
else:
points = str(points)
f = open("4thScore.txt", "w")
f.write(points)
x = open("4thName.txt", "w")
y = open("4thDifficulty.txt","w")
y.write(difficulty)
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
f.close()
x.close()
y.close()
else:
points = str(points)
f = open("5thScore.txt", "w")
f.write(points)
x = open("5thName.txt", "w")
y = open("5thDifficulty.txt","w")
y.write(difficulty)
while True:
try:
flush_input()
newName = input(Fore.MAGENTA + "Enter your name for the leaderboard (must be < 11 char): ")
for letters in newName:
nameCheck.append(letters)
if len(nameCheck) >= 11:
newName = int("f")
x.write(newName)
break
except:
print(Fore.RED + "Invalid try again")
nameCheck.clear()
f.close()
x.close()
y.close()
while True:
try:
flush_input()
turns = input(Fore.YELLOW + "Go again (y/n): ").lower()
if turns == "y" or turns == "n":
break
else:
turns = int("f")
except ValueError:
print(Fore.RED + "Invalid try again")
if turns == "y":
print()
if incorrect < 1 and startReady != "p":
streak += 1
incorrect = 0
if incorrect > 0 or startReady == "p":
streak = 1
if streak > 10:
print(Fore.MAGENTA + "Congrats on getting here! Your streak will now reset")
streak = 1
time.sleep(3)
clearConsole()
print(Fore.BLUE + "NOTE; if you just played in normal mode, you can no longer change your difficulty unless you choose practice mode")
print()