fix bug and improvement

This commit is contained in:
Maik 2026-06-13 22:27:45 +02:00
parent a1b5805727
commit 4299dd48c5
3 changed files with 68 additions and 73 deletions

View File

@ -6,7 +6,6 @@ class ActionButtons:
self.gui = gui # Reference to main GUI for callbacks self.gui = gui # Reference to main GUI for callbacks
self._create_button_frame() self._create_button_frame()
self._create_action_buttons() self._create_action_buttons()
self._create_control_buttons()
def _create_button_frame(self): def _create_button_frame(self):
"""Matches original button frame creation""" """Matches original button frame creation"""
@ -59,40 +58,6 @@ class ActionButtons:
) )
self.split_button.grid(row=1, column=1, padx=10, pady=10) self.split_button.grid(row=1, column=1, padx=10, pady=10)
def _create_control_buttons(self):
"""Replicates hint and next round buttons"""
self.hint_button = ctk.CTkButton(
self.parent,
text="Hint",
command=self.gui.show_hint,
fg_color="white",
text_color="black",
font=("Arial", 20)
)
self.hint_button.pack(pady=10)
self.next_round_button = ctk.CTkButton(
self.parent,
text="Next Round",
command=self.gui.start_new_round,
fg_color="white",
text_color="black",
font=("Arial", 20)
)
self.next_round_button.pack(pady=10)
self.next_round_button.configure(state="disabled")
self.exit_button = ctk.CTkButton(
self.parent,
text="Exit",
command=self.gui._exit,
fg_color="#555",
text_color="#ccc",
font=("Arial", 16),
hover_color="#666"
)
self.exit_button.pack(pady=(4, 10))
def _enable_action_buttons(self, enable): def _enable_action_buttons(self, enable):
"""Original enable/disable functionality""" """Original enable/disable functionality"""
state = "normal" if enable else "disabled" state = "normal" if enable else "disabled"

View File

