diff --git a/Color_Game/main.py b/Color_Game/main.py index 4d1e68d9..e7d2e6ec 100644 --- a/Color_Game/main.py +++ b/Color_Game/main.py @@ -1,6 +1,8 @@ import random import tkinter as tk from tkinter import messagebox +import os +import sys colours = ['Red', 'Blue', 'Green', 'Yellow', 'Orange', 'Purple', 'Pink', 'Black', 'White'] score = 0 @@ -15,13 +17,15 @@ def next_colour(): if user_input == correct_color: score += 1 + feedback_label.config(text="✅ Correct!", fg="green") + elif user_input != "": + feedback_label.config(text=f"❌ Wrong! It was: {colours[1]}", fg="red") e.delete(0, tk.END) random.shuffle(colours) label.config(fg=colours[1], text=colours[0]) score_label.config(text=f"Score: {score}") - def countdown(): global timeleft if timeleft > 0: @@ -29,17 +33,13 @@ def countdown(): time_label.config(text=f"Time left: {timeleft}") time_label.after(1000, countdown) else: - # messagebox.showwarning ('Attention', 'Your time is out!!') scoreshow() - def record_highest_score(): highest_score = load_highest_score() if score > highest_score: with open("highest_score.txt", "w") as file: file.write(str(score)) - - def load_highest_score(): try: @@ -52,18 +52,23 @@ def load_highest_score(): except FileNotFoundError: return 0 - def scoreshow(): record_highest_score() - window2 = tk.Tk() + window2 = tk.Toplevel() window2.title("HIGH SCORE") window2.geometry("300x200") - label = tk.Label(window2, text=f"Highest Score: {load_highest_score()}",font=(font, 12)) - + label = tk.Label(window2, text=f"Highest Score: {load_highest_score()}", font=(font, 12)) label.pack() - window2.mainloop() + # ✅ Restart button that restarts everything + def restart(): + window2.destroy() + window.destroy() + os.execl(sys.executable, sys.executable, *sys.argv) + + restart_btn = tk.Button(window2, text="Play Again", command=restart) + restart_btn.pack(pady=10) def start_game(event): global timeleft @@ -71,19 +76,24 @@ def start_game(event): countdown() next_colour() +# --- Main Window --- window = tk.Tk() font = 'Helvetica' window.title("Color Game") -window.iconbitmap("color_game_icon.ico") -window.geometry("375x250") +window.geometry("375x300") window.resizable(False, False) +# ✅ Fix: icon only if exists +icon_path = "color_game_icon.ico" +if os.path.exists(icon_path): + window.iconbitmap(icon_path) + instructions = tk.Label(window, text="Enter the color of the text, not the word!", font=(font, 12)) instructions.pack(pady=10) score_label = tk.Label(window, text="Press Enter to start", font=(font, 12)) score_label.pack() - + time_label = tk.Label(window, text=f"Time left: {timeleft}", font=(font, 12)) time_label.pack() @@ -94,6 +104,10 @@ def start_game(event): window.bind('', start_game) e.pack() +# ✅ Inline feedback (replaces popups) +feedback_label = tk.Label(window, text="", font=(font, 10)) +feedback_label.pack(pady=5) + e.focus_set() -window.mainloop() \ No newline at end of file +window.mainloop()