Download app.py from won987/ai: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/spaces/won987/ai/resolve/main/app.py
- Command line
-
hf download hf://spaces/won987/ai/app.py
-
curl -L -o app.py https://huggingface.co/spaces/won987/ai/resolve/main/app.py
2.2 kB
| import gradio as gr | |
| import random | |
| player = {"name": "์ฉ์ฌ", "hp": 100, "max_hp": 100, "atk": 20, "def": 5} | |
| monster = {} | |
| def start_battle(): | |
| global monster | |
| monster = { | |
| "name": random.choice(["๊ณ ๋ธ๋ฆฐ", "๋๋", "์ฌ๋ผ์", "๋์ "]), | |
| "hp": random.randint(30, 70), | |
| "atk": random.randint(10, 20), | |
| "def": random.randint(2, 6) | |
| } | |
| return f"{monster['name']}์ด(๊ฐ) ๋ํ๋ฌ๋ค! ์ฒด๋ ฅ: {monster['hp']}" | |
| def attack(): | |
| if not monster: | |
| return "๋จผ์ ๋ชฌ์คํฐ๋ฅผ ์ํํ์ธ์!" | |
| dmg = max(1, player["atk"] - monster["def"]) | |
| monster["hp"] -= dmg | |
| log = f"{player['name']}์ด(๊ฐ) {monster['name']}์๊ฒ {dmg}์ ํผํด๋ฅผ ์ ํ๋ค.\n" | |
| if monster["hp"] <= 0: | |
| log += f"{monster['name']}์(๋ฅผ) ์ฒ์นํ๋ค!" | |
| monster.clear() | |
| return log | |
| enemy_dmg = max(1, monster["atk"] - player["def"]) | |
| player["hp"] -= enemy_dmg | |
| log += f"{monster['name']}์ด(๊ฐ) {player['name']}์๊ฒ {enemy_dmg}์ ํผํด๋ฅผ ์ ํ๋ค.\n" | |
| if player["hp"] <= 0: | |
| return log + "๋น์ ์ ์ฐ๋ฌ์ก์ต๋๋ค..." | |
| return log | |
| def heal(): | |
| if player["hp"] >= player["max_hp"]: | |
| return "์ด๋ฏธ ์ฒด๋ ฅ์ด ๊ฐ๋ ์ฐผ์ต๋๋ค." | |
| player["hp"] = min(player["max_hp"], player["hp"] + 30) | |
| return f"ํฌ์ ์ ์ฌ์ฉํ์ฌ ์ฒด๋ ฅ์ ํ๋ณตํ์ต๋๋ค. ํ์ฌ ์ฒด๋ ฅ: {player['hp']}" | |
| def get_status(): | |
| return f"{player['name']} ์ฒด๋ ฅ: {player['hp']}/{player['max_hp']}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# โ๏ธ ๋๋ง์ RPG ๊ฒ์") | |
| status = gr.Textbox(label="ํ๋ ์ด์ด ์ํ", value=get_status()) | |
| log = gr.Textbox(label="์ ํฌ ๋ก๊ทธ") | |
| with gr.Row(): | |
| btn_battle = gr.Button("๋ชฌ์คํฐ ์ํ") | |
| btn_attack = gr.Button("๊ณต๊ฒฉ") | |
| btn_heal = gr.Button("ํฌ์ ์ฌ์ฉ") | |
| btn_battle.click(fn=start_battle, outputs=log, show_progress=False) | |
| btn_attack.click(fn=attack, outputs=log, show_progress=False) | |
| btn_heal.click(fn=heal, outputs=log, show_progress=False) | |
| btn_battle.click(fn=get_status, outputs=status) | |
| btn_attack.click(fn=get_status, outputs=status) | |
| btn_heal.click(fn=get_status, outputs=status) | |
| demo.launch() |