-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaygame.py
143 lines (125 loc) · 5.27 KB
/
playgame.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
"""
This class represents the main game PentesterRPG
Removing any line of code, might result in breaking the game functionality
You can remove time.seconds(x) if you wish to increase the game speed
"""
import csv
# import math for future usage
import os
import random
# import re for future usage
# import subprocess # for future usage
import sys
import time
def main():
""" Initiates the game """
start_game()
def start_game():
""" Check if all game conditions are truth and initiates the game """
validate_input()
check_player()
start_map()
def validate_input():
""" Validate if game is executed correctly """
if len(sys.argv) != 2 or sys.argv[1].lower() != (GAME_EXE):
sys.exit(ERROR_01)
else:
print(GAME_INTRO_01)
downloading()
def downloading():
""" Simulate downloading, still upgrading """
loading()
for percentage in range(101):
sleep_duration = random.uniform(0, 0.09)
time.sleep(sleep_duration)
print(f"Downloading game: {percentage}%", end="\r")
# Create a loading message
def loading():
""" Simulate loading, still upgrading """
for loadings in range(len(DOTS) * 20):
sleep_duration = random.uniform(0, 0.07)
time.sleep(sleep_duration)
iterator = loadings % len(DOTS)
print(DOTS[iterator], end = "\r")
if iterator == len(DOTS) -1:
print(" " * 13, end = "\r")
def check_player():
"""" Check if player is registered if not registered it creates a save game for the user """
new_player = input(NEW_MSG).lower().split()[0]
save_game = SAVE_GAME
if not os.path.isfile(save_game):
with open(save_game, "w", newline="", encoding="utf-8"):
print("\nGenerating a save game file:\n")
# loading() # Assuming loading() is a custom function
print("Searching for the username...")
# loading() # Assuming loading() is a custom function
temporary_var = set()
with open(save_game, "r", newline="", encoding="utf-8") as file:
reader = csv.reader(file)
for row in reader:
temporary_var.add(row[0].lower())
if new_player in temporary_var:
print(ERROR_02)
new_player = input(REGISTER_MSG)
break
else:
with open(save_game, "a", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
register_gift = first_pet()
writer.writerow([new_player, register_gift])
print(f"{FIRST_LOGIN}{register_gift}")
break
def first_pet():
""" Adds a random pet to the user, still updating """
first_random_pet = random.choice(["Nyx", "Cynth", "Lurph", "Sandler"])
return first_random_pet
def start_map():
""" Structure of the game map, still updating """
loading()
while True:
game_options = input("player: ").lower()
os.chdir("/workspaces/PentesterRPG/Game_PentesterRPG/Ethereal_Empire_Maps")
if game_options == "menu":
print(MENU)
elif game_options == "view":
os.system("ls -v")
elif game_options == "open door":
print("Inside this room you see something:")
os.system("ls -d */")
open_door = input("\nWhich door would you like to open?\n\nplayer:")
if open_door == "basecamp":
os.chdir("/workspaces/PentesterRPG/Game_PentesterRPG/Ethereal_Empire_Maps/Ethereal_Empire_Basecamp")
if game_options == "menu":
print(MENU)
elif game_options == "view":
os.system("ls -v")
elif game_options == "open door":
print("Inside this room you see something:")
os.system("ls -d */")
elif game_options == "inspect":
print("Your pet starts inspecting the area")
loading()
os.system("ls -v")
elif game_options == "back":
print("You're returning to the previous map")
loading()
elif game_options == "exit":
print("Closing game, please wait...")
time.sleep(5)
sys.exit()
else:
print("\nSorry that door does not exist.\nYou're returning to the previous map")
# PentesterRPG constants
GAME_EXE = "start"
DOTS = ("loading.", "loading..", "loading...", "loading....", "loading.....", "loading......")
ERROR_01 = "To correctly initiate the game, you must type:\ngame start"
ERROR_02 = "\nError:\nThat username is already registered, please choose another one\n"
GAME_INTRO_01 = print("\nStarting PentesterRPG\n")
NEW_MSG = "Please choose a username in order to save your game progress:\n" + ("Name: \r")
REGISTER_MSG = "If that's your username, you can load your game progress.\nIf it's not you can register a different name: ".lower()
SAVE_GAME = "/workspaces/PentesterRPG/Game_PentesterRPG/Kingdom_PentesterRPG_Data/Sys_Config/bin/save_game.csv"
FIRST_LOGIN = "\nWelcome to PentesterRPG\nYou have found a mystical pet: "
NEW_PLAYER_MSG = "\nIf you want to save your game you need to create a new_player"
MENU = "\nSee what's inside the room:\nsee\n\nOpen the door:\nopen door\n\nQuit the game:\nexit\n\n"
if __name__ == "__main__":
main()