Update app.py
Browse files10 unmodified lines11121314141516171820192021222324252627272829293031303132333433353637381 unmodified line404142434445464748496 unmodified lines5657585359605556616263645960656667686938 unmodified lines10810911010511111211311419 unmodified lines13413513613113713813914010 unmodified lines}
def draw_scene(keeper_pos, ball_dir, is_goal): # Thủ môn bay người keeper_move = { "trái": "translateX(-80px) rotate(-20deg)", "giữa": "translateX(0px)", "phải": "translateX(80px) rotate(20deg)" } # Bóng bay # bóng sẽ dính vào thủ môn nếu cản phá if is_goal: ball_path = { "trái": "translate(-120px, -180px)", "giữa": "translate(0px, -200px)", "phải": "translate(120px, -180px)" } else: # cản phá, bóng văng sang bên ngoài else: # bóng dính vào thủ môn (ở chính giữa đầu/thân thủ môn) ball_path = { "trái": "translate(-180px, -50px)", "giữa": "translate(0px, -50px)", "phải": "translate(180px, -50px)" "trái": "translate(0px, 0px)", "giữa": "translate(0px, 0px)", "phải": "translate(0px, 0px)" }
# Màu áo cầu thủ theo đội # màu áo cầu thủ theo đội if state["turn"] == "A": shirt_color = "#2196F3" pants_color = "#1565C0"1 unmodified line shirt_color = "#e53935" pants_color = "#b71c1c"
# Thủ môn áo vàng cố định keeper_shirt = "#FFEB3B" keeper_pants = "#FBC02D"
html = f""" <div style="position:relative;width:100%;height:360px;background:linear-gradient(#4CAF50,#2e7d32);border-radius:20px;overflow:hidden;"> <!-- Khung thành -->6 unmodified lines <!-- Thủ môn --> <div style="position:absolute;top:120px;left:50%;transform:{keeper_move[keeper_pos]};transition: all 0.4s ease;"> <div style="width:18px;height:18px;background:#ffd1a4;border-radius:50%;margin:auto;"></div> <div style="width:30px;height:45px;background:#2196F3;border-radius:8px;margin:auto;"></div> <div style="width:30px;height:45px;background:{keeper_shirt};border-radius:8px;margin:auto;"></div> <div style="display:flex;justify-content:space-between;"> <div style="width:8px;height:25px;background:#2196F3;transform:rotate(30deg);"></div> <div style="width:8px;height:25px;background:#2196F3;transform:rotate(-30deg);"></div> <div style="width:8px;height:25px;background:{keeper_shirt};transform:rotate(30deg);"></div> <div style="width:8px;height:25px;background:{keeper_shirt};transform:rotate(-30deg);"></div> </div> <div style="display:flex;justify-content:space-between;"> <div style="width:8px;height:25px;background:#1565C0;"></div> <div style="width:8px;height:25px;background:#1565C0;"></div> <div style="width:8px;height:25px;background:{keeper_pants};"></div> <div style="width:8px;height:25px;background:{keeper_pants};"></div> </div> </div>
38 unmodified lines if hit: state["score_b"] +=1
msg = f"Đội {state['turn']} sút {direction}, thủ môn đoán {keeper} → " msg += "⚽ Bàn thắng!" if hit else "🧤 Cản phá!" msg += "⚽ Bàn thắng!" if hit else "🧤 Cản phá, bóng dính thủ môn!"
scene = draw_scene(keeper, direction, hit)
19 unmodified lines return 0,0,1,"A","Game mới bắt đầu! Đội A sút trước.",scene
with gr.Blocks() as demo: gr.Markdown("# ⚽ Penalty 2 Đội – 5 lượt + Bóng văng khi cản phá") gr.Markdown("# ⚽ Penalty 2 Đội – Thủ môn vàng + Bóng dính thủ môn")
score_a = gr.State(0) score_b = gr.State(0)app.py+20-14