pip install transformers pip install datasets pip install gradio import turtle import random import gradio as gr # 플레이어 클래스 class Player(turtle.Turtle): def __init__(self): super().__init__() self.shape("circle") self.color("blue") self.penup() self.speed(0) self.direction = "stop" def move(self): if self.direction == "up": self.sety(self.ycor() + 10) elif self.direction == "down": self.sety(self.ycor() - 10) elif self.direction == "left": self.setx(self.xcor() - 10) elif self.direction == "right": self.setx(self.xcor() + 10) # 장애물 클래스 class Obstacle(turtle.Turtle): def __init__(self): super().__init__() self.shape("square") self.color("red") self.penup() self.speed(0) self.goto(random.randint(-200, 200), random.randint(-200, 200)) # 키 이벤트 함수 def go_up(): player.direction = "up" def go_down(): player.direction = "down" def go_left(): player.direction = "left" def go_right(): player.direction = "right" # 게임 실행 함수 def run_game(): win = turtle.Screen() win.title("Keyboard Controlled Game") win.bgcolor("white") win.setup(width=500, height=500) # 플레이어 및 장애물 생성 player = Player() obstacles = [Obstacle() for _ in range(5)] # 키보드 이벤트 바인딩 win.listen() win.onkeypress(go_up, "Up") win.onkeypress(go_down, "Down") win.onkeypress(go_left, "Left") win.onkeypress(go_right, "Right") while True: win.update() # 플레이어 이동 player.move() # 장애물 이동 및 충돌 체크 for obstacle in obstacles: obstacle.setx(obstacle.xcor() - 2) if player.distance(obstacle) < 20: print("Game Over") return # Gradio 인터페이스 실행 iface = gr.Interface(fn=run_game, inputs=None, outputs=None, title="Keyboard Controlled Game", description="Use arrow keys to move the player. Avoid red squares.") iface.launch()