Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • c22027697/group-project
1 result
Show changes
Commits on Source (2)
...@@ -205,6 +205,10 @@ def unlock_door(): ...@@ -205,6 +205,10 @@ def unlock_door():
if location_door["locked"]: if location_door["locked"]:
if item_key in inventory: if item_key in inventory:
while True: while True:
totalseconds = (minutes*60)+seconds
append_leaderboard(totalseconds, 'Times.csv')
print("WELL DONE! You've escaped LEVEL 1 in a time of", minutes, "minutes and", seconds,"seconds") print("WELL DONE! You've escaped LEVEL 1 in a time of", minutes, "minutes and", seconds,"seconds")
print("Type CONTINUE to begin the next level") print("Type CONTINUE to begin the next level")
response = input() response = input()
......
...@@ -5,6 +5,11 @@ from csv import reader ...@@ -5,6 +5,11 @@ from csv import reader
def view_leaderboard(filename): def view_leaderboard(filename):
if filename == 'Times.csv':
print('LEVEL 1 \n')
else:
print('LEVEL 2 \n')
print("________Leaderboard________\n") print("________Leaderboard________\n")
with open(str(filename)) as csv_file: with open(str(filename)) as csv_file:
...@@ -15,15 +20,13 @@ def view_leaderboard(filename): ...@@ -15,15 +20,13 @@ def view_leaderboard(filename):
pass pass
line_count += 1 line_count += 1
else: else:
time = row[2] #00:00:00 format time = row[2]
minutes = time // 60 time = int(time)
seconds = time % 60 minutes = round(time // 60)
time = [round(minutes), round(seconds)] seconds = round(time % 60)
time = [str(minutes), str(seconds)]
name = row[1] name = row[1]
if minutes[0] == '0':
minutes = minutes[1]
print(f'{row[1]} escaped in {time[0]} minutes and {time[1]} seconds!') print(f'{row[1]} escaped in {time[0]} minutes and {time[1]} seconds!')
line_count += 1 line_count += 1
...@@ -55,11 +58,19 @@ def append_leaderboard(seconds_used,filename): #time_used = 20 minutes - time r ...@@ -55,11 +58,19 @@ def append_leaderboard(seconds_used,filename): #time_used = 20 minutes - time r
for row in list_of_rows: for row in list_of_rows:
newRecord = str(row[0]) + "," + str(row[1]) + "," + str(row[2]) + "\n" newRecord = str(row[0]) + "," + str(row[1]) + "," + str(row[2]) + "\n"
file.write(newRecord) file.write(newRecord)
print(newRecord)
lastRecord = str(newindex) + "," + str(name) + "," + str(seconds_used) + "\n" lastRecord = str(newindex) + "," + str(name) + "," + str(seconds_used) + "\n"
file.write(str(lastRecord)) #Writes data into the file file.write(str(lastRecord)) #Writes data into the file
file.close() file.close()
print("Input 'Yes' or 'No'")
userinput = input("Would you live to view the leaderboard? :")
userinput = userinput.lower()
if userinput == 'yes':
view_leaderboard(filename)
elif userinput == 'no':
print("Continuing back into the game...")
print('Returning back to the game...')