CDT-1D / end_screen.py
end_screen.py
Raw
from tkinter import *
from initialise import *
from copy import deepcopy

#score breakdown
def final_score_breakdown(stat):
  global total_score
  total_score = stat["score"][0]
  global correct_score
  correct_score = stat["correct"][0] * 100
  global total_time_bonus
  total_time_bonus = total_score - correct_score
  return "Total Score: {} = \nCorrect Answers: {} = {} * 100 \nTotal Time Bonus = {}".format(total_score, correct_score, stat["correct"], total_time_bonus)


def call_end(root, stat):
    # creating a frame (a canvas that is within the screen that stores the widgets)
    frame = Frame(root)
    #frame.eval('tk::PlaceWindow . center')
    frame.tk.call('tk', 'scaling', 2)
    frame.grid()

    
    # creating end screen to show score breakdown stats
    final_score_breakdown(stat)
    variable = 0
    pts = Label(frame, text=f"TOTAL POINTS: {total_score}")
    correct_pts = Label(frame, text=f"POINTS FROM CORRECT ANSWERS: {correct_score}")
    time_bonus= Label(frame, text=f"TOTAL TIME BONUS: {total_time_bonus}")
    health_left= Label(frame, text=f"TOTAL HEALTH LEFT: {stat['hp'][0]}")


    pts.grid(row=0, column=2)
    correct_pts.grid(row=1, column=2)
    time_bonus.grid(row=2, column=2)
    health_left.grid(row=3, column=2)


    # restart option/button
    restart_button = Button(frame, text="Restart Game", command=lambda: change_to_next(frame))
    restart_button.grid(row=4, column=2)

    #change call value of this screen (Prevent repeat call here)
    call_value_dict["end"] = False
    #print(call_value_dict)

#generally same
def change_to_next(frame):
    #destroy current frame
    frame.grid_forget()
    #print("frame destroyed")
    # change call value of next screen (Calls next screen)
    call_value_dict["char"] = True
    # change update value of this screen (updates this)
    update_value_dict["end"] = True
    #print(call_value_dict)


#diff per screen
def update_end(stat):
    #reset progress
    #stat = deepcopy(char_stat_dict)
    starting_char[0] = "Normie"
    #print(stat)
    update_value_dict["end"] = False