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)
......@@ -8,6 +8,8 @@ from items import *
from level_1 import *
import time
from level_2 import *
from leaderboard import *
start_time = ""
global current_room
global current_level
......
import csv, datetime
from email.utils import format_datetime
from datetime import datetime
from csv import reader
def view_leaderboard(filename):
print("________Leaderboard________\n")
with open(str(filename)) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0 #csv reader becomes a 2d list with contents of the Times.csv file
for row in csv_reader:
if line_count == 0:
pass
line_count += 1
else:
time = row[2] #00:00:00 format
minutes = time // 60
seconds = time % 60
time = [round(minutes), round(seconds)]
name = row[1]
if minutes[0] == '0':
minutes = minutes[1]
print(f'{row[1]} escaped in {time[0]} minutes and {time[1]} seconds!')
line_count += 1
def append_leaderboard(seconds_used,filename): #time_used = 20 minutes - time remaining
minutes = seconds_used // 60
seconds = seconds_used % 60
time = [round(minutes), round(seconds)]
print("Congrats, enter your name on the leaderboard!")
name = input("What's your name? :")
print('Well done! '+name)
print(f'You escaped in {time[0]} minutes and {time[1]} seconds')
file = open(str(filename), 'r')
csv_reader = reader(file)
list_of_rows = list(csv_reader)
lastrow = list_of_rows[-1]
old_index = lastrow[0]
if old_index == 'index':
old_index = 0
newindex = int(old_index) + 1
file.close()
file = open(str(filename), 'w')
for row in list_of_rows:
newRecord = str(row[0]) + "," + str(row[1]) + "," + str(row[2]) + "\n"
file.write(newRecord)
print(newRecord)
lastRecord = str(newindex) + "," + str(name) + "," + str(seconds_used) + "\n"
file.write(str(lastRecord)) #Writes data into the file
file.close()
index,name,seconds
\ No newline at end of file