Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Adding typing hints to the code
  • Loading branch information
RaffaeleFiorillo committed Oct 26, 2021
1 parent ab73d0d commit 8cc8bf4
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 24 deletions.
18 changes: 12 additions & 6 deletions Auxiliary_Functionalities.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,14 @@ def decrypt_letter(letter: str, key: int) -> str:


# given a string, returns the decrypted version of it
def decrypt_line(data: str, key):
def decrypt_line(data: str, key) -> str:
data = data if "\n" not in data else data[:-1]
decrypted_data = "".join(reversed([decrypt_letter(char, key) for char in data]))
return decrypted_data


# de crypts a file given his directory
def decrypt_file(directory: str):
def decrypt_file(directory: str) -> None:
with open(directory, "r") as file: # get file content
lines = file.readlines()
if len(lines) == 0: # prevents list index error if file is empty
Expand All @@ -699,7 +699,9 @@ def decrypt_file(directory: str):
file.write(decrypt_line(lines[-1][start_index:], key))


def read_file_content(file_directory, lines_to_read=0):
# reads an encrypted file and returns its decrypted content. Takes the directory of the encrypted file and the number
# of lines that we need to be returned. the output is a list of strings (every string is a different line of the file).
def read_file_content(file_directory: str, lines_to_read: int = 0) -> [str]:
decrypt_file(file_directory)
with open(file_directory, "r") as file:
if lines_to_read == 0:
Expand All @@ -710,13 +712,16 @@ def read_file_content(file_directory, lines_to_read=0):
return file_content


def write_file_content(file_directory, content):
# Takes as parameters the file directory where the data will be written; and the content (to be written). content is
# a string containing all the data to be written in the file.
def write_file_content(file_directory: str, content: str) -> None:
with open(file_directory, "w") as file:
file.writelines(content)
encrypt_file(file_directory)


def encrypt_all_files(directories):
# encrypts all .txt files in a list of directories passed as parameter
def encrypt_all_files(directories: [str]) -> None:
for directory in directories:
print(f"encrypting: {directory}")
try:
Expand All @@ -725,7 +730,8 @@ def encrypt_all_files(directories):
print(f"!!! Error in current directory: {directory} !!!")


def decrypt_all_files(directories):
# decrypts all .txt files in a list of directories passed as parameter
def decrypt_all_files(directories: [str]) -> None:
for directory in directories:
print(f"decrypting: {directory}")
try:
Expand Down
2 changes: 1 addition & 1 deletion eventos.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ def initiate_test(self):
"parameters/levels info/13.txt", "texts/1.txt", "texts/2.txt", "texts/3.txt", "texts/4.txt",
"texts/5.txt", "texts/6.txt", "texts/7.txt", "texts/8.txt", ]

Af.encrypt_all_files(directories)
# Af.encrypt_all_files(directories)

# [print(f'"{directory}",') for directory in directories]
2 changes: 1 addition & 1 deletion parameters/levels info/2.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30 ..YzY zYV
20 TTOpOQpOL
2 changes: 1 addition & 1 deletion parameters/levels info/3.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65 888yY35Y81
43 lllcCgiCle
2 changes: 1 addition & 1 deletion saves/Test/data.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
44 kDkDfedDfeiDeDggDeh
2 9,B3,543,6A9,6,66,47
3 changes: 2 additions & 1 deletion saves/Test/next_level.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
56 p
1 _A
11 K
14 changes: 7 additions & 7 deletions texts/1.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
26 vV
52 dYLe4LOUSQadL.YLUcQLdcQedLj.Q,Lh'XLdh'. LjT'R'9
28 QF3ExOG0xQDL53P7xOGFCxGLx7D4AKKGHEAxQDD35AL53JH
56 RnmUaU PgjdPc,PijVPRYhgYk,cJPY_iPc,PYgUPhgUih
51 .gdK,TTgdTQKcXKcbPdcKU.KbTQ_e,KTWdKMiPGKiZ X7
38 UK8 ZCNCI8TWv8AUPQKNNKD8FGTFPWJ8TWQH8FPC8FGTFPWJ
35 8DQDGS5STN5SRDFFHA5DGS5SNM
9 eE
6 yobzObekigvybtobkxgbyxgzyb5tgsb3unby3utqb5juhuT
56 ncUbPld_PnaiWUmYPldc'PdiPYaV,hhdeb,PnaaUW,iWUge
13 kBAnynti582i1vi78oikr65r9v1ciru7i1vir5ni65n76
28 GOLxF77OL74xKAxKJ3LKx8GxJ74EMFx70LxzQ3txQCDAj
25 H8uNMzAz6uGJiuxHCD8AA81u34G3CJ7uGJD5u3Czu34G3CJ7
25 x4G47IuIJDuIH46681u47IuIDC
12 changes: 6 additions & 6 deletions texts/6.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
45 Ei
53 eQ.VfekEMdR,aEMVYfMWaM,,RMk,dRV'MeV_RfM'gEMVYF
37 SPl70UOFDSFQ7FOJO7UOJPQ7FOJO7ZUFOJO7UVPCg70TTBN
37 OFU7UVPCB7FSB7FSFIU79IUSBk7OP7EOBT7GP7OJBSH7IDBF
19 xA86oxAtoxAx1horxBAxE27iox1Co72oBAtCBow7tBD81C
59 V_kj_nafMS_'lSfaSkjXlkSfX'lS_q_SjmgqSfaSkeg'lX
16 lK
2 ubogvu1U,tcnqU,gjv,hq,nnc,1ntcgp,ugmcv,pwU,gjV
5 wtKadysjhwjuajsnsaysntuajsnsa4yjsnsayztgFadxxfr
50 _ScJcd,POJSaOJSaSVcJLVcaOxJ_,JR_ObJT,J_WOaUJVQOS
55 XfcaOXfTOXfX HORXgfXj_bIOX hOb_OgfThgOWbTgic h
3 bhvuhylqX.hkw.ql.vudwv.qdkw.h2h.uxr2.ql.vprkwd
2 changes: 2 additions & 0 deletions to do list.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ Include type-hints for variables and returned values
During the game rare Letters turn red and in one text they form a cheat-word | Pendent | 9 | 9 |
------------------------------------------------------------------------------------------------------------------
Make cheat-words to unlock hidden functionalities&stuff (like skins,boosts&powers)| Pendent | 9 | 9 |
------------------------------------------------------------------------------------------------------------------
Change some of the "exit" buttons to a more adapt name | Pendent | 2 | 2 |
------------------------------------------------------------------------------------------------------------------

0 comments on commit 8cc8bf4

Please sign in to comment.