খেলার নিয়ম
এই গেমে স্ক্রিনে একটি রঙের নাম লিখা থাকে, কিন্তু লেখাটি ভিন্ন রঙে দেখায়। খেলোয়াড়কে লেখার রঙটি সঠিকভাবে ধরতে হয়। প্রতি সঠিক উত্তরে ১ পয়েন্ট। মোট সময় ৩০ সেকেন্ড। রঙগুলো: লাল, নীল, সবুজ, গোলাপি, কালো, হলুদ, কমলা, সাদা, বেগুনি, কাপড়ির রঙ।
সম্পূর্ণ কোড
import tkinter
import random
# রঙের তালিকা
my_colours = ['Red','Blue','Green','Pink','Black','Yellow','Orange','White','Purple','Brown']
my_score = 0
my_timeleft = 30
def my_startGame(event):
if my_timeleft == 30:
my_countdown() # টাইমার শুরু
my_nextColour() # প্রথম রঙ দেখানো
def my_nextColour():
global my_score, my_timeleft
if my_timeleft > 0:
e.focus_set() # ইনপুট বক্সে ফোকাস
# ব্যবহারকারীর ইনপুট চেক করা (কেস-ইনসেনসিটিভ)
if e.get().lower() == my_colours[1].lower():
my_score += 1
e.delete(0, tkinter.END) # ইনপুট বক্স খালি করা
random.shuffle(my_colours) # রঙগুলো শাফল
# লেবেল আপডেট: টেক্সট = my_colours[0], রঙ = my_colours[1]
label.config(fg=str(my_colours[1]), text=str(my_colours[0]))
my_scoreLabel.config(text="Score: " + str(my_score))
def my_countdown():
global my_timeleft
if my_timeleft > 0:
my_timeleft -= 1
timeLabel.config(text="Time left: " + str(my_timeleft))
timeLabel.after(1000, my_countdown) # ১ সেকেন্ড পর আবার কল
# --- GUI সেটআপ ---
root = tkinter.Tk()
root.title("COLOR GAME")
root.geometry("375x200")
instructions = tkinter.Label(root, text="Type in the color\nof the words, and not the word text!", font=('Helvetica', 12))
instructions.pack()
my_scoreLabel = tkinter.Label(root, text="Press enter to start", font=('Helvetica', 12))
my_scoreLabel.pack()
timeLabel = tkinter.Label(root, text="Time left: " + str(my_timeleft), font=('Helvetica', 12))
timeLabel.pack()
label = tkinter.Label(root, font=('Helvetica', 60))
label.pack()
e = tkinter.Entry(root)
root.bind('', my_startGame) # এন্টার কী চাপলে গেম শুরু
e.pack()
e.focus_set()
root.mainloop()
কোড ব্যাখ্যা
random.shuffle()রঙের তালিকা যাদুকরি করে।label.config(fg=..., text=...)লেবেলের লেখার রঙ এবং টেক্সট পরিবর্তন করে।after(1000, func)১ সেকেন্ড পর ফাংশন কল করে (টাইমারের জন্য)।bind('এন্টার কীতে ফাংশন বাঁধা হয়েছে।', func)
বিকাশের সুযোগ
- উচ্চতম স্কোর সংরক্ষণ করা (high score)।
- কঠিনতা বাড়াতে রঙের সংখ্যা বাড়ানো।
- ধ্বনি প্রভাব যোগ করা।