@ -28,30 +28,65 @@ class BlackjackGUI:
"""Create all UI components""" """Create all UI components"""
# Card display # Card display
self.card_display = CardDisplay(self.app, self.card_images) self.card_display = CardDisplay(self.app, self.card_images)
# Buttons (pass reference to self for callbacks) # Action buttons (Hit, Stand, Double, Split)
self.buttons = ActionButtons(self.app, self) self.buttons = ActionButtons(self.app, self)
# Notifications # Hint button
self.notifications = NotificationSystem(self.app) self.hint_button = ctk.CTkButton(
self.app,
# Hint system text="Hint",
self.hints = HintSystem(self.app) command=self.show_hint,
self.hints.set_hint_button(self.buttons.hint_button) fg_color="white",
text_color="black",
# Stats display font=("Arial", 20)
self.stats = StatsDisplay(self.app) )
self.hint_button.pack(pady=10)
# Feedback label (only remaining widget in main file)
# Feedback label (centered — matches web layout)
self.feedback_label = ctk.CTkLabel( self.feedback_label = ctk.CTkLabel(
self.app, self.app,
text="", text="",
font=("Arial", 20), font=("Arial", 20),
wraplength=550, wraplength=550,
anchor="w" anchor="center"
) )
self.feedback_label.pack(pady=20, padx=10, fill="x") self.feedback_label.pack(pady=20, padx=10, fill="x")
# Next Round button
self.next_round_button = ctk.CTkButton(
self.app,
text="Next Round",
command=self.start_new_round,
fg_color="white",
text_color="black",
font=("Arial", 20)
)
self.next_round_button.pack(pady=10)
self.next_round_button.configure(state="disabled")
# Exit button
self.exit_button = ctk.CTkButton(
self.app,
text="Exit",
command=self._exit,
fg_color="#555",
text_color="#ccc",
font=("Arial", 16),
hover_color="#666"
)
self.exit_button.pack(pady=(4, 10))
# Notifications
self.notifications = NotificationSystem(self.app)
# Hint system
self.hints = HintSystem(self.app)
self.hints.set_hint_button(self.hint_button)
# Stats display
self.stats = StatsDisplay(self.app)
def start_new_round(self): def start_new_round(self):
"""Start a new round of the game""" """Start a new round of the game"""
self._reset_ui() self._reset_ui()
@ -61,9 +96,9 @@ class BlackjackGUI:
def _reset_ui(self): def _reset_ui(self):
"""Reset UI for new round""" """Reset UI for new round"""
self.hints._close_hint_window() self.hints._close_hint_window()
self.buttons.hint_button.configure(state="normal") self.hint_button.configure(state="normal")
self.feedback_label.configure(text="") self.feedback_label.configure(text="")
self.buttons.next_round_button.configure(state="disabled") self.next_round_button.configure(state="disabled")
self.buttons._enable_action_buttons(True) self.buttons._enable_action_buttons(True)
self.buttons._reset_button_colors() self.buttons._reset_button_colors()
@ -85,7 +120,7 @@ class BlackjackGUI:
text_color="green" text_color="green"
) )
self.buttons._enable_action_buttons(False) self.buttons._enable_action_buttons(False)
self.buttons.next_round_button.configure(state="normal") self.next_round_button.configure(state="normal")
# Handle split possibility # Handle split possibility
can_split_bool = can_split(self.game_logic.player_hand) can_split_bool = can_split(self.game_logic.player_hand)
@ -148,7 +183,7 @@ class BlackjackGUI:
# Update button states # Update button states
self.buttons._enable_action_buttons(False) self.buttons._enable_action_buttons(False)
self.buttons.next_round_button.configure(state="normal") self.next_round_button.configure(state="normal")
def _on_main_window_close(self): def _on_main_window_close(self):
"""Handle window close event — just close directly""" """Handle window close event — just close directly"""
@ -173,7 +208,7 @@ class BlackjackGUI:
ctk.CTkLabel( ctk.CTkLabel(
content, content,
text="This is a blackjack basic strategy trainer and not a real blackjack game.\n\nEach round you're dealt a hand and asked to make the correct play (Hit, Stand, Double, or Split) according to basic strategy. You get immediate feedback and track your accuracy over time.", text="This is a blackjack basic strategy trainer and not a real blackjack game.\n\nEach round you're dealt a hand and asked to make the correct play (Hit, Stand, Double, or Split) according to basic strategy. You get immediate feedback and track your accuracy over time.\n\nHave Fun!",
font=("Arial", 15), font=("Arial", 15),
text_color="#ccc", text_color="#ccc",
wraplength=450, wraplength=450,
@ -213,8 +248,8 @@ class BlackjackGUI:
def _exit(self): def _exit(self):
"""Exit button handler — show stats popup""" """Exit button handler — show stats popup"""
self.buttons._enable_action_buttons(False) self.buttons._enable_action_buttons(False)
self.buttons.next_round_button.configure(state="disabled") self.next_round_button.configure(state="disabled")
self.buttons.hint_button.configure(state="disabled") self.hint_button.configure(state="disabled")
self.stats._show_exit_popup(self.game_logic.get_stats(), self._exit_to_start) self.stats._show_exit_popup(self.game_logic.get_stats(), self._exit_to_start)
def _exit_to_start(self): def _exit_to_start(self):

View File

@ -56,7 +56,9 @@ body{background:#2b2b2b;color:#fff;font-family:Arial,sans-serif;display:flex;jus
<div id="start-screen"> <div id="start-screen">
<div id="start-content"> <div id="start-content">
<h1>&#x1F0CF; Blackjack Theory Trainer</h1> <h1>&#x1F0CF; Blackjack Theory Trainer</h1>
<p>This is a blackjack basic strategy trainer and not a real blackjack game. Each round you're dealt a hand and asked to make the correct play (Hit, Stand, Double, or Split) according to basic strategy. You get immediate feedback and track your accuracy over time.</p> <p>This is a blackjack basic strategy trainer and not a real blackjack game.</p>
<p>Each round you're dealt a hand and asked to make the correct play (Hit, Stand, Double, or Split) according to basic strategy. You get immediate feedback and track your accuracy over time.</p>
<p>Have Fun!</p>
<button id="btn-start">Start Training</button> <button id="btn-start">Start Training</button>
</div> </div>
</div> </div>
@ -140,7 +142,7 @@ function markButton(btn,correct){
btn.style.color='#fff'; btn.style.color='#fff';
} }
function renderCards(dc,hc,isNewRound){ function renderCards(dc,hc){
dealerCards.innerHTML=''; dealerCards.innerHTML='';
playerCards.innerHTML=''; playerCards.innerHTML='';
var d=document.createElement('img'); var d=document.createElement('img');
@ -151,24 +153,17 @@ function renderCards(dc,hc,isNewRound){
i.src=cardUrl(c);i.alt='Player card'; i.src=cardUrl(c);i.alt='Player card';
playerCards.appendChild(i); playerCards.appendChild(i);
}); });
if(isNewRound){
feedback.textContent='';
if(hc===undefined){
btnHint.disabled=false;
btnNext.disabled=true;
enableActions(true);
resetButtonColors();
}
}
} }
async function startRound(){ async function startRound(){
try{ try{
var r=await fetch('/api/start-round',{method:'POST'}); var r=await fetch('/api/start-round',{method:'POST'});
var d=await r.json(); var d=await r.json();
renderCards(d.dealer_card,d.player_hand,true); renderCards(d.dealer_card,d.player_hand);
feedback.textContent='';
setStreak(d.current_streak); setStreak(d.current_streak);
btnHint.disabled=false; btnHint.disabled=false;
btnNext.disabled=true;
enableActions(true); enableActions(true);
resetButtonColors(); resetButtonColors();
if(d.has_blackjack){ if(d.has_blackjack){