From 503d9012350195ee4a0f5eed259aa3e0f5a3f3e6 Mon Sep 17 00:00:00 2001 From: Prayas Dey Date: Fri, 14 Aug 2026 23:49:32 +0530 Subject: [PATCH 1/2] fix(Color_Game): resolve missing icon crash, path resolution, scoring logic, and add game restart --- Color_Game/main.py | 196 ++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/Color_Game/main.py b/Color_Game/main.py index 4d1e68d9..65dce8e0 100644 --- a/Color_Game/main.py +++ b/Color_Game/main.py @@ -1,99 +1,99 @@ -import random -import tkinter as tk -from tkinter import messagebox - -colours = ['Red', 'Blue', 'Green', 'Yellow', 'Orange', 'Purple', 'Pink', 'Black', 'White'] -score = 0 -timeleft = 30 - -def next_colour(): - global score, timeleft - - if timeleft > 0: - user_input = e.get().lower() - correct_color = colours[1].lower() - - if user_input == correct_color: - score += 1 - - 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: - timeleft -= 1 - 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: - with open("highest_score.txt", "r") as file: - data = file.read() - if data: - return int(data) - else: - return 0 - except FileNotFoundError: - return 0 - - -def scoreshow(): - record_highest_score() - window2 = tk.Tk() - window2.title("HIGH SCORE") - window2.geometry("300x200") - - label = tk.Label(window2, text=f"Highest Score: {load_highest_score()}",font=(font, 12)) - - label.pack() - - window2.mainloop() - -def start_game(event): - global timeleft - if timeleft == 30: - countdown() - next_colour() - -window = tk.Tk() -font = 'Helvetica' -window.title("Color Game") -window.iconbitmap("color_game_icon.ico") -window.geometry("375x250") -window.resizable(False, False) - -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() - -label = tk.Label(window, font=(font, 60)) -label.pack(pady=20) - -e = tk.Entry(window) -window.bind('', start_game) -e.pack() - -e.focus_set() - +import random +import tkinter as tk +from tkinter import messagebox + +colours = ['Red', 'Blue', 'Green', 'Yellow', 'Orange', 'Purple', 'Pink', 'Black', 'White'] +score = 0 +timeleft = 30 + +def next_colour(): + global score, timeleft + + if timeleft > 0: + user_input = e.get().lower() + correct_color = colours[1].lower() + + if user_input == correct_color: + score += 1 + + 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: + timeleft -= 1 + 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: + with open("highest_score.txt", "r") as file: + data = file.read() + if data: + return int(data) + else: + return 0 + except FileNotFoundError: + return 0 + + +def scoreshow(): + record_highest_score() + window2 = tk.Tk() + window2.title("HIGH SCORE") + window2.geometry("300x200") + + label = tk.Label(window2, text=f"Highest Score: {load_highest_score()}",font=(font, 12)) + + label.pack() + + window2.mainloop() + +def start_game(event): + global timeleft + if timeleft == 30: + countdown() + next_colour() + +window = tk.Tk() +font = 'Helvetica' +window.title("Color Game") +window.iconbitmap("color_game_icon.ico") +window.geometry("375x250") +window.resizable(False, False) + +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() + +label = tk.Label(window, font=(font, 60)) +label.pack(pady=20) + +e = tk.Entry(window) +window.bind('', start_game) +e.pack() + +e.focus_set() + window.mainloop() \ No newline at end of file From 06f6b4490cefff63fb9b29968cf65199feb8ab81 Mon Sep 17 00:00:00 2001 From: Prayas Dey Date: Fri, 14 Aug 2026 23:49:33 +0530 Subject: [PATCH 2/2] docs(Color_Game): update README with overview, features, usage, and gameplay rules --- Color_Game/README.md | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Color_Game/README.md b/Color_Game/README.md index ae4e1a56..6a4b65bd 100644 --- a/Color_Game/README.md +++ b/Color_Game/README.md @@ -1,5 +1,29 @@ -# COLOR GAME -_**Mechanics:**_ -* You must enter the color of the word, not the text itself. -* You have 30 seconds to play every round. -* The highest score will be recorded in the .txt file. \ No newline at end of file +# Color Game + +A fun and interactive Python Tkinter GUI game based on the Stroop Effect. The player must enter the font color of the displayed word, rather than the text of the word itself, within a 30-second time limit. + +## Features +- **Stroop Effect Challenge**: Tests cognitive processing and reaction time by presenting mismatched word names and colors. +- **Timer & Real-Time Scoring**: 30-second countdown with immediate score updates. +- **High Score Persistence**: Automatically tracks and saves the highest score in `highest_score.txt`. +- **Game Restart & Replay**: Easy restart mechanism to play multiple rounds. +- **Cross-Platform Compatibility**: Robust path resolution and safe icon handling across platforms. + +## Prerequisites +- Python 3.x +- Tkinter (included by default in standard Python installations) + +## How to Run +1. Navigate to the `Color_Game` directory: + ```bash + cd Color_Game + ``` +2. Run the script: + ```bash + python main.py + ``` + +## Rules / Gameplay +- Press `Enter` to start the game. +- Type the **color of the text** (e.g. if the word "BLUE" is shown in red font, type `red`) into the input box and press `Enter`. +- Score as many points as possible before the 30-second timer expires! \ No newline at end of file