Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,67 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
|
|
3 |
|
4 |
# Game State
|
5 |
state = {
|
6 |
"progress": 0,
|
7 |
"clues_solved": 0,
|
8 |
-
"found_dave": False
|
|
|
|
|
9 |
}
|
10 |
|
11 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
puzzles = [
|
13 |
-
{
|
14 |
-
|
15 |
-
|
16 |
-
},
|
17 |
-
{
|
18 |
-
|
19 |
-
|
20 |
-
},
|
21 |
-
{
|
22 |
-
|
23 |
-
"answer": "Traffic Cone"
|
24 |
-
},
|
25 |
-
{
|
26 |
-
"clue": "What’s the correct pigeon call to summon Dave for the ceremony?",
|
27 |
-
"answer": "Coo-coo"
|
28 |
-
}
|
29 |
]
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def game_logic(user_input):
|
32 |
if state["progress"] < len(puzzles):
|
33 |
current_puzzle = puzzles[state["progress"]]
|
@@ -36,31 +70,29 @@ def game_logic(user_input):
|
|
36 |
state["clues_solved"] += 1
|
37 |
if state["progress"] == len(puzzles):
|
38 |
state["found_dave"] = True
|
39 |
-
|
|
|
|
|
40 |
return f"✅ Correct! {puzzles[state['progress']]['clue']}", None
|
41 |
else:
|
42 |
return "❌ Not quite! Try again.", None
|
43 |
return "🎉 Game Over - You already found Pigeon Dave! 🐦", None
|
44 |
|
45 |
def reset_game():
|
46 |
-
|
47 |
-
state["clues_solved"] = 0
|
48 |
-
state["found_dave"] = False
|
49 |
-
return "Game reset! First clue: " + puzzles[0]["clue"], None
|
50 |
|
51 |
# Gradio Interface
|
52 |
with gr.Blocks() as app:
|
53 |
-
gr.Markdown(
|
54 |
-
# 🐦 The Tyne Bridge Pigeon Rebellion
|
55 |
-
Pigeon Dave has vanished before an important ceremony! Solve the puzzles to find him before it's too late!
|
56 |
-
""")
|
57 |
|
58 |
-
game_output = gr.Textbox(label="Game Status", interactive=False, value=
|
59 |
user_input = gr.Textbox(label="Your Answer")
|
60 |
submit_btn = gr.Button("Submit Answer")
|
|
|
61 |
reset_btn = gr.Button("Reset Game")
|
62 |
|
63 |
submit_btn.click(game_logic, inputs=user_input, outputs=game_output)
|
|
|
64 |
reset_btn.click(reset_game, outputs=game_output)
|
65 |
|
66 |
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
+
import time
|
4 |
|
5 |
# Game State
|
6 |
state = {
|
7 |
"progress": 0,
|
8 |
"clues_solved": 0,
|
9 |
+
"found_dave": False,
|
10 |
+
"start_time": None,
|
11 |
+
"hints_used": 0
|
12 |
}
|
13 |
|
14 |
+
# Enhanced Storyline with Historical Context
|
15 |
+
story_intro = """
|
16 |
+
## 🐦 The Tyne Bridge Pigeon Rebellion
|
17 |
+
|
18 |
+
It is **present day**, and Newcastle is in **full-blown crisis**.
|
19 |
+
|
20 |
+
**Pigeon Dave**, the **only bird in history to ever receive a salary**, was meant to be the guest of honor at Newcastle’s **prestigious heritage ceremony**.
|
21 |
+
|
22 |
+
But **disaster has struck**—**Pigeon Dave has vanished without a trace**!
|
23 |
+
|
24 |
+
The **Lord Mayor is preparing his speech**, the **media is swarming**, and the **city’s reputation is on the line**. If Pigeon Dave is not found **within the next hour**, the ceremony will be an **absolute disaster**.
|
25 |
+
|
26 |
+
### 📜 **Historical Context**
|
27 |
+
|
28 |
+
The **Tyne Bridge**, completed in **1928**, is an architectural symbol of Newcastle. During its construction, a peculiar legend emerged—a pigeon, affectionately known as **Pigeon Dave**, became a fixture among the workers. The laborers swore that he arrived **daily**, observed the progress, and even took **breaks** like a regular employee.
|
29 |
+
|
30 |
+
Eventually, as a **good-humored gesture**, the city put **Pigeon Dave on the payroll**, making him the **first and only paid pigeon in British history**. For decades, his tale was forgotten, buried under layers of bureaucratic paperwork—until now.
|
31 |
+
|
32 |
+
**Your Mission:** Track down Pigeon Dave, unravel the conspiracy, and ensure Newcastle’s most famous bird gets the **recognition he deserves!**
|
33 |
+
"""
|
34 |
+
|
35 |
+
# New Set of More Challenging & Historically Rich Puzzles
|
36 |
puzzles = [
|
37 |
+
{"clue": "The first sighting: A cryptic message was found in a Greggs receipt near the Quayside.\nIt reads: ‘A legend once stood where the river bends, under the gaze of steel giants.’\nWhere should you investigate first?", "answer": "Tyne Bridge"},
|
38 |
+
{"clue": "The Tyne Bridge was inspired by another, more famous British bridge. Which one?", "answer": "Sydney Harbour Bridge"},
|
39 |
+
{"clue": "A street performer near the bridge claims to have seen Dave, but they will only talk if you answer:\nWhat is the only letter that does **not** appear in any UK city name?", "answer": "J"},
|
40 |
+
{"clue": "Following a trail of suspicious breadcrumbs, you find a **mysterious coded note**.\nThe note reads: ‘NUFCTHR33L3G3ND’\nWhat does it refer to?", "answer": "Alan Shearer"},
|
41 |
+
{"clue": "A bartender at a pub in the Bigg Market swears he saw a pigeon causing chaos at **closing time**.\nTo unlock the next clue, solve this riddle:\n‘Though I have no feet, I leave tracks behind;\nYou follow me wherever I go,\nYet you cannot touch me or hold me.\nWhat am I?’", "answer": "Shadow"},
|
42 |
+
{"clue": "The search leads you to **Jesmond**, where Dave was last spotted.\nA cryptic text message appears on your phone: ‘**Check the relic that guards wisdom.**’\nWhere should you look?", "answer": "Library"},
|
43 |
+
{"clue": "Inside the library, an **ancient-looking book falls from the shelf**.\nThe inside cover has a single question written in ink:\n‘**The more you take, the more you leave behind. What am I?**’", "answer": "Footsteps"},
|
44 |
+
{"clue": "A librarian mentions that a **local historian** has vital information about Pigeon Dave.\nBut first, they want you to answer:\nWhat is the **oldest building in Newcastle still standing?**", "answer": "Castle Keep"},
|
45 |
+
{"clue": "The historian reveals that Dave may be at his old haunt—**his favorite secret hideout from the 1920s**.\nIf Pigeon Dave worked on the Tyne Bridge construction, where would he have hidden?", "answer": "High Level Bridge"},
|
46 |
+
{"clue": "At the **High Level Bridge**, you finally spot Dave! But he refuses to return unless you prove you are truly worthy.\nTo complete your mission, answer this final challenge:\n‘What was Newcastle’s original name during Roman times?’", "answer": "Pons Aelius"}
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
]
|
48 |
|
49 |
+
# Timer and Scoring System
|
50 |
+
|
51 |
+
def start_game():
|
52 |
+
state["progress"] = 0
|
53 |
+
state["clues_solved"] = 0
|
54 |
+
state["found_dave"] = False
|
55 |
+
state["start_time"] = time.time()
|
56 |
+
state["hints_used"] = 0
|
57 |
+
return story_intro + "\n\n**First Clue:** " + puzzles[0]["clue"]
|
58 |
+
|
59 |
+
def get_hint():
|
60 |
+
if state["progress"] < len(puzzles):
|
61 |
+
state["hints_used"] += 1
|
62 |
+
return f"Hint: The answer starts with '{puzzles[state['progress']]['answer'][0]}'."
|
63 |
+
return "No more hints available!"
|
64 |
+
|
65 |
def game_logic(user_input):
|
66 |
if state["progress"] < len(puzzles):
|
67 |
current_puzzle = puzzles[state["progress"]]
|
|
|
70 |
state["clues_solved"] += 1
|
71 |
if state["progress"] == len(puzzles):
|
72 |
state["found_dave"] = True
|
73 |
+
elapsed_time = time.time() - state["start_time"]
|
74 |
+
score = max(100 - (elapsed_time // 10) - (state["hints_used"] * 5), 0)
|
75 |
+
return f"🎉 You found Pigeon Dave! Newcastle is saved! 🐦\nFinal Score: {int(score)}", None
|
76 |
return f"✅ Correct! {puzzles[state['progress']]['clue']}", None
|
77 |
else:
|
78 |
return "❌ Not quite! Try again.", None
|
79 |
return "🎉 Game Over - You already found Pigeon Dave! 🐦", None
|
80 |
|
81 |
def reset_game():
|
82 |
+
return start_game(), None
|
|
|
|
|
|
|
83 |
|
84 |
# Gradio Interface
|
85 |
with gr.Blocks() as app:
|
86 |
+
gr.Markdown(story_intro)
|
|
|
|
|
|
|
87 |
|
88 |
+
game_output = gr.Textbox(label="Game Status", interactive=False, value=start_game())
|
89 |
user_input = gr.Textbox(label="Your Answer")
|
90 |
submit_btn = gr.Button("Submit Answer")
|
91 |
+
hint_btn = gr.Button("Get a Hint")
|
92 |
reset_btn = gr.Button("Reset Game")
|
93 |
|
94 |
submit_btn.click(game_logic, inputs=user_input, outputs=game_output)
|
95 |
+
hint_btn.click(get_hint, outputs=game_output)
|
96 |
reset_btn.click(reset_game, outputs=game_output)
|
97 |
|
98 |
app.launch()
|