olivercareyncl's picture
Update app.py
6b8cbf3 verified
raw
history blame
5.89 kB
import gradio as gr
import random
import time
# Game State
state = {
"progress": 0,
"clues_solved": 0,
"found_dave": False,
"start_time": None,
"hints_used": 0
}
# Enhanced Storyline with Historical Context
story_intro = """
## 🐦 The Tyne Bridge Pigeon Rebellion
It is **present day**, and Newcastle is in **full-blown crisis**.
**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**.
But **disaster has struck**—**Pigeon Dave has vanished without a trace**!
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**.
### 📜 **Historical Context**
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.
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.
**Your Mission:** Track down Pigeon Dave, unravel the conspiracy, and ensure Newcastle’s most famous bird gets the **recognition he deserves!**
"""
# New Set of More Challenging & Historically Rich Puzzles
puzzles = [
{"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"},
{"clue": "The Tyne Bridge was inspired by another, more famous British bridge. Which one?", "answer": "Sydney Harbour Bridge"},
{"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"},
{"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"},
{"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"},
{"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"},
{"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"},
{"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"},
{"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"},
{"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"}
]
# Timer and Scoring System
def start_game():
state["progress"] = 0
state["clues_solved"] = 0
state["found_dave"] = False
state["start_time"] = time.time()
state["hints_used"] = 0
return story_intro + "\n\n**First Clue:** " + puzzles[0]["clue"]
def get_hint():
if state["progress"] < len(puzzles):
state["hints_used"] += 1
return f"Hint: The answer starts with '{puzzles[state['progress']]['answer'][0]}'."
return "No more hints available!"
def game_logic(user_input):
if state["progress"] < len(puzzles):
current_puzzle = puzzles[state["progress"]]
if user_input.strip().lower() == current_puzzle["answer"].strip().lower():
state["progress"] += 1
state["clues_solved"] += 1
if state["progress"] == len(puzzles):
state["found_dave"] = True
elapsed_time = time.time() - state["start_time"]
score = max(100 - (elapsed_time // 10) - (state["hints_used"] * 5), 0)
return f"🎉 You found Pigeon Dave! Newcastle is saved! 🐦\nFinal Score: {int(score)}", None
return f"✅ Correct! {puzzles[state['progress']]['clue']}", None
else:
return "❌ Not quite! Try again.", None
return "🎉 Game Over - You already found Pigeon Dave! 🐦", None
def reset_game():
return start_game(), None
# Gradio Interface
with gr.Blocks() as app:
gr.Markdown(story_intro)
game_output = gr.Textbox(label="Game Status", interactive=False, value=start_game())
user_input = gr.Textbox(label="Your Answer")
submit_btn = gr.Button("Submit Answer")
hint_btn = gr.Button("Get a Hint")
reset_btn = gr.Button("Reset Game")
submit_btn.click(game_logic, inputs=user_input, outputs=game_output)
hint_btn.click(get_hint, outputs=game_output)
reset_btn.click(reset_game, outputs=game_output)
app.launch()