Spaces:
Sleeping
Sleeping
File size: 1,921 Bytes
e0878df 5702df1 e0878df 5702df1 6bc94d7 5702df1 6bc94d7 5702df1 6bc94d7 5702df1 6bc94d7 5702df1 6bc94d7 5702df1 6bc94d7 5702df1 6bc94d7 5702df1 6bc94d7 5702df1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import gradio as gr
# Initialize game state
game_state = {"step": 0}
# Game logic
def play_game(user_input):
step = game_state["step"]
user_input = user_input.strip().lower()
if step == 0:
game_state["step"] = 1
return "You are in a dark forest. Do you go 'left' or 'right'?"
elif step == 1:
if user_input == "left":
game_state["step"] = 2
return "You see a river. Do you 'swim' across or 'build a raft'?"
elif user_input == "right":
game_state["step"] = 3
return "You meet a wizard. Do you 'talk' to him or 'run' away?"
else:
return "Please type 'left' or 'right'."
elif step == 2:
if user_input == "swim":
game_state["step"] = 4
return "You tried to swim and got swept away! Game Over. Type anything to restart."
elif user_input == "build a raft":
game_state["step"] = 4
return "You safely crossed the river. You win! π Type anything to restart."
else:
return "Please choose 'swim' or 'build a raft'."
elif step == 3:
if user_input == "talk":
game_state["step"] = 4
return "The wizard gives you a treasure. You win! π§ββοΈ Type anything to restart."
elif user_input == "run":
game_state["step"] = 4
return "The wizard curses you! Game Over. Type anything to restart."
else:
return "Please choose 'talk' or 'run'."
else:
game_state["step"] = 0
return "The game is restarted. Do you want to go 'left' or 'right'?"
# Gradio interface
iface = gr.Interface(
fn=play_game,
inputs=gr.Textbox(placeholder="Type your choice here..."),
outputs="text",
title="πΉοΈ Simple Text Adventure Game",
description="Make your choices and see where the story goes!"
)
iface.launch() |