feature/start-screen-and-stats-screen #2
@ -6,7 +6,6 @@ class ActionButtons:
|
||||
self.gui = gui # Reference to main GUI for callbacks
|
||||
self._create_button_frame()
|
||||
self._create_action_buttons()
|
||||
self._create_control_buttons()
|
||||
|
||||
def _create_button_frame(self):
|
||||
"""Matches original button frame creation"""
|
||||
@ -59,40 +58,6 @@ class ActionButtons:
|
||||
)
|
||||
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):
|
||||
"""Original enable/disable functionality"""
|
||||
state = "normal" if enable else "disabled"
|
||||
|
||||
73
gui/gui.py
73
gui/gui.py
@ -29,29 +29,64 @@ class BlackjackGUI:
|
||||
# Card display
|
||||
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)
|
||||
|
||||
# Hint button
|
||||
self.hint_button = ctk.CTkButton(
|
||||
self.app,
|
||||
text="Hint",
|
||||
command=self.show_hint,
|
||||
fg_color="white",
|
||||
text_color="black",
|
||||
font=("Arial", 20)
|
||||
)
|
||||
self.hint_button.pack(pady=10)
|
||||
|
||||
# Feedback label (centered — matches web layout)
|
||||
self.feedback_label = ctk.CTkLabel(
|
||||
self.app,
|
||||
text="",
|
||||
font=("Arial", 20),
|
||||
wraplength=550,
|
||||
anchor="center"
|
||||
)
|
||||
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.buttons.hint_button)
|
||||
self.hints.set_hint_button(self.hint_button)
|
||||
|
||||
# Stats display
|
||||
self.stats = StatsDisplay(self.app)
|
||||
|
||||
# Feedback label (only remaining widget in main file)
|
||||
self.feedback_label = ctk.CTkLabel(
|
||||
self.app,
|
||||
text="",
|
||||
font=("Arial", 20),
|
||||
wraplength=550,
|
||||
anchor="w"
|
||||
)
|
||||
self.feedback_label.pack(pady=20, padx=10, fill="x")
|
||||
|
||||
def start_new_round(self):
|
||||
"""Start a new round of the game"""
|
||||
self._reset_ui()
|
||||
@ -61,9 +96,9 @@ class BlackjackGUI:
|
||||
def _reset_ui(self):
|
||||
"""Reset UI for new round"""
|
||||
self.hints._close_hint_window()
|
||||
self.buttons.hint_button.configure(state="normal")
|
||||
self.hint_button.configure(state="normal")
|
||||
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._reset_button_colors()
|
||||
|
||||
@ -85,7 +120,7 @@ class BlackjackGUI:
|
||||
text_color="green"
|
||||
)
|
||||
self.buttons._enable_action_buttons(False)
|
||||
self.buttons.next_round_button.configure(state="normal")
|
||||
self.next_round_button.configure(state="normal")
|
||||
|
||||
# Handle split possibility
|
||||
can_split_bool = can_split(self.game_logic.player_hand)
|
||||
@ -148,7 +183,7 @@ class BlackjackGUI:
|
||||
|
||||
# Update button states
|
||||
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):
|
||||
"""Handle window close event — just close directly"""
|
||||
@ -173,7 +208,7 @@ class BlackjackGUI:
|
||||
|
||||
ctk.CTkLabel(
|
||||
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),
|
||||
text_color="#ccc",
|
||||
wraplength=450,
|
||||
@ -213,8 +248,8 @@ class BlackjackGUI:
|
||||
def _exit(self):
|
||||
"""Exit button handler — show stats popup"""
|
||||
self.buttons._enable_action_buttons(False)
|
||||
self.buttons.next_round_button.configure(state="disabled")
|
||||
self.buttons.hint_button.configure(state="disabled")
|
||||
self.next_round_button.configure(state="disabled")
|
||||
self.hint_button.configure(state="disabled")
|
||||
self.stats._show_exit_popup(self.game_logic.get_stats(), self._exit_to_start)
|
||||
|
||||
def _exit_to_start(self):
|
||||
|
||||
@ -56,7 +56,9 @@ body{background:#2b2b2b;color:#fff;font-family:Arial,sans-serif;display:flex;jus
|
||||
<div id="start-screen">
|
||||
<div id="start-content">
|
||||
<h1>🃏 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>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,7 +142,7 @@ function markButton(btn,correct){
|
||||
btn.style.color='#fff';
|
||||
}
|
||||
|
||||
function renderCards(dc,hc,isNewRound){
|
||||
function renderCards(dc,hc){
|
||||
dealerCards.innerHTML='';
|
||||
playerCards.innerHTML='';
|
||||
var d=document.createElement('img');
|
||||
@ -151,24 +153,17 @@ function renderCards(dc,hc,isNewRound){
|
||||
i.src=cardUrl(c);i.alt='Player card';
|
||||
playerCards.appendChild(i);
|
||||
});
|
||||
if(isNewRound){
|
||||
feedback.textContent='';
|
||||
if(hc===undefined){
|
||||
btnHint.disabled=false;
|
||||
btnNext.disabled=true;
|
||||
enableActions(true);
|
||||
resetButtonColors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function startRound(){
|
||||
try{
|
||||
var r=await fetch('/api/start-round',{method:'POST'});
|
||||
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);
|
||||
btnHint.disabled=false;
|
||||
btnNext.disabled=true;
|
||||
enableActions(true);
|
||||
resetButtonColors();
|
||||
if(d.has_blackjack){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user