Spaces:
Sleeping
Sleeping
Commit
·
b8a1a18
1
Parent(s):
63495b1
change
Browse files
app.py
CHANGED
@@ -1,16 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
|
4 |
-
def flappy_bird(
|
|
|
|
|
|
|
|
|
5 |
PIPE_WIDTH = 3
|
6 |
GAME_HEIGHT = 5
|
7 |
GAP_SIZE = 2
|
8 |
|
9 |
if game_over:
|
10 |
-
return "Game Over! Your score: {}\
|
11 |
-
|
12 |
-
if command.lower() == "start":
|
13 |
-
return get_game_state(2, 2, 0, 0), 0, 2, 2, 0, False
|
14 |
|
15 |
# Move bird based on command
|
16 |
bird_position += 1 if command.lower() != "flap" else -1
|
@@ -49,26 +50,28 @@ def get_game_state(height, gap_position, bird_position, score):
|
|
49 |
return game_state
|
50 |
|
51 |
iface = gr.Interface(
|
52 |
-
|
53 |
inputs=[
|
54 |
-
gr.
|
55 |
-
gr.
|
56 |
-
gr.
|
57 |
-
gr.
|
58 |
-
gr.
|
59 |
-
gr.
|
60 |
],
|
61 |
outputs=[
|
62 |
gr.Textbox(label="Game State"),
|
63 |
-
gr.
|
64 |
-
gr.
|
65 |
-
gr.
|
66 |
-
gr.
|
67 |
-
gr.
|
68 |
],
|
69 |
title="Simple Text-based Flappy Bird Game",
|
70 |
-
description="
|
71 |
)
|
72 |
|
|
|
|
|
73 |
if __name__ == "__main__":
|
74 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
|
4 |
+
def flappy_bird(_):
|
5 |
+
# Initialize or reset the game state
|
6 |
+
return get_game_state(2, 2, 0, 0), 0, 2, 2, 0, False
|
7 |
+
|
8 |
+
def update_game(command, height, gap_position, bird_position, score, game_over):
|
9 |
PIPE_WIDTH = 3
|
10 |
GAME_HEIGHT = 5
|
11 |
GAP_SIZE = 2
|
12 |
|
13 |
if game_over:
|
14 |
+
return "Game Over! Your score: {}\nClick 'Start' to play again.".format(score), 0, 2, 2, 0, False
|
|
|
|
|
|
|
15 |
|
16 |
# Move bird based on command
|
17 |
bird_position += 1 if command.lower() != "flap" else -1
|
|
|
50 |
return game_state
|
51 |
|
52 |
iface = gr.Interface(
|
53 |
+
fn=update_game,
|
54 |
inputs=[
|
55 |
+
gr.Buttons(choices=["flap"], label="Control"),
|
56 |
+
gr.State(),
|
57 |
+
gr.State(),
|
58 |
+
gr.State(),
|
59 |
+
gr.State(),
|
60 |
+
gr.State()
|
61 |
],
|
62 |
outputs=[
|
63 |
gr.Textbox(label="Game State"),
|
64 |
+
gr.State(),
|
65 |
+
gr.State(),
|
66 |
+
gr.State(),
|
67 |
+
gr.State(),
|
68 |
+
gr.State()
|
69 |
],
|
70 |
title="Simple Text-based Flappy Bird Game",
|
71 |
+
description="Click 'Start' to begin. Then click 'Flap' to move the bird up and avoid the pipes."
|
72 |
)
|
73 |
|
74 |
+
iface.add_component(gr.Button("Start").click(flappy_bird, [], ["game_state", "height", "gap_position", "bird_position", "score", "game_over"]), "above")
|
75 |
+
|
76 |
if __name__ == "__main__":
|
77 |
iface.launch()
|