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 and Plot Twists story_intro = """ ## 🐩 The Tyne Bridge Pigeon Rebellion ### **The Crisis** Newcastle is in **full-blown crisis**. The city's **most famous pigeon**, Pigeon Dave, is missing. As the **only bird in history to receive a salary**, he was meant to be the guest of honor at Newcastle’s **prestigious heritage ceremony**. 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**. """ history_section = """ ### **A Look Back in Time** The **Tyne Bridge**, completed in **1928**, is one of Newcastle’s most iconic landmarks. During its construction, a peculiar legend emerged—a pigeon, affectionately known as **Pigeon Dave**, became a fixture among the workers. Every morning, Dave **arrived like clockwork**, perched on scaffolding, and “supervised” the laborers. He became such an integral part of the team that, as a **good-humored gesture**, the city **put him on the payroll**, making him the **first and only paid pigeon in British history**. His story, once well-known, faded into obscurity—until today. **Now, it’s your job to track him down.** """ mission_section = """ ### **Your Mission** Unravel the conspiracy, follow the clues, and ensure Newcastle’s most famous bird **gets the recognition he deserves!** """ # Introducing Plot Twists & Multiple Endings plot_twists = [ "Pigeon Dave was **kidnapped by a secret underground pigeon racing ring** operating in Newcastle! Find the hideout and negotiate his release!", "Dave wasn’t kidnapped—**he was accidentally removed from city records due to a clerical error**. You must battle Newcastle’s bureaucracy to reinstate him!", "Dave doesn’t want to return—he’s **gone into retirement** in a cozy Jesmond garden. Convince him to come back for one last grand public appearance!" ] endings = [ "🏅 **Best Ending:** Dave arrives just in time, delivers a ceremonial ‘coo,’ and gets a **golden bird bath** in his honor!", "đŸ„ˆ **Neutral Ending:** A **random pigeon fills in for Dave**, the crowd doesn’t notice, and the ceremony proceeds. Meanwhile, Dave watches from a rooftop, nodding approvingly.", "đŸ„‰ **Bad Ending:** The Mayor replaces the event with a **two-hour PowerPoint on council budgets.** Newcastle mourns the lost legend." ] # New Set of More Challenging & Historically Rich Puzzles (Multiple Choice Format) puzzles = [ {"clue": "A cryptic message was found in a Greggs receipt near the Quayside.\nWhere should you investigate first?", "options": ["Grey’s Monument", "Tyne Bridge", "St. James’ Park"], "answer": "Tyne Bridge"}, {"clue": "The Tyne Bridge was inspired by another, more famous British bridge. Which one?", "options": ["Tower Bridge", "Sydney Harbour Bridge", "Brooklyn Bridge"], "answer": "Sydney Harbour Bridge"}, {"clue": "What is the only letter that does **not** appear in any UK city name?", "options": ["J", "Q", "X"], "answer": "J"}, {"clue": "Following a trail of breadcrumbs, you find a mysterious coded note reading: ‘NUFCTHR33L3G3ND’.\nWhat does it refer to?", "options": ["Kevin Keegan", "Alan Shearer", "Bobby Robson"], "answer": "Alan Shearer"}, {"clue": "A pub in Bigg Market reports a pigeon causing chaos at **closing time**. Solve this riddle:\n‘Though I have no feet, I leave tracks behind; You follow me wherever I go, Yet you cannot touch me or hold me. What am I?’", "options": ["Wind", "Shadow", "Echo"], "answer": "Shadow"}, {"clue": "A cryptic text message appears on your phone: ‘**Check the relic that guards wisdom.**’\nWhere should you look?", "options": ["Library", "Museum", "Cathedral"], "answer": "Library"}, {"clue": "Inside the library, an **ancient-looking book falls from the shelf**. The inside cover has a single question written in ink:\n‘**The more you take, the more you leave behind. What am I?**’", "options": ["Memories", "Footsteps", "Secrets"], "answer": "Footsteps"}, {"clue": "What is the **oldest building in Newcastle still standing?**", "options": ["Theatre Royal", "Castle Keep", "The Sage"], "answer": "Castle Keep"}, {"clue": "If Pigeon Dave worked on the Tyne Bridge construction, where would he have hidden?", "options": ["High Level Bridge", "The Baltic", "Central Station"], "answer": "High Level Bridge"}, {"clue": "What was Newcastle’s original name during Roman times?", "options": ["Hadrian’s Wall", "Pons Aelius", "Vicus"], "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 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 == current_puzzle["answer"]: state["progress"] += 1 state["clues_solved"] += 1 if state["progress"] == len(puzzles): return random.choice(endings), 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) gr.Markdown(history_section) gr.Markdown(mission_section) game_output = gr.Textbox(label="Game Status", interactive=False, value=start_game()) user_input = gr.Radio(label="Your Answer", choices=[""], interactive=True) 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()