Update app.py
Browse files2 unmodified lines34567891011121314151617181920212223242526272829303132333 unmodified lines37383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788892 unmodified lines92939495969798991001017 unmodified lines1091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541558 unmodified lines1641651661671681691702 unmodified linesdef draw_scene(keeper_pos, ball_dir):keeper_move = {"trái": "translateX(-80px) rotate(-20deg)","giữa": "translateX(0px)","phải": "translateX(80px) rotate(20deg)"}ball_path = {"trái": "translate(-120px, -180px)","giữa": "translate(0px, -200px)","phải": "translate(120px, -180px)"}html = f"""<div style="position:relative;width:100%;height:360px;background:linear-gradient(#4CAF50,#2e7d32);border-radius:20px;overflow:hidden;"><!-- KHUNG THÀNH --><div style="position:absolute;top:40px;left:15%;width:70%;height:140px;border:6px solid white;border-bottom:none;"></div><!-- LƯỚI --><div style="position:absolute;top:40px;left:15%;width:70%;height:140px;background:repeating-linear-gradient(to right, transparent, transparent 10px, rgba(255,255,255,0.2) 12px),repeating-linear-gradient(3 unmodified lines<!-- THỦ MÔN --><div style="position:absolute;top:120px;left:50%;transform:{keeper_move[keeper_pos]};transition: all 0.4s ease;"><!-- đầu --><div style="width:18px;height:18px;background:#ffd1a4;border-radius:50%;margin:auto;"></div><!-- thân --><div style="width:30px;height:45px;background:#2196F3;border-radius:8px;margin:auto;"></div><!-- tay --><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><!-- chân --><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></div><!-- CẦU THỦ --><div style="position:absolute;bottom:30px;left:50%;transform:translateX(-50%);"><div style="width:18px;height:18px;background:#ffd1a4;border-radius:50%;margin:auto;"></div><div style="width:30px;height:45px;background:#e53935;border-radius:8px;margin:auto;"></div><div style="display:flex;justify-content:space-between;"><div style="width:8px;height:25px;background:#e53935;transform:rotate(20deg);"></div><div style="width:8px;height:25px;background:#e53935;transform:rotate(-20deg);"></div></div><div style="display:flex;justify-content:space-between;"><div style="width:8px;height:25px;background:#b71c1c;"></div><div style="width:8px;height:25px;background:#b71c1c;"></div></div></div><!-- BÓNG --><div style="position:absolute;bottom:90px;left:50%;width:14px;height:14px;background:white;border-radius:50%;animation: shoot 0.7s ease-out forwards;2 unmodified lines<style>@keyframes shoot {{0% {{transform: translate(0,0);}}100% {{transform: {ball_path[ball_dir]};}}}}</style>7 unmodified lineskeeper = random.choice(["trái", "giữa", "phải"])if direction == keeper:result = f"🧤 Cản phá! Thủ môn đoán {keeper}"else:score += 1result = f"⚽ GOAL!!! Thủ môn đoán {keeper}"round_num += 1if round_num > 5:result += f"<br>🏁 Kết thúc! Bạn ghi {score}/5 bàn"return score, round_num, result, draw_scene(keeper, direction)with gr.Blocks(css="""button {font-size:18px !important;padding:12px !important;border-radius:12px !important;}""") as demo:gr.Markdown("# ⚽ Penalty Game PRO")score = gr.State(0)round_num = gr.State(1)score_text = gr.Markdown("**Điểm: 0 | Lượt: 1/5**")result = gr.Markdown("Chọn hướng sút 👇")field = gr.HTML(draw_scene("giữa", "giữa"))with gr.Row():btn_left = gr.Button("⬅️ Trái")btn_center = gr.Button("⬆️ Giữa")btn_right = gr.Button("➡️ Phải")btn_restart = gr.Button("🔄 Chơi lại")def update(direction, s, r):s, r, msg, html = shoot(direction, s, r)return s, r, f"**Điểm: {s} | Lượt: {min(r,5)}/5**", msg, htmlbtn_left.click(lambda s, r: update("trái", s, r),inputs=[score, round_num],8 unmodified linesoutputs=[score, round_num, score_text, result, field])btn_restart.click(lambda: (0, 1, "**Điểm: 0 | Lượt: 1/5**", "Game mới!", draw_scene("giữa", "giữa")),outputs=[score, round_num, score_text, result, field])2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383 unmodified lines424344454647484950515253545556575859606162636465666768697071727374752 unmodified lines787980818283848586877 unmodified lines95969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331348 unmodified lines1431441451461471481492 unmodified linesdef draw_scene(keeper_pos, ball_dir):keeper_move = {"trái": "translateX(-120px)","giữa": "translateX(0px)","phải": "translateX(120px)"}ball_target = {"trái": "translate(-150px, -250px)","giữa": "translate(0px, -280px)","phải": "translate(150px, -250px)"}html = f"""<div style="position:relative;width:100%;height:400px;background:linear-gradient(#6ec6ff,#2e7d32);overflow:hidden;border-radius:20px;"><!-- KHÁN ĐÀI --><div style="position:absolute;top:0;width:100%;height:120px;background:repeating-linear-gradient(45deg, red, red 10px, yellow 10px, yellow 20px);"></div><!-- KHUNG THÀNH --><div style="position:absolute;top:120px;left:20%;width:60%;height:140px;border:6px solid white;border-bottom:none;"></div><!-- LƯỚI --><div style="position:absolute;top:120px;left:20%;width:60%;height:140px;background:repeating-linear-gradient(to right, transparent, transparent 10px, rgba(255,255,255,0.2) 12px),repeating-linear-gradient(3 unmodified lines<!-- THỦ MÔN --><div style="position:absolute;top:180px;left:50%;transform:{keeper_move[keeper_pos]};transition: all 0.4s ease;"><div style="width:20px;height:20px;background:#ffd1a4;border-radius:50%;margin:auto;"></div><div style="width:35px;height:50px;background:#ff9800;border-radius:10px;margin:auto;"></div></div><!-- CẦU THỦ (NHÌN TỪ SAU) --><div style="position:absolute;bottom:40px;left:50%;transform:translateX(-50%);"><div style="width:25px;height:25px;background:#333;border-radius:50%;margin:auto;"></div><div style="width:40px;height:60px;background:#2196F3;border-radius:10px;margin:auto;"></div><div style="width:10px;height:40px;background:#000;display:inline-block;"></div><div style="width:10px;height:40px;background:#000;display:inline-block;"></div></div><!-- BÓNG --><div style="position:absolute;bottom:100px;left:50%;width:16px;height:16px;background:white;border-radius:50%;animation: shoot 0.7s ease-out forwards;2 unmodified lines<style>@keyframes shoot {{0% {{transform: translate(0,0) scale(1);}}100% {{transform: {ball_target[ball_dir]} scale(0.6);}}}}</style>7 unmodified lineskeeper = random.choice(["trái", "giữa", "phải"])if direction == keeper:result = f"🧤 Cản phá!"else:score += 1result = f"⚽ GOAL!!!"round_num += 1if round_num > 5:result += f"<br>🏁 Bạn ghi {score}/5 bàn"return score, round_num, result, draw_scene(keeper, direction)with gr.Blocks() as demo:gr.Markdown("# ⚽ Penalty Game (Real View)")score = gr.State(0)round_num = gr.State(1)score_text = gr.Markdown("**0 bàn | lượt 1/5**")result = gr.Markdown("Chọn hướng sút")field = gr.HTML(draw_scene("giữa", "giữa"))with gr.Row():btn_left = gr.Button("⬅️")btn_center = gr.Button("⬆️")btn_right = gr.Button("➡️")btn_restart = gr.Button("🔄")def update(direction, s, r):s, r, msg, html = shoot(direction, s, r)return s, r, f"**{s} bàn | lượt {min(r,5)}/5**", msg, htmlbtn_left.click(lambda s, r: update("trái", s, r),inputs=[score, round_num],8 unmodified linesoutputs=[score, round_num, score_text, result, field])btn_restart.click(lambda: (0, 1, "**0 bàn | lượt 1/5**", "Game mới!", draw_scene("giữa", "giữa")),outputs=[score, round_num, score_text, result, field])
app.py+52-73