import random
import time
import tkinter as tk
from tkinter import messagebox
# 1. 카드 데이터 설정
SUITS = ["♠", "♥", "♦", "♣"]
RANKS = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
class ACAANTrainerApp:
def __init__(self, root):
self.root = root
self.root.title("ACAAN 마술 실전 연습기")
self.root.geometry("450x550")
self.root.configure(bg="#1E1E2E")
# 상태 변수
self.current_card = ""
self.current_num = 0
self.start_time = 0
self.total_trials = 0
self.correct_trials = 0
# UI 레이아웃 구성
self.create_widgets()
def create_widgets(self):
# 타이틀
title_label = tk.Label(
self.root,
text="🃏 ACAAN Trainer",
font=("Arial", 22, "bold"),
fg="#F5E0DC",
bg="#1E1E2E",
)
title_label.pack(pady=20)
# 서브 설명
sub_label = tk.Label(
self.root,
text="숫자 범위: 3 ~ 27 | 카드: 52장 무작위",
font=("Arial", 11),
fg="#BAC2DE",
bg="#1E1E2E",
)
sub_label.pack(pady=5)
# 카드 표시 카드판
self.card_frame = tk.Frame(
self.root,
bg="#313244",
bd=2,
relief="groove",
padx=20,
pady=20,
)
self.card_frame.pack(pady=20, fill="x", padx=40)
self.card_label = tk.Label(
self.card_frame,
text="[ 시작 버튼을 누르세요 ]",
font=("Arial", 18, "bold"),
fg="#A6E3A1",
bg="#313244",
)
self.card_label.pack(pady=10)
self.num_label = tk.Label(
self.card_frame,
text="숫자: -",
font=("Arial", 16, "bold"),
fg="#89B4FA",
bg="#313244",
)
self.num_label.pack(pady=5)
# 타이머 및 메시지 표시
self.timer_label = tk.Label(
self.root,
text="소요 시간: 0.00초",
font=("Arial", 13),
fg="#CDD6F4",
bg="#1E1E2E",
)
self.timer_label.pack(pady=10)
# 메인 버튼 (새 문제 / 계산 완료)
self.action_btn = tk.Button(
self.root,
text="🎲 문제 뽑기",
font=("Arial", 14, "bold"),
bg="#89B4FA",
fg="#11111B",
activebackground="#B4BEFE",
padx=20,
pady=10,
command=self.next_question,
)
self.action_btn.pack(pady=10)
# 정답 자가 체크 프레임 (초기에는 숨김)
self.check_frame = tk.Frame(self.root, bg="#1E1E2E")
self.check_frame.pack(pady=15)
self.correct_btn = tk.Button(
self.check_frame,
text="✅ 정답!",
font=("Arial", 12, "bold"),
bg="#A6E3A1",
fg="#11111B",
width=10,
command=lambda: self.record_result(True),
)
self.correct_btn.grid(row=0, column=0, padx=10)
self.wrong_btn = tk.Button(
self.check_frame,
text="❌ 오답",
font=("Arial", 12, "bold"),
bg="#F38BA8",
fg="#11111B",
width=10,
command=lambda: self.record_result(False),
)
self.wrong_btn.grid(row=0, column=1, padx=10)
# 하단 스코어보드
self.score_label = tk.Label(
self.root,
text="시도: 0회 | 성공: 0회 | 성공률: 0%",
font=("Arial", 11),
fg="#A6ADC8",
bg="#1E1E2E",
)
self.score_label.pack(side="bottom", pady=20)
def next_question(self):
"""새로운 카드와 숫자를 무작위로 뽑습니다."""
suit = random.choice(SUITS)
rank = random.choice(RANKS)
self.current_card = f"{suit} {rank}"
# 하트/다이아몬드는 빨간색으로 포인트
color = "#F38BA8" if suit in ["♥", "♦"] else "#CDD6F4"
# 숫자: 3 ~ 27 제한
self.current_num = random.randint(3, 27)
# 화면 업데이트
self.card_label.config(
text=f"카드 : {self.current_card}", fg=color
)
self.num_label.config(text=f"지목된 숫자 : {self.current_num}")
# 타이머 시작 및 버튼 상태 전환
self.start_time = time.time()
self.timer_label.config(
text="⏱️ 계산 중...", fg="#FAB387"
)
self.action_btn.config(
text="💡 계산 완료! (클릭)", command=self.stop_timer
)
def stop_timer(self):
"""계산 완료 시 타이머를 멈추고 정답 여부를 확인합니다."""
if self.start_time == 0:
return
elapsed_time = round(time.time() - self.start_time, 2)
self.timer_label.config(
text=f"⏱️ 소요 시간: {elapsed_time}초", fg="#A6E3A1"
)
# 다음 단계를 위해 버튼 재설정
self.action_btn.config(
text="🎲 다음 문제", command=self.next_question
)
def record_result(self, is_correct):
"""성공/실패 결과를 기록하고 스코어를 갱신합니다."""
if self.current_card == "":
messagebox.showwarning(
"경고", "먼저 '문제 뽑기'를 진행해 주세요!"
)
return
self.total_trials += 1
if is_correct:
self.correct_trials += 1
accuracy = round((self.correct_trials / self.total_trials) * 100, 1)
self.score_label.config(
text=f"시도: {self.total_trials}회 | 성공: {self.correct_trials}회 | 성공률: {accuracy}%"
)
# 다음 문제 자동 시작
self.next_question()
if __name__ == "__main__":
root = tk.Tk()
app = ACAANTrainerApp(root)
root.mainloop()