-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
1191 lines (1139 loc) · 49.7 KB
/
main.py
File metadata and controls
1191 lines (1139 loc) · 49.7 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 useful packages
from time import * # To use the sleep() procedure to make the program run smoother
from random import * # Use for randomising certain things such as chances
from math import * # Handle damage rounding
import os # Useage for using commands in the terminal
import sys # Exiting the program
# Global Variables
gamemode = "" # The gamemode the player is in
num_modules = 0 # The number of modules in the current station
station = "" # The name of the station that the player is in
curr_module = 1 # The number of the current module that the player is in
last_module = 0 # The number of the last module the player was in
possible_moves = [] # The modules that the player can move to
curr_deck = "" # The letter of the deck the player is in
curr_room = "" # The module description of the player's current module
alive = True # Is the player alive
won = False # Has the player won
hp = 100 # Player health
defence = 10 # Player defence
damage_reduction = 0 # The damage reduction percentage
damage_increase = 50 # The damage increase percentage
power = 100 # The amount of power the space station has
fuel = 100 # The amount of fuel the player has to use their flamethrower
locked = 0 # The module that is locked by the player
queen = 0 # The module that the alien queen is in
vent_shafts = [] # The modules where vent shafts are located in
info_panels = [] # The modules where information panels are located in
workers = [] # The modules where alien workers are located in
# Procedure declarations
# Displays the story of the game to the player
def display_story():
# Clears the console
os.system("clear")
# The story paragraphs
paragraph1 = "A remote probe on the surface of Mars has detected biological signatures of dormant, single-celled, primative life. A sample of the Martian soil is returned to a space station orbiting the Earth for further analysis."
paragraph2 = "The orange-coloured cells are examined and DNA analysis shows remarkable similarities to Dictyostelium discoideum, a species of soil-living amoeba from Earth. Commonly referred to as slime mould, it transitions from a collection of unicellular amoebae into a multicellular organism and then into a fruiting body."
paragraph3 = "Nicknamed Telium due to its colour and cellular structure, the sample is incubated in a lab with conditions similar to Mars' ancient past when it was a warmer, wetter planet."
paragraph4 = "Remarkably, independant Telium cells slowly begin to move and, after a period of several days, join together to form an organism resembling a slug. In the coming days, the creature grows additional arms and begins to look like a large startfish. Intrigued, scientists continue to examine the creature, which appears to be consuming bacteria from inside the incubation chamber and growing in size with each passing day."
paragraph5 = "Telium begins to show signs of advanced movement around the chamber, and its strength increases significantly. Eventually, it becomes strong enough to break out of its chamber and suffocates a scientist. The creature scuttles through the space station to an unknown location."
paragraph6 = "Telium is not seen for several days."
paragraph7 = "Tension between the astonauts escalates when electronics on the station begin to behave erratically, power starts draining and communication at central command with Earth is lost."
paragraph8 = "Clearly this is the work of Telium, the Queen Alien."
paragraph9 = "\"We are on our own. Telium must be found and destroyed,\" the captain orders. \"There is no protocol for this, but we cannot risk further loss of life. We must stick together and work it out.\""
# Printing the paragraphs character by character with an X second delay then wait Y seconds before printing the next paragraph
for char in paragraph1:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph2:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph3:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph4:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph5:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph6:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph7:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph8:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print("\n")
for char in paragraph9:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
# Force the loop to start
option = 0
# Forces player to type an option below or if they don't writes all paragphs back
while option not in ("r", "return"):
os.system('clear')
print(paragraph1)
print('\n')
print(paragraph2)
print('\n')
print(paragraph3)
print('\n')
print(paragraph4)
print('\n')
print(paragraph5)
print('\n')
print(paragraph6)
print('\n')
print(paragraph7)
print('\n')
print(paragraph8)
print('\n')
print(paragraph9)
print('\n\n')
print("-----------------------------------------------------------------")
option = input("(R)eturn to help menu: ")
os.system('clear')
# Shows an error that occured (Dev usage only)
def render_error(custom_code, message, timeout = 5):
# Continue to update the message until the timer has reached -1
while timeout != -1:
# Clear the consle
os.system('clear')
# Show a nice formated error message
print("-----------------------------------------------------------------")
print("Error: {0}".format(custom_code))
print("Message: {0}".format(message))
print("-----------------------------------------------------------------")
print("Stopping game in {0} seconds".format(timeout))
# Decrease timer by 1
timeout -= 1
# Wait 1 second
sleep(1)
# Cleat the console
os.system('clear')
# Stop the python file
sys.exit()
# Display specified information in text files found in "Help_Text"
def handle_help_text_file_rendering(type="", code=""):
# If the type given is not valid, display an error
if type != "query":
# Stop the function and send error info to the renderer
return render_error("TYPENOTFOUND", "Param \"type\" given in help text file rendering does not exist", 5)
# Open the text file to read it using corresponding to the type of info and the info code
text_file = open("Help_Text/{0}_{1}.txt".format(type, code), 'r')
# Clear to console if there is anything being displayed
os.system('clear')
# Read the text file and print it to the console
print(text_file.read())
# Display a clean return to menu option
print("\n")
print("-----------------------------------------------------------------")
# Ask the user to type "r" or "return"
option = input("(R)eturn to help menu: ")
# Force the input to become lower cased
option = option.lower()
# If the correct input was proved, stop the function and show the help menu
if option == "r" or option == "return":
return display_help()
# Stop and re-call the function
else:
return handle_help_text_file_rendering(type, code)
# Prints the game instructions to beat the game
def display_instructions():
# Clear the console
os.system('clear')
# Print the instuctions
print("1. To win you must find and kill the Alien Queen, Telium, by blocking all of it's exits and killing it with your flamethrower")
print("2. You can use the commands M(2) or MOVE(2) to move to a connecting module next to your current module")
print("3. Alien workers are placed randomly around the station and can cause you trouble")
print("4. Ventilation shafts will randomly move around the station")
print("5. You can lock 1 module at a time to block the aliens")
print("6. If you run out of health or the staion runs out of power you die\n")
print("-----------------------------------------------------------------")
# Ask the user for input
option = input("(R)eturn to menu: ")
# Force the input to become lower cased
option = option.lower()
# If the correct input was given, stop the function and show the main menu
if option == "r" or option == "return":
return show_title_screen()
# Stop and re-call the function
else:
return display_instructions()
# Shows the help menu
def display_help():
# Declare a variable to force the while loop to start
option = 0
# Continue to loop in the "option" variable is not in the list below
while option not in ("aq", "wa", "vs", "ip", "lm", "mc", "ss", "ps", "r"):
# Clear the console
os.system('clear')
# Show the help menu
print("-----------------------------------------------------------------")
print("Alien Queen - (AQ)")
print("Worker Aliens - (WA)")
print("Ventilation Shafts - (VS)")
print("Information Panels - (IP)")
print("Locking Modules - (LM)")
print("Movment Controlls - (MC)")
print("Station Stats - (SS)")
print("Player Stats - (PS)")
print("-----------------------------------------------------------------")
print("Return to menu - (R)")
print("-----------------------------------------------------------------\n")
print("Welcome to the help menu. Please type one of the option codes which can be seen around brackets")
# Ask the user for input
option = input("> ")
# Force the input to become lower cased
option = option.lower()
# If the input is "r", stop the function and show the main menu
if option == "r":
return show_title_screen()
# Stop the function and send data to the help text file handler
return handle_help_text_file_rendering("query", option)
# Manage easy mode
def handle_easy_mode():
# Allow global variables to be changed
global gamemode, num_modules, station, damage_reduction, hp, defence, fuel, power
# Change the global variables to match the easy mode settings
gamemode = "Easy"
num_modules = 17
station = "Victoria_Station"
damage_reduction = 50
hp = 150
defence = 20
fuel = 750
power = 150
# Manage normal mode
def handle_normal_mode():
# Allow global variables to be changed
global gamemode, num_modules, station, damage_reduction
# Change the global variables to match the normal mode settings
gamemode = "Normal"
num_modules = 20
station = "Charles_Darwin"
damage_reduction = 0
# Manage hard mode
def handle_hard_mode():
# Allow global variables to be changed
global gamemode, num_modules, station, damage_increase, defence
# Change the global variables to match the hard mode settings
gamemode = "Hard"
num_modules = 30
station = "Iris"
damage_increase = 50
defence = 5
# Manage impossible mode
def handle_impossible_mode():
# Allow global variables to be changed
global gamemode, num_modules, station, damage_increase, hp, defence, fuel, power
# Change the global variables to match the impossible mode settings
gamemode = "Impossible"
num_modules = 50
station = "Olympus"
damage_increase = 100
hp = 50
defence = 0
fuel = 250
power = 50
# Show all gamemodes to play in
def show_gamemodes():
# Declare a variable to force the while loop to start
option = 0
# Continue to loop in the "option" variable is not in the list below
while option not in ("easy", "e", "normal", "n", "hard", "h", "impossible", "i"):
# Clear the console
os.system('clear')
# Show all gamemodes
print("-----------------------------------------------------------------")
print("Easy Mode (E) - Start with 50% more health, less damage taken, more defence, less modules")
print("Normal Mode (N) - All settings are default")
print("Hard Mode (H) - More damage taken, less defence, more modules")
print("Impossible Mode (I) - Start with 50% less health, more damage taken, no defence, more modules")
print("-----------------------------------------------------------------\n")
print("Type the gamemode you want to play in. If you're new, it is recommened you play normal mode")
# Ask the user for input
option = input("> ")
# Force the input to become lower cased
option = option.lower()
# If the option matches the correct gamemode code, change global settings and stop the function
if option == "easy" or option == "e":
handle_easy_mode()
elif option == "normal" or option == 'n':
handle_normal_mode()
elif option == "hard" or option == "h":
handle_hard_mode()
elif option == "impossible" or option == "i":
handle_impossible_mode()
# Or if the code gets confused and the loop is stopped with the input being inncorrect, stop and re-call the function
else:
return show_gamemodes()
return
# Show the main menu
def show_title_screen():
# Declare a variable to force the while loop to start
option = 0
# Continue to loop in the "option" variable is not in the list below
while option not in ("play", "p", "story", "s", "help", "h", "instructions", "i", "quit", "q"):
# Clear the console
os.system("clear")
# Show the menu options
print("-----------------------------------------------------------------")
print("Play (P)\nStory (S) - Recommended\nHelp (H) - Ask a query on a game machanic\nInstructions (I) - How to play\nQuit (Q)")
print("-----------------------------------------------------------------\n")
print("Type the option you would like to select")
# Ask the user for input
option = input("> ")
# Force the input to become lower cased
option = option.lower()
# If the input matches the correct code, stop and start the gamemode display
if option == "play" or option == "p":
return show_gamemodes()
# Or show the story line and then stop and re-call the function
elif option == "story" or option == "s":
display_story()
return show_title_screen()
# Or stop the function and show the help menu
elif option == "help" or option == "h":
return display_help()
# Or stop the function and show the instructions
elif option == "instructions" or option == "i":
return display_instructions()
# Or clear the console and stop the python file
elif option == "quit" or option == "q":
os.system("clear")
sys.exit()
# And in case of a weird error, clear the console and stop the python file
else:
os.system("clear")
sys.exit()
# Get the players current module data
def load_module():
# Allow global variables to be changed
global curr_module, possible_moves, curr_deck, curr_room
# Get the module data as an array
module = get_modules_from(curr_module)
# Change the global variables according to the returned data
possible_moves = module[0]
curr_deck = module[1]
curr_room = module[2]
# Stop and show the module as a neat display
return output_module()
# Get the data from the module's text file
def get_modules_from(module):
# The modules connecting the "module"
moves = []
# The location of the "modue"
deck = ""
# The name of the "module"
room = ""
# If "station" is not correcly named, stop the function and render an error
if (station not in ('Charles_Darwin', 'Victoria_Station', 'Iris', 'Olympus')):
return render_error('STNNOTFOUND', 'The station name was not found and is currenly named as: {0}'.format(station))
# Open the text file of the "module" in the current gamemode station
text_file = open("Stations/" + station + "/module" + str(module) + ".txt", "r")
# Loop and read all 6 lines
for counter in range(0, 6):
# Read the current line
move_read = text_file.readline()
# If "counter" is 4, which means this is line 5
if counter == 4:
# Change the "deck" to the line which is stripped to prevent "\n" being added to the variable
deck = move_read.strip()
# If "counter" is 5, which means this is line 56
elif counter == 5:
# Change the "room" to the line which is stripped to prevent "\n" being added to the variable
room = move_read.strip()
# Then the line is a number to show connecting modules
else:
# Stip and change the line to a number
move_read = int(move_read.strip())
# If "move_read" is not 0, add it to the "moves" array
if move_read != 0:
moves.append(move_read)
# Close the "module" text file
text_file.close()
# Return the cleaned "module" data as an array
return moves, deck, room
# Re-load a module
def reload_module():
# Clear the console
os.system('clear')
# Show the current module
output_module()
# Check if the queen needs to move
move_queen()
# Show the possible moves
output_moves()
# Ask the user for an action to perform
get_action()
# Display the current module as a neat output
def output_module():
global fuel
# Clear the console
os.system('clear')
# Show the current module data as a display
print("-----------------------------------------------------------------\n")
print(curr_deck + " >>> " + curr_room)
print()
print("You are in module", curr_module)
print("Queen is in module:", queen)
print("Workers are in modules:", workers)
print("Vent Shafts are in modules:", vent_shafts)
print("Info Panels are in modules", info_panels)
print("\n-----------------------------------------------------------------\n")
if fuel < 100:
print("[WARNING] Low fuel\n")
# Show the modules the player can move to
def output_moves():
# Print the modules the player can move to on one line neatly
print("\nFrom here you can move to modules: | ", end=' ')
for move in possible_moves:
print(move, ' | ', end=' ')
print()
def display_station_power():
option = 0
while option not in ("return", "r"):
os.system("clear")
print("-----------------------------------------------------------------")
print("Station Power: {0}".format(power))
print("-----------------------------------------------------------------\n\n")
print("Return to station - (R)")
option = input('> ')
adjust_station_power("sub", 1)
return reload_module()
def display_lifeforms():
option = 0
lifeforms = len(workers) + 1
while option not in ("return", "r"):
os.system("clear")
print("-----------------------------------------------------------------")
print("Lifeforms: {0}".format(lifeforms))
print("-----------------------------------------------------------------\n\n")
print("Return to station - (R)")
option = input('> ')
adjust_station_power("sub", 1)
return reload_module()
def adjust_station_power(operation, amount):
global power
if operation == "add":
power += amount
elif operation == "sub":
power -= amount
else:
return render_error('OPINVALID', 'Operation not valid while adjusting station power')
return
def adjust_player_health(operation, amount):
global hp, defence
if operation == "add":
hp += amount
elif operation == "sub":
hp -= amount
if defence > 0:
defence -= 1
else:
return render_error('OPINVALID', 'Operation not valid while adjusting player health')
return
# Ask the user to make an action
def get_action():
# Allow global variable to be changed
global curr_module, last_module, possible_moves, power
# Delare a variable to force the loop to start
valid_action = False
# Continue to loop if "valid_action" does not change to True
while valid_action != True:
# Display what actions the player can do
print("What do you want to do next ?")
print("\n- (M)OVE - Optional syntax include module number moving to || Example: M2 or MOVE2")
print("- (S)CANNER")
# Ask the user for input
action = input("> ")
# Force the input to become upper cased
action = action.upper()
action_copy = action
# Wait 1 second
sleep(1)
# If the input equals an "M" as the first character check for correct inputing format to move the player
if action.find("M") == 0:
# Delare a variable to be used in all indentations
move = ""
# If the input equal "M" or "MOVE"
if action == "M" or action == "MOVE":
# Ask the user for more input
print("Enter the module to move to or go back to the actions || Example: 2 or B or BACK")
move = input("> ")
# Force the input to become lower cased
move = move.lower()
# If the input length equals 2
if len(action) >= 2 and len(action) <= 3:
# Turn the input into an array of all characters
actionArray = list(action)
if len(action) == 2 and action[1].isnumeric():
move = int(actionArray[1])
elif (actionArray[1] + actionArray[2]).isnumeric():
move = int(actionArray[1] + actionArray[2])
# If the input length equals 5 and it starts with "MOVE"
if len(action) >= 5 and len(action) <= 6 and action.startswith("MOVE"):
# Turn the input into an array of all characters
actionArray = list(action)
if len(action) == 5 and actionArray[4].isnumeric():
move = int(actionArray[4])
elif (actionArray[4] + actionArray[5]).isnumeric():
move = int(actionArray[4] + actionArray[5])
# If the input or "move" equals "back" or "b"
if action == "back" or action == "b" or move == "back" or move == "b":
# Stop the function and reload the module
return reload_module()
# If the variable "move" is a string
elif str(move).isnumeric() == False:
# Stop the function and reload the module
return reload_module()
# If "move" is a number and it is in the "possible_moves" array
elif int(move) in possible_moves:
# Allow the loop to end
valid_action = True
# Change the global variables
last_module = curr_module
curr_module = move
power -= 1
# If there is no power left in the station
if power <= 0:
# Set the player to no longer be alive and then stop the function
alive == False
return
# Or if the "move" is not in "possible_moves"
else:
# Wait 1 second
sleep(1)
# Tell the player that the module they want to move to must be connected to the current module
print("\n\nThe module must be connected to the current module.")
# Wait 3 more seconds
sleep(3)
# Stop the function and re-load the module
return reload_module()
# If the input is the lock command
if action.find("L") == 0:
action_copy = list(action_copy)
if len(action_copy) == 1:
new_lock = input("Enter module to lock: ")
if new_lock.isnumeric():
lock(int(new_lock))
elif len(action_copy) >= 2 and len(action_copy) <= 3:
if len(action_copy) == 2 and action_copy[1].isnumeric():
lock(int(action_copy[1]))
elif (action_copy[1] + action_copy[2]).isnumeric():
lock(int(action_copy[1] + action_copy[2]))
elif len(action_copy) == 4:
new_lock = input("Enter module to lock: ")
if new_lock.isnumeric():
lock(int(new_lock))
elif len(action_copy) >= 5 and len(action_copy) <= 6:
if len(action_copy) == 2 and action_copy[4].isnumeric():
lock(int(action_copy[4]))
elif (action_copy[4] + action_copy[5]).isnumeric():
lock(int(action_copy[4] + action_copy[5]))
return reload_module()
# If the input equals an "S" as the first character check for correct inputing format to open the scanner
if action.find("S") == 0:
# Declare a variable to force the while loop to start
command = 0
# Continue to loop in the "command" variable is not in the list below
while command not in ("lifeforms", "li", "power", "p", "back", "b") and alive == True:
# Clear the console
os.system("clear")
# Show scanner commands
print("-----------------------------------------------------------------\n")
print("Scanner is ready\n")
print("Type the command you would like to use\n")
print("- (L)OCK - Use to lock a module to prevent aliens from escaping it")
print("- (P)OWER - View how much power the station has")
print("- (LI)FEFORMS - Shows all lifeforms on the station except you")
print("- (B)ACK - Go back to the action commands")
# Ask the user for input
command = input("> ")
# Force the input to become lower cased
command = command.lower()
# Check if the command is the lifeforms
if command == "li" or command == "lifeforms":
break
# Check if the command is the lock command
if command.startswith('l') or command.startswith('lock'):
command = list(command)
if len(command) == 1:
new_lock = input("Enter module to lock: ")
if new_lock.isnumeric():
lock(int(new_lock))
elif len(command) >= 2 and len(command) <= 3:
if len(command) == 2 and command[1].isnumeric():
lock(int(command[1]))
elif (command[1] + command[2]).isnumeric():
lock(int(command[1] + command[2]))
elif len(command) == 4:
new_lock = input("Enter module to lock: ")
if new_lock.isnumeric():
lock(int(new_lock))
elif len(command) >= 5 and len(command) <= 6:
if len(command) == 2 and command[4].isnumeric():
lock(int(command[4]))
elif (command[4] + command[5]).isnumeric():
lock(int(command[4] + command[5]))
# If the input equals "back" or "b"
if command == "power" or command == "p":
# Stop the function and show the station power
return display_station_power()
elif command == "lifeforms" or command == "li":
# Stop the function and show all lifeforms
return display_lifeforms()
elif command == "back" or command == "b":
# Stop the function and re-load the module
return reload_module()
# Spawn the npcs in random modules
def spawn_npcs():
# Allow global variables to be changed
global num_modules, queen, vent_shafts, info_panels, workers
# Add all modules in an array except for the first module
module_set = []
for counter in range(2, num_modules + 1):
module_set.append(counter)
# Shuffle the modules
shuffle(module_set)
# Place the queen in the first module in the array
i = 0
queen = module_set[i]
# Default params
vent_counter = 3
info_counter = 2
worker_counter = 3
# Check what station the player is in then modify the default params
if station == "Charles_Darwin":
vent_counter = 4
info_counter = 3
worker_counter = 4
elif station == "Iris":
vent_counter = 5
info_counter = 4
worker_counter = 5
elif station == "Olympus":
vent_counter = 10
info_counter = 5
worker_counter = 10
# Place the vents in the correct modules without putting it in a medbay room
for counter in range(vent_counter):
i += 1
room = get_modules_from(module_set[i])[2]
room = room.lower()
while room.endswith('medbay'):
room = get_modules_from(module_set[i])[2]
room = room.lower()
i += 1
if len(module_set) <= i:
continue
vent_shafts.append(module_set[i])
# Place the vents in the correct modules without putting it in a medbay room
for counter in range(info_counter):
i += 1
room = get_modules_from(module_set[i])[2]
room = room.lower()
while room.endswith('medbay'):
room = get_modules_from(module_set[i])[2]
room = room.lower()
i += 1
if len(module_set) <= i:
continue
info_panels.append(module_set[i])
# Place the vents in the correct modules without putting it in a medbay room
for counter in range(worker_counter):
i += 1
room = get_modules_from(module_set[i])[2]
room = room.lower()
while room.endswith('medbay'):
room = get_modules_from(module_set[i])[2]
room = room.lower()
i += 1
if len(module_set) <= i:
continue
workers.append(module_set[i])
# Check if the player is in a module that contains a vent shaft
def check_vent_shafts():
# Allow global variable to be changed
global num_modules, curr_module, last_module, vent_shafts, fuel
# If the player is in a module that contains a vent shaft
if curr_module in vent_shafts:
# Start telling the player they entered a module with a vent shaft
vent_shaft_message = "You walk into the room and you find some bank of fuel cells. You take one and load it into your flamethrower"
for char in vent_shaft_message:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
# Wait 2 seconds
sleep(2)
# Radomly select the number 20, 30, 40 or 50
fuel_gained = randint(2, 5) * 10
# Tell the player their old fuel reading and their new fuel reading
print("Fuel was {0} now reading: {1}".format(fuel, fuel + fuel_gained))
# Add the fuel to the player's fuel
fuel += fuel_gained
# Wait 2 seconds
sleep(2)
# Start the vent shaft door closure text
vent_shaft_doors_shut = "The doors suddenly lock shut. You can't leave via the doors. What is happening to the station? Our only escape is to climb into the ventilation shaft which will take us to a random module on Charles Darwin."
for char in vent_shaft_doors_shut:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
# Wait 2 seconds
sleep(2)
# Tell the player they are moving to a new module
print("We follow the passages and find outselves sliding down.")
last_module = curr_module
# Keep moving the player until they enter a module with no vent shafts
while curr_module in vent_shafts or curr_module == last_module:
curr_module = randint(1, num_modules)
# Clear the console
os.system("clear")
# Stop the function and load the new module
return load_module()
# Ask the player to lock a module
def lock(new_lock):
# Allow global variables to be changed
global num_modules, power, locked, alive, curr_module
# If the number is not a module number
if new_lock < 0 or new_lock > num_modules:
# Tell the player the operation failed
print("Invalid module. Operation failed. Power will still be used")
# If the module is the module already locked
elif new_lock == locked:
# Tell the player the operation failed
print("Module already locked. Operation failed. Power will still be used")
# If the number is the module the queen is in
elif new_lock == queen:
# Tell the player the operation failed
print("Unable to lock module. Operation failed. Power will still be used")
# If the number is the module to the player's current module
elif new_lock == curr_module:
# Tell the player the operation failed
print("Unable to lock module you're in. Operation failed. Power will still be used")
# Or start to lock the module
else:
# Set the "locked" global variable to be the module the player inputted
locked = new_lock
# Tell the player the operation was successfull
print("Aliens cannot get into module {0}. Power will be used. Operation sucessfull".format(locked))
# Randomly generate amount of power to be drained
power_used = 25 + 5 * randint(0, 5)
# Remove power needed to be drained
power -= power_used
# If the power ran out
if power <= 0:
# Kill the player and stop the function
alive == False
return
# Or stop the function
else:
sleep(5)
return
# Reduce the player's defence
def reduce_defence():
# Allow the global variable to be changed
global defence
# If defense can be taken
if defence > 1:
# Reduce defence by 1
defence -= 1
# Calcuate the total damage applied to a player
def calculate_damage(damage):
# If both damage reduction and increase are 0
if damage_reduction == 0 and damage_increase == 0:
# Apply the defence if any
totalDamage = damage - defence
# Reduce the player's defence
reduce_defence()
# If the "totalDamage" is 0 or less
if totalDamage <= 0:
# Stop the function and return 0 to say no damage taken
return 0
# Or stop the function with the "totalDamage"
else:
return totalDamage
# If the damage reduction is applied
elif damage_reduction > 0:
# Calculate the damage reduction
baseDamage = floor((damage / damage_reduction) * 100)
# Apply the defence if any
totalDamage = baseDamage - defence
# Reduce the player's defence
reduce_defence()
# If the "totalDamage" is 0 or less
if totalDamage <= 0:
# Stop the function and return 0 to say no damage taken
return 0
# Or stop the function with the "totalDamage"
else:
return totalDamage
# If the damage increase is applied
elif damage_increase > 0:
# Calculate the damage increase
baseDamage = floor(damage * ((damage_increase / 100) + 1))
# Apply the defence if any
totalDamage = baseDamage - defence
# Reduce the player's defence
reduce_defence()
# On the rare ocation that "totalDamage" is 0 or less
if totalDamage <= 0:
# Stop the function and return 0 to say no damage taken
return 0
# Or stop the function with the "totalDamage"
else:
return totalDamage
# Or if damage redcution or increase is a negative number for some reason
else:
# Stop the function and reder an error
return render_error("DMGCAL", 'Calculation error while handling damage taken')
# Check if the queen is in the same module as the player
def move_queen():
# Allow global variables to be changed
global num_modules, curr_module, last_module, locked, queen, won, vent_shafts, hp, alive
# If the player is in the queen's module
if curr_module == queen:
# Tell the player
print("There it is! The queen alien in this module...")
# Wait 5 seconds
sleep(5)
# Randomly give the queen chances to escape
moves_to_make = randint(1, 3)
# Stops the queen from moving to the last module
can_move_to_last_module = False
# While the queen has chances to escape, run the loop
while moves_to_make > 0:
# Get the connecting modules
escapes = get_modules_from(queen)
# Store the connecting modules correctly
escapes = escapes[0]
# If the current module is in the escapes array
if curr_module in escapes:
# Remove it
escapes.remove(curr_module)
# If the last module the player was in is in the escapes array
if last_module in escapes and can_move_to_last_module == False:
# Remove it
escapes.remove(last_module)
# If a locked module is in the escapes array
if locked in escapes:
# Remove it
escapes.remove(locked)
# If the queen has no modules to escape to
if len(escapes) == 0:
# Tell the player
print("...and the door is locked. It's trapped")
sleep(3)
print("You get out your flamethrower and prepare to kill the queen...")
sleep(5)
# If the player doesn;t have enough fuel
if fuel < 100:
# Tell them
print('...and you don\'t have enough fuel')
sleep(1)
print("She deals great damage to you")
# Randomise damage taken
random_damage = randint(1, 5) * 10
# Get a total damage after player stats
damage_taken = calculate_damage(random_damage)
# If the player is dead
if damage_taken >= hp:
# Set the variable to False
alive = False
# If their not
else:
# Reduce player health
hp -= damage_taken
sleep(1)
# Tell the player they survived
print("You survived the attack with only {0} hp remaining and retreated to a random adjacted module".format(hp))
# Move the queen
escape_modules = get_modules_from(queen)
# Move the player to a random connecting module
curr_module = choice(escape_modules[0])
# Or if it does have an escape route
else:
# If it has 1 move to make
if moves_to_make == 1:
# Let the queen escape
print("...and has escaped.")
# Move the queen to a random module in the escapes array
queen = choice(escapes)
# Decrease the queen's moves to make by 1
moves_to_make -= 1
# Allow it to move to the last module if it placed connecting to it
can_move_to_last_module = True
# If the queen moves into a room with a vent shaft
while queen in vent_shafts:
# If it has more than one move to make
if moves_to_make > 1:
# Let it escape
print("...and has escaped.")
# Tell the player the queen moved into a vent shaft
print("We can hear scuttling in the ventilation shafts.")
# Declare a variable to force the loop to start
valid_move = False
# While the "valid_move" variable is not True, loop
while valid_move != True:
# Set the "valid_move" to be True
valid_move = True
# Randomly move the queen to a module
queen = randint(1, num_modules)
# If the module is a vent shaft
if queen in vent_shafts:
# Set the "valid_move" to be False to continue the loop
valid_move = False
# Force the queen to have no more moves left
moves_to_make = 0
# Check if the player is in an info panel module
def check_info_panels():
# If the player is in an info panel room
if curr_module in info_panels:
# Decair a varibale to force the loop to start
option = 0
# While the user does not type an option below continue to loop
while option not in ("yes", 'y', 'no', 'n'):
# Clear the console
os.system("clear")
# Tell the player they are in an info panel room
entered_info_panel_room = "You enter a room with a strange beeping sound"
for char in entered_info_panel_room:
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print()
sleep(1)
for char in "You found an information panel":
print(char, end='')
sys.stdout.flush()
sleep(0.05)
print()
sleep(2)
# Ask the player if they want to view the panel
option = input("Do you want to open the panel? (Y)es or (N)o: ")
# Force the input to become lower cased
option = option.lower()
# If they want to open the panel
if option == "yes" or option == "y":
# Reduce station power by for using the info panel
adjust_station_power('sub', 5)
# Get the total lifeforms
total_lifeforms = len(workers) + 1
# Copy the workers array
lifeforms_list = workers.copy()
# Add the queen's module to the copied workers array
lifeforms_list.append(queen)
# Get a random lifeform
random_lifeform = choice(lifeforms_list)
# Get the locked module
locked_module = locked
# If there is no locked module
if locked_module == 0:
# Re-declar the vaiable to be "None"
locked_module = "None"
# Decalre a varibale to force the loop to start
option2 = 0