awacke1 commited on
Commit
e75654e
Β·
verified Β·
1 Parent(s): bb3644c

Create index.html

Browse files

# "Choose Your Own Epic Adventure!" 🎲✨πŸšͺ

Files changed (1) hide show
  1. index.html +1081 -0
index.html ADDED
@@ -0,0 +1,1081 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Gradio Choose Your Own Adventure</title>
7
+ <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
8
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
9
+ <style>
10
+ body {
11
+ font-family: 'Courier New', monospace;
12
+ background-color: #f0f0f0;
13
+ margin: 0;
14
+ padding: 20px;
15
+ }
16
+
17
+ h1 {
18
+ color: #c00;
19
+ text-align: center;
20
+ margin-bottom: 20px;
21
+ }
22
+
23
+ .container {
24
+ max-width: 900px;
25
+ margin: 0 auto;
26
+ background-color: white;
27
+ border: 5px solid #d4a017;
28
+ border-radius: 10px;
29
+ padding: 20px;
30
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
31
+ }
32
+
33
+ .game-description {
34
+ text-align: center;
35
+ margin-bottom: 20px;
36
+ padding-bottom: 10px;
37
+ border-bottom: 2px solid #d4a017;
38
+ }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <div class="container">
43
+ <h1>CHOOSE YOUR OWN ADVENTURE</h1>
44
+ <div class="game-description">
45
+ <p>An interactive text adventure game powered by Gradio-lite</p>
46
+ <p><em>Can you defeat the Evil Power Master and save the land?</em></p>
47
+ </div>
48
+
49
+ <gradio-lite theme="light">
50
+ <gradio-file name="app.py" entrypoint>
51
+ import gradio as gr
52
+ import random
53
+ import json
54
+ from game_data import game_data, illustrations, enemies_data, items_data
55
+ from game_engine import GameState, create_svg_illustration
56
+
57
+ def initialize_game():
58
+ """Initialize a new game with default state"""
59
+ game_state = GameState()
60
+ current_page = 1
61
+ page_data = game_data[str(current_page)]
62
+
63
+ # Create the SVG illustration
64
+ svg_content = create_svg_illustration(page_data["illustration"])
65
+
66
+ # Build page content
67
+ content = f"<h2>{page_data['title']}</h2>"
68
+ content += page_data["content"]
69
+
70
+ # Build options
71
+ options = []
72
+ for opt in page_data["options"]:
73
+ options.append(opt["text"])
74
+
75
+ # Update game statistics display
76
+ stats = f"""
77
+ <div style='display: flex; flex-wrap: wrap; gap: 10px; margin-top: 15px;'>
78
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px;'>
79
+ <strong>Courage:</strong> {game_state.stats['courage']}
80
+ </div>
81
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px;'>
82
+ <strong>Wisdom:</strong> {game_state.stats['wisdom']}
83
+ </div>
84
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px;'>
85
+ <strong>Strength:</strong> {game_state.stats['strength']}
86
+ </div>
87
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px;'>
88
+ <strong>HP:</strong> {game_state.current_hp}/{game_state.max_hp}
89
+ </div>
90
+ </div>
91
+ """
92
+
93
+ # Initialize inventory as empty
94
+ inventory = ""
95
+
96
+ # Set story path
97
+ story_path = "You are at the beginning of your adventure."
98
+
99
+ return svg_content, content, gr.Dropdown(choices=options, label="What will you do?"), game_state.to_json(), stats, inventory, story_path
100
+
101
+ def update_game(choice, game_state_json):
102
+ """Update game based on player choice"""
103
+ # Parse game state from JSON
104
+ game_state_dict = json.loads(game_state_json)
105
+ game_state = GameState.from_dict(game_state_dict)
106
+
107
+ # Get current page data
108
+ current_page = game_state.current_page
109
+ page_data = game_data[str(current_page)]
110
+
111
+ # Find the selected option
112
+ selected_option = None
113
+ for i, opt in enumerate(page_data["options"]):
114
+ if opt["text"] == choice:
115
+ selected_option = opt
116
+ break
117
+
118
+ if selected_option is None:
119
+ return "Error: Option not found", "Please try again", gr.Dropdown(choices=["Restart"]), game_state.to_json(), "", "", ""
120
+
121
+ # Check if this option requires an item
122
+ if "requireItem" in selected_option and selected_option["requireItem"] not in game_state.inventory:
123
+ content = f"<p>You need the <strong>{selected_option['requireItem']}</strong> for this option, but you don't have it.</p>"
124
+ options = [opt["text"] for opt in page_data["options"]]
125
+ return create_svg_illustration(page_data["illustration"]), content, gr.Dropdown(choices=options), game_state.to_json(), generate_stats_display(game_state), generate_inventory_display(game_state), f"You remain on page {current_page}."
126
+
127
+ # Process special items to collect
128
+ if "addItem" in selected_option and selected_option["addItem"] not in game_state.inventory:
129
+ game_state.inventory.append(selected_option["addItem"])
130
+
131
+ # Move to the next page
132
+ next_page = selected_option["next"]
133
+ game_state.current_page = next_page
134
+ game_state.visited_pages.append(next_page)
135
+
136
+ # Update journey progress based on page transitions
137
+ game_state.journey_progress += 5 # Increment progress with each decision
138
+ if game_state.journey_progress > 100:
139
+ game_state.journey_progress = 100
140
+
141
+ # Check for random battle (20% chance if page has randomBattle flag)
142
+ if "randomBattle" in page_data and page_data["randomBattle"] and random.random() < 0.2:
143
+ battle_result = simulate_battle(game_state)
144
+ if not battle_result:
145
+ # Player died in battle
146
+ content = "<h2>Game Over</h2><p>You have been defeated in battle!</p>"
147
+ return create_svg_illustration("game-over"), content, gr.Dropdown(choices=["Restart"]), game_state.to_json(), generate_stats_display(game_state), generate_inventory_display(game_state), "Game Over - You were defeated in battle."
148
+
149
+ # Get new page data
150
+ page_data = game_data[str(next_page)]
151
+
152
+ # Create the SVG illustration
153
+ svg_content = create_svg_illustration(page_data["illustration"])
154
+
155
+ # Process page stat effects
156
+ if "statIncrease" in page_data:
157
+ stat = page_data["statIncrease"]["stat"]
158
+ amount = page_data["statIncrease"]["amount"]
159
+ game_state.stats[stat] += amount
160
+
161
+ # Process HP loss
162
+ if "hpLoss" in page_data:
163
+ game_state.current_hp -= page_data["hpLoss"]
164
+ if game_state.current_hp <= 0:
165
+ game_state.current_hp = 0
166
+ content = "<h2>Game Over</h2><p>You have died from your wounds!</p>"
167
+ return create_svg_illustration("game-over"), content, gr.Dropdown(choices=["Restart"]), game_state.to_json(), generate_stats_display(game_state), generate_inventory_display(game_state), "Game Over - You died from your wounds."
168
+
169
+ # Check if this is a challenge page
170
+ if "challenge" in page_data:
171
+ challenge = page_data["challenge"]
172
+ success = perform_challenge(game_state, challenge)
173
+
174
+ # Update story based on challenge result
175
+ if success:
176
+ next_page = challenge["success"]
177
+ else:
178
+ next_page = challenge["failure"]
179
+
180
+ game_state.current_page = next_page
181
+ game_state.visited_pages.append(next_page)
182
+ page_data = game_data[str(next_page)]
183
+ svg_content = create_svg_illustration(page_data["illustration"])
184
+
185
+ # Handle game over
186
+ if "gameOver" in page_data and page_data["gameOver"]:
187
+ content = f"<h2>{page_data['title']}</h2>"
188
+ content += page_data["content"]
189
+ if "ending" in page_data:
190
+ content += f"<div style='text-align: center; margin-top: 20px; font-weight: bold; color: #c00;'>THE END</div>"
191
+ content += f"<p style='font-style: italic;'>{page_data['ending']}</p>"
192
+
193
+ return svg_content, content, gr.Dropdown(choices=["Restart"]), game_state.to_json(), generate_stats_display(game_state), generate_inventory_display(game_state), "Game Over - " + page_data['title']
194
+
195
+ # Build page content
196
+ content = f"<h2>{page_data['title']}</h2>"
197
+ content += page_data["content"]
198
+
199
+ # Build options
200
+ options = []
201
+ for opt in page_data["options"]:
202
+ # Check if option requires an item
203
+ if "requireItem" in opt and opt["requireItem"] not in game_state.inventory:
204
+ continue
205
+ # Check if option requires any item from a list
206
+ if "requireAnyItem" in opt:
207
+ has_required_item = False
208
+ for item in opt["requireAnyItem"]:
209
+ if item in game_state.inventory:
210
+ has_required_item = True
211
+ break
212
+ if not has_required_item:
213
+ continue
214
+
215
+ options.append(opt["text"])
216
+
217
+ # Handle alternative option if necessary
218
+ if "alternativeOption" in page_data and not options:
219
+ alt_opt = page_data["alternativeOption"]
220
+ if "showIf" not in alt_opt or any(item in game_state.inventory for item in alt_opt["showIf"]):
221
+ options.append(alt_opt["text"])
222
+
223
+ # Update game progress
224
+ story_path = f"You are on page {next_page}: {page_data['title']}"
225
+ if game_state.journey_progress >= 80:
226
+ story_path += " (Nearing the conclusion)"
227
+ elif game_state.journey_progress >= 50:
228
+ story_path += " (Middle of your journey)"
229
+ elif game_state.journey_progress >= 25:
230
+ story_path += " (Adventure beginning)"
231
+
232
+ return svg_content, content, gr.Dropdown(choices=options), game_state.to_json(), generate_stats_display(game_state), generate_inventory_display(game_state), story_path
233
+
234
+ def generate_stats_display(game_state):
235
+ """Generate HTML for displaying player stats"""
236
+ # Calculate HP percentage for the progress bar
237
+ hp_percent = (game_state.current_hp / game_state.max_hp) * 100
238
+ hp_color = "#4CAF50" # Green
239
+ if hp_percent < 30:
240
+ hp_color = "#F44336" # Red
241
+ elif hp_percent < 70:
242
+ hp_color = "#FFC107" # Yellow
243
+
244
+ stats = f"""
245
+ <div style='display: flex; flex-wrap: wrap; gap: 10px; margin-top: 15px;'>
246
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px;'>
247
+ <strong>Courage:</strong> {game_state.stats['courage']}
248
+ </div>
249
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px;'>
250
+ <strong>Wisdom:</strong> {game_state.stats['wisdom']}
251
+ </div>
252
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px;'>
253
+ <strong>Strength:</strong> {game_state.stats['strength']}
254
+ </div>
255
+ <div style='background: #f0f0f0; padding: 5px 10px; border-radius: 5px; position: relative;'>
256
+ <strong>HP:</strong> {game_state.current_hp}/{game_state.max_hp}
257
+ <div style='width: 100px; height: 5px; background: #e0e0e0; margin-top: 3px; border-radius: 3px;'>
258
+ <div style='width: {hp_percent}%; height: 100%; background: {hp_color}; border-radius: 3px;'></div>
259
+ </div>
260
+ </div>
261
+ </div>
262
+ """
263
+
264
+ # Add journey progress
265
+ stats += f"""
266
+ <div style='margin-top: 10px;'>
267
+ <div style='display: flex; justify-content: space-between; font-size: 12px;'>
268
+ <span>Journey Progress:</span>
269
+ <span>{game_state.journey_progress}%</span>
270
+ </div>
271
+ <div style='width: 100%; height: 5px; background: #e0e0e0; border-radius: 3px;'>
272
+ <div style='width: {game_state.journey_progress}%; height: 100%; background: #2196F3; border-radius: 3px;'></div>
273
+ </div>
274
+ </div>
275
+ """
276
+
277
+ return stats
278
+
279
+ def generate_inventory_display(game_state):
280
+ """Generate HTML for displaying player inventory"""
281
+ if not game_state.inventory:
282
+ return "<em>Your inventory is empty.</em>"
283
+
284
+ inventory_html = "<div style='display: flex; flex-wrap: wrap; gap: 10px;'>"
285
+
286
+ for item in game_state.inventory:
287
+ item_data = items_data.get(item, {"type": "unknown", "description": "A mysterious item."})
288
+ bg_color = "#e0e0e0"
289
+ if item_data["type"] == "weapon":
290
+ bg_color = "#ffcdd2"
291
+ elif item_data["type"] == "armor":
292
+ bg_color = "#c8e6c9"
293
+ elif item_data["type"] == "spell":
294
+ bg_color = "#bbdefb"
295
+ elif item_data["type"] == "quest":
296
+ bg_color = "#fff9c4"
297
+
298
+ inventory_html += f"""
299
+ <div style='background: {bg_color}; padding: 5px 10px; border-radius: 5px; position: relative;'
300
+ title="{item_data['description']}">
301
+ {item}
302
+ </div>
303
+ """
304
+
305
+ inventory_html += "</div>"
306
+ return inventory_html
307
+
308
+ def perform_challenge(game_state, challenge):
309
+ """Perform a skill challenge and determine success"""
310
+ stat = challenge["stat"]
311
+ difficulty = challenge["difficulty"]
312
+
313
+ # Roll dice (1-6) and add stat
314
+ roll = random.randint(1, 6)
315
+ total = roll + game_state.stats[stat]
316
+
317
+ # Determine if successful
318
+ success = total >= difficulty
319
+
320
+ # Bonus for great success
321
+ if success and total >= difficulty + 3:
322
+ stat_increase = random.randint(1, 2)
323
+ game_state.stats[stat] += stat_increase
324
+
325
+ # Penalty for bad failure
326
+ if not success and total <= difficulty - 3:
327
+ stat_decrease = random.randint(1, 2)
328
+ game_state.stats[stat] = max(1, game_state.stats[stat] - stat_decrease)
329
+
330
+ # Record challenge outcome
331
+ if success:
332
+ game_state.challenges_won += 1
333
+
334
+ return success
335
+
336
+ def simulate_battle(game_state):
337
+ """Simulate a battle with a random enemy"""
338
+ # Select a random enemy type
339
+ enemy_types = list(enemies_data.keys())
340
+ enemy_type = random.choice(enemy_types)
341
+ enemy = enemies_data[enemy_type]
342
+
343
+ # Simple battle simulation
344
+ player_hp = game_state.current_hp
345
+ enemy_hp = enemy["hp"]
346
+
347
+ player_attack = game_state.stats["strength"]
348
+ player_defense = 1 # Base defense
349
+
350
+ # Add weapon bonus if the player has a weapon
351
+ for item in game_state.inventory:
352
+ item_data = items_data.get(item, {})
353
+ if "attackBonus" in item_data:
354
+ player_attack += item_data["attackBonus"]
355
+ if "defenseBonus" in item_data:
356
+ player_defense += item_data["defenseBonus"]
357
+
358
+ enemy_attack = enemy["attack"]
359
+ enemy_defense = enemy["defense"]
360
+
361
+ # Simple turn-based combat
362
+ while player_hp > 0 and enemy_hp > 0:
363
+ # Player attacks
364
+ damage = max(1, player_attack - enemy_defense)
365
+ enemy_hp -= damage
366
+
367
+ if enemy_hp <= 0:
368
+ break
369
+
370
+ # Enemy attacks
371
+ damage = max(1, enemy_attack - player_defense)
372
+ player_hp -= damage
373
+
374
+ # Update player HP after battle
375
+ game_state.current_hp = player_hp
376
+
377
+ # Return True if player won, False if player lost
378
+ return player_hp > 0
379
+
380
+ def restart_game(choice, game_state_json):
381
+ """Restart the game when the player chooses to restart"""
382
+ if choice == "Restart":
383
+ return initialize_game()
384
+ else:
385
+ # Parse existing game state
386
+ game_state_dict = json.loads(game_state_json)
387
+ game_state = GameState.from_dict(game_state_dict)
388
+
389
+ # Return current game state
390
+ current_page = game_state.current_page
391
+ page_data = game_data[str(current_page)]
392
+
393
+ svg_content = create_svg_illustration(page_data["illustration"])
394
+ content = f"<h2>{page_data['title']}</h2>"
395
+ content += page_data["content"]
396
+
397
+ options = []
398
+ for opt in page_data["options"]:
399
+ options.append(opt["text"])
400
+
401
+ return svg_content, content, gr.Dropdown(choices=options), game_state.to_json(), generate_stats_display(game_state), generate_inventory_display(game_state), f"You are on page {current_page}: {page_data['title']}"
402
+
403
+ # Create Gradio interface
404
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
405
+ gr.Markdown("# Choose Your Own Adventure")
406
+ gr.Markdown("### Can you defeat the Evil Power Master?")
407
+
408
+ with gr.Row():
409
+ with gr.Column(scale=2):
410
+ illustration = gr.HTML(label="Scene")
411
+ content = gr.HTML(label="Story")
412
+ choice = gr.Dropdown(label="What will you do?")
413
+
414
+ # Hidden field to store game state as JSON
415
+ game_state = gr.Textbox(visible=False)
416
+
417
+ with gr.Column(scale=1):
418
+ story_path = gr.Markdown(label="Your Path")
419
+ stats = gr.HTML(label="Character Stats")
420
+ inventory = gr.HTML(label="Inventory")
421
+ map_btn = gr.Button("View Story Map")
422
+
423
+ # Initialize or restart the game
424
+ choice.change(update_game, [choice, game_state], [illustration, content, choice, game_state, stats, inventory, story_path])
425
+
426
+ # Handle restart
427
+ demo.load(initialize_game, [], [illustration, content, choice, game_state, stats, inventory, story_path])
428
+
429
+ demo.launch()
430
+ </gradio-file>
431
+
432
+ <gradio-file name="game_engine.py">
433
+ import json
434
+ import random
435
+
436
+ class GameState:
437
+ """Class to manage game state"""
438
+ def __init__(self):
439
+ self.current_page = 1
440
+ self.visited_pages = [1]
441
+ self.inventory = []
442
+ self.max_hp = 30
443
+ self.current_hp = 30
444
+ self.stats = {
445
+ "courage": 7,
446
+ "wisdom": 5,
447
+ "strength": 6,
448
+ "luck": 4
449
+ }
450
+ self.status_effects = []
451
+ self.enemies_defeated = 0
452
+ self.challenges_won = 0
453
+ self.current_path = "main"
454
+ self.journey_progress = 0
455
+
456
+ def to_json(self):
457
+ """Convert game state to JSON string"""
458
+ return json.dumps(self.__dict__)
459
+
460
+ @classmethod
461
+ def from_dict(cls, data):
462
+ """Create a GameState object from a dictionary"""
463
+ game_state = cls()
464
+ for key, value in data.items():
465
+ setattr(game_state, key, value)
466
+ return game_state
467
+
468
+ def create_svg_illustration(illustration_key):
469
+ """Return SVG illustration based on the illustration key"""
470
+ # If illustration is not found, use a default illustration
471
+ if illustration_key not in illustrations:
472
+ illustration_key = "default"
473
+
474
+ # Wrap the SVG in a container div with appropriate styling
475
+ return f"""
476
+ <div style="width: 100%; height: 250px; border: 2px solid #999; border-radius: 5px; overflow: hidden;">
477
+ {illustrations[illustration_key]}
478
+ </div>
479
+ """
480
+ </gradio-file>
481
+
482
+ <gradio-file name="game_data.py">
483
+ # Game content data - contains all pages with branching storylines
484
+
485
+ game_data = {
486
+ "1": {
487
+ "title": "The Beginning",
488
+ "content": """<p>The Evil Power Master has been terrorizing the land for years. With his dark magic, he has enslaved villages, summoned terrible monsters, and threatens to plunge the world into eternal darkness.</p>
489
+ <p>You, a skilled adventurer, have been called upon to stop him. You stand at the entrance to the last free city, Silverhold, ready to begin your quest.</p>
490
+ <p>The fate of the world rests on your shoulders. How will you prepare for your journey?</p>""",
491
+ "options": [
492
+ { "text": "Visit the local weaponsmith for equipment", "next": 2 },
493
+ { "text": "Seek wisdom at the ancient temple", "next": 3 },
494
+ { "text": "Meet with the resistance leader for information", "next": 4 }
495
+ ],
496
+ "illustration": "city-gates"
497
+ },
498
+
499
+ "2": {
500
+ "title": "The Weaponsmith",
501
+ "content": """<p>The city's renowned weaponsmith, Gorn, welcomes you to his forge. Weapons of all kinds line the walls, from simple daggers to exotic blades that pulse with magic.</p>
502
+ <p>"I've been expecting you," Gorn says. "The Evil Power Master's fortress is treacherous. You'll need more than common steel to face what lies ahead."</p>
503
+ <p>He presents you with three weapons, each crafted with special materials and enchantments.</p>""",
504
+ "options": [
505
+ { "text": "Take the Flaming Sword, powerful but dangerous", "next": 5, "addItem": "Flaming Sword" },
506
+ { "text": "Choose the Whispering Bow, silent and precise", "next": 5, "addItem": "Whispering Bow" },
507
+ { "text": "Select the Guardian Shield, defensive and protective", "next": 5, "addItem": "Guardian Shield" }
508
+ ],
509
+ "illustration": "weaponsmith"
510
+ },
511
+
512
+ "3": {
513
+ "title": "The Ancient Temple",
514
+ "content": """<p>The Temple of Eternal Light stands at the heart of Silverhold. Inside, the air is thick with incense, and soft chanting echoes through the chambers.</p>
515
+ <p>High Priestess Alara greets you with concern in her eyes. "The Evil Power Master grows stronger each day. Before you face him, you should prepare your mind and spirit."</p>
516
+ <p>She offers to teach you one of the temple's secret arts to aid your quest.</p>""",
517
+ "options": [
518
+ { "text": "Learn the Healing Light technique", "next": 5, "addItem": "Healing Light Spell" },
519
+ { "text": "Master the Shield of Faith protection", "next": 5, "addItem": "Shield of Faith Spell" },
520
+ { "text": "Study the ancient Binding Runes", "next": 5, "addItem": "Binding Runes Scroll" }
521
+ ],
522
+ "illustration": "temple"
523
+ },
524
+
525
+ "4": {
526
+ "title": "The Resistance Leader",
527
+ "content": """<p>In a secluded tavern, you meet Lyra, leader of the resistance against the Evil Power Master. Battle-scarred but determined, she unfurls a map across the table.</p>
528
+ <p>"His fortress has three possible entry points," she explains, pointing to marked locations. "Each has its dangers and advantages. You must choose your path carefully."</p>
529
+ <p>She also offers you a special item from the resistance's limited supplies.</p>""",
530
+ "options": [
531
+ { "text": "Take the map showing the secret tunnel entrance", "next": 5, "addItem": "Secret Tunnel Map" },
532
+ { "text": "Accept the poison-tipped daggers for stealth", "next": 5, "addItem": "Poison Daggers" },
533
+ { "text": "Choose the master key that unlocks ancient doors", "next": 5, "addItem": "Master Key" }
534
+ ],
535
+ "illustration": "resistance-meeting"
536
+ },
537
+
538
+ "5": {
539
+ "title": "The Journey Begins",
540
+ "content": """<p>Prepared as best you can be, you leave Silverhold behind. The path to the Evil Power Master's fortress takes you through the Shadowwood Forest, a place once beautiful but now corrupted by dark magic.</p>
541
+ <p>Strange sounds echo among the twisted trees, and the feeling of being watched raises the hair on your neck. The main road is the fastest route, but there are alternatives.</p>""",
542
+ "options": [
543
+ { "text": "Take the main road through the forest", "next": 6 },
544
+ { "text": "Follow the winding river path", "next": 7 },
545
+ { "text": "Brave the ancient ruins shortcut", "next": 8 }
546
+ ],
547
+ "randomBattle": True,
548
+ "illustration": "shadowwood-forest"
549
+ },
550
+
551
+ "6": {
552
+ "title": "Ambush on the Road",
553
+ "content": """<p>The main road through Shadowwood is overgrown but still visible. As you make your way forward, the trees suddenly rustle with movement.</p>
554
+ <p>A group of the Evil Power Master's scouts emerges from hiding! They've been patrolling the road, looking for those who might oppose their master.</p>
555
+ <p>"Surrender now," their leader snarls, "or face the consequences!"</p>""",
556
+ "challenge": {
557
+ "title": "Escape the Ambush",
558
+ "description": "You need to either fight your way through or find an escape route.",
559
+ "stat": "courage",
560
+ "difficulty": 5,
561
+ "success": 9,
562
+ "failure": 10
563
+ },
564
+ "illustration": "road-ambush"
565
+ },
566
+
567
+ "7": {
568
+ "title": "The Mist-Shrouded River",
569
+ "content": """<p>The river path is longer but less traveled. Thick mist clings to the water's surface, reducing visibility but potentially hiding you from enemies.</p>
570
+ <p>As you follow the winding shore, you notice strange glowing lights beneath the water's surface. Suddenly, the mist parts to reveal a mysterious figure standing on the water itself.</p>
571
+ <p>"Few choose this path," the figure says in a melodic voice. "To proceed, you must answer my riddle."</p>""",
572
+ "challenge": {
573
+ "title": "The River Spirit's Riddle",
574
+ "description": "Answer correctly to gain passage and a blessing. Answer wrongly and face the river's peril.",
575
+ "stat": "wisdom",
576
+ "difficulty": 6,
577
+ "success": 11,
578
+ "failure": 12
579
+ },
580
+ "illustration": "river-spirit"
581
+ },
582
+
583
+ "8": {
584
+ "title": "The Forgotten Ruins",
585
+ "content": """<p>The ancient ruins rise from the forest floor like the bones of a forgotten civilization. Moss-covered stones and crumbling arches create a labyrinth of passages and dead ends.</p>
586
+ <p>This path is the shortest route to the fortress, but the ruins are said to be haunted by the spirits of those who built this place long ago.</p>
587
+ <p>As you enter the heart of the ruins, the temperature drops dramatically, and whispers echo through the stone corridors.</p>""",
588
+ "challenge": {
589
+ "title": "Navigate the Haunted Ruins",
590
+ "description": "Find the correct path through the ruins while avoiding the malevolent spirits.",
591
+ "stat": "wisdom",
592
+ "difficulty": 5,
593
+ "success": 13,
594
+ "failure": 14
595
+ },
596
+ "illustration": "ancient-ruins"
597
+ },
598
+
599
+ "9": {
600
+ "title": "Breaking Through",
601
+ "content": """<p>With courage and quick thinking, you manage to fight your way through the ambush. Several scouts fall to your attacks, and the rest scatter into the forest.</p>
602
+ <p>Though you've escaped, the commotion may have alerted other enemies in the area. You need to move quickly before reinforcements arrive.</p>
603
+ <p>Ahead, the forest begins to thin, revealing the barren lands that surround the Evil Power Master's fortress.</p>""",
604
+ "options": [
605
+ { "text": "Rush across the open ground to the fortress", "next": 15 },
606
+ { "text": "Wait for nightfall before crossing", "next": 16 },
607
+ { "text": "Search for underground passages", "next": 17 }
608
+ ],
609
+ "randomBattle": True,
610
+ "illustration": "forest-edge"
611
+ },
612
+
613
+ "10": {
614
+ "title": "Captured!",
615
+ "content": """<p>Despite your best efforts, the scouts overwhelm you. Disarmed and bound, you're dragged through the forest to a small outpost.</p>
616
+ <p>"The Master will be pleased," the leader laughs. "He always enjoys interrogating those who think they can stand against him."</p>
617
+ <p>As night falls, you're locked in a crude cell. All seems lost, but one guard looks at you with sympathy when the others aren't watching.</p>""",
618
+ "options": [
619
+ { "text": "Try to escape during the night", "next": 18 },
620
+ { "text": "Appeal to the sympathetic guard", "next": 19 },
621
+ { "text": "Wait for transport to the fortress", "next": 20 }
622
+ ],
623
+ "hpLoss": 5,
624
+ "illustration": "prisoner-cell"
625
+ },
626
+
627
+ "11": {
628
+ "title": "The Spirit's Blessing",
629
+ "content": """<p>"Wisdom flows in you like the river itself," the spirit says, impressed by your answer. The mist swirls around you, and you feel a surge of energy.</p>
630
+ <p>"Take my blessing. The waters will aid you against the darkness." The spirit touches your forehead, and a cool sensation spreads through your body.</p>
631
+ <p>The mist parts, revealing a clear path forward and the distant silhouette of the Evil Power Master's fortress.</p>""",
632
+ "options": [
633
+ { "text": "Continue to the barren plains", "next": 15 },
634
+ { "text": "Ask the spirit for more information", "next": 16 },
635
+ { "text": "Follow the underwater passage the spirit reveals", "next": 17 }
636
+ ],
637
+ "addItem": "Water Spirit's Blessing",
638
+ "statIncrease": { "stat": "wisdom", "amount": 2 },
639
+ "illustration": "spirit-blessing"
640
+ },
641
+
642
+ "12": {
643
+ "title": "The Spirit's Wrath",
644
+ "content": """<p>"Incorrect," the spirit hisses, its melodic voice turning harsh. "The river does not suffer fools!"</p>
645
+ <p>The mist thickens around you, and the calm water suddenly churns. A powerful current grabs your legs, pulling you into the depths.</p>
646
+ <p>You struggle against the supernatural force, barely managing to break free and scramble onto the shore, soaked and battered.</p>""",
647
+ "options": [
648
+ { "text": "Continue along the riverbank", "next": 15 },
649
+ { "text": "Find another path through the forest", "next": 16 },
650
+ { "text": "Rest and recover before moving on", "next": 17 }
651
+ ],
652
+ "hpLoss": 8,
653
+ "illustration": "river-danger"
654
+ },
655
+
656
+ "13": {
657
+ "title": "Ancient Allies",
658
+ "content": """<p>Your wisdom guides you through the ruins' labyrinth. As you navigate the crumbling corridors, the whispers change from threatening to curious.</p>
659
+ <p>In the central chamber, transparent figures materialize - the ancient spirits of this place. They were not malevolent but protective, testing those who pass through.</p>
660
+ <p>"You have shown respect and intelligence," their leader says. "We too oppose the darkness that has corrupted our land."</p>""",
661
+ "options": [
662
+ { "text": "Accept their offer of a magical artifact", "next": 15, "addItem": "Ancient Amulet" },
663
+ { "text": "Ask for knowledge about the fortress", "next": 16 },
664
+ { "text": "Request they guide you through secret paths", "next": 17 }
665
+ ],
666
+ "illustration": "ancient-spirits"
667
+ },
668
+
669
+ "14": {
670
+ "title": "Lost in Time",
671
+ "content": """<p>The ruins become an impossible maze. Each turn leads to unfamiliar passages, and the whispers grow louder, disorienting you further.</p>
672
+ <p>Hours pass as you wander, and malevolent spirits tug at your life force. By the time you finally stumble out of the ruins, you're exhausted and drained.</p>
673
+ <p>Worse, you've emerged far from your intended path, and valuable time has been lost.</p>""",
674
+ "options": [
675
+ { "text": "Rest to recover your strength", "next": 15 },
676
+ { "text": "Push on despite your exhaustion", "next": 16 },
677
+ { "text": "Find a local guide in a nearby village", "next": 17 }
678
+ ],
679
+ "hpLoss": 10,
680
+ "illustration": "lost-ruins"
681
+ },
682
+
683
+ "15": {
684
+ "title": "The Looming Fortress",
685
+ "content": """<p>The Evil Power Master's fortress dominates the landscape - a massive structure of black stone with towers that seem to pierce the clouds.</p>
686
+ <p>Lightning crackles around its highest spires, and dark shapes patrol the battlements. The main gate is heavily guarded, but there must be other ways in.</p>
687
+ <p>As you survey the imposing structure, you consider your options for infiltration.</p>""",
688
+ "options": [
689
+ { "text": "Approach the main gate in disguise", "next": 21 },
690
+ { "text": "Scale the outer wall under cover of darkness", "next": 22 },
691
+ { "text": "Look for the secret tunnel (requires Secret Tunnel Map)", "next": 23, "requireItem": "Secret Tunnel Map" }
692
+ ],
693
+ "alternativeOption": { "text": "Search for another entrance", "next": 21, "showIf": ["Secret Tunnel Map"] },
694
+ "illustration": "evil-fortress"
695
+ },
696
+
697
+ "16": {
698
+ "title": "Strategic Approach",
699
+ "content": """<p>You take time to observe the fortress from a distance. Patrols move in predictable patterns, and supply wagons come and go at regular intervals.</p>
700
+ <p>As night falls, different sections of the fortress light up, revealing potential weaknesses in security. Your careful observation provides valuable insights.</p>
701
+ <p>You identify several possible entry points, each with its own risks and advantages.</p>""",
702
+ "options": [
703
+ { "text": "Infiltrate with an incoming supply wagon", "next": 21 },
704
+ { "text": "Use magic to create a distraction (requires any spell)", "next": 22, "requireAnyItem": ["Healing Light Spell", "Shield of Faith Spell", "Binding Runes Scroll", "Water Spirit's Blessing"] },
705
+ { "text": "Bribe a guard to let you in (requires special item)", "next": 23, "requireAnyItem": ["Ancient Amulet", "Poison Daggers", "Master Key"] }
706
+ ],
707
+ "alternativeOption": { "text": "Wait for another opportunity", "next": 21, "showIf": ["Healing Light Spell", "Shield of Faith Spell", "Binding Runes Scroll", "Water Spirit's Blessing", "Ancient Amulet", "Poison Daggers", "Master Key"] },
708
+ "illustration": "fortress-observation"
709
+ },
710
+
711
+ "17": {
712
+ "title": "The Hidden Way",
713
+ "content": """<p>Your search reveals an unexpected approach to the fortress - an ancient maintenance tunnel that runs beneath the barren plains, likely forgotten by the Evil Power Master.</p>
714
+ <p>The tunnel is old and could be unstable, but it would allow you to bypass most of the outer defenses entirely.</p>
715
+ <p>As you consider this option, you hear patrol horns in the distance - they're sweeping the area for intruders.</p>""",
716
+ "options": [
717
+ { "text": "Enter the tunnel immediately", "next": 24 },
718
+ { "text": "Hide and wait for the patrol to pass", "next": 21 },
719
+ { "text": "Set a trap for the patrol", "next": 22 }
720
+ ],
721
+ "illustration": "hidden-tunnel"
722
+ },
723
+
724
+ "18": {
725
+ "title": "Night Escape",
726
+ "content": """<p>You wait until the dead of night, when most guards are dozing at their posts. Using a loose stone you discovered in your cell, you work on the rusted lock.</p>
727
+ <p>With a satisfying click, the cell door unlocks. Moving silently through the shadows, you retrieve your confiscated equipment from a nearby storeroom.</p>
728
+ <p>Now you must leave the outpost without raising the alarm.</p>""",
729
+ "challenge": {
730
+ "title": "Stealthy Escape",
731
+ "description": "Slip past the sleeping guards without alerting them.",
732
+ "stat": "wisdom",
733
+ "difficulty": 6,
734
+ "success": 16,
735
+ "failure": 10
736
+ },
737
+ "illustration": "night-escape"
738
+ },
739
+
740
+ "19": {
741
+ "title": "Unexpected Ally",
742
+ "content": """<p>When the guard passes your cell alone, you whisper, asking why they seemed sympathetic. The guard looks around nervously before responding.</p>
743
+ <p>"My village was enslaved by the Evil Power Master. My family serves him under threat of death, but many of us secretly hope for his downfall."</p>
744
+ <p>The guard offers to help you escape, but warns there will be a price for this betrayal if discovered.</p>""",
745
+ "options": [
746
+ { "text": "Accept the guard's help", "next": 16 },
747
+ { "text": "Decline - you don't want to put them at risk", "next": 18 },
748
+ { "text": "Convince them to join your cause", "next": 20 }
749
+ ],
750
+ "addItem": "Guard Disguise",
751
+ "illustration": "guard-ally"
752
+ },
753
+
754
+ "20": {
755
+ "title": "Journey to the Fortress",
756
+ "content": """<p>At dawn, you're bound and loaded onto a prison wagon with other captured travelers. The journey to the fortress is uncomfortable, but you use the time to observe and plan.</p>
757
+ <p>The other prisoners share what they know about the fortress. One mentions rumors of a resistance operating within the Evil Power Master's ranks.</p>
758
+ <p>As the wagon approaches the massive gates, you begin to formulate a plan.</p>""",
759
+ "options": [
760
+ { "text": "Look for an opportunity to escape during transfer", "next": 21 },
761
+ { "text": "Remain captive to get inside, then escape", "next": 22 },
762
+ { "text": "Try to contact the internal resistance", "next": 23 }
763
+ ],
764
+ "illustration": "prison-wagon"
765
+ },
766
+
767
+ "21": {
768
+ "title": "Infiltration",
769
+ "content": """<p>Using your skills and preparation, you manage to infiltrate the outer perimeter of the fortress. The black stone walls loom overhead, even more intimidating up close.</p>
770
+ <p>Guards patrol in pairs, and magical wards pulse with dark energy. You'll need to be extremely careful as you navigate deeper into enemy territory.</p>
771
+ <p>The sound of a bell signals a shift change, providing a momentary distraction.</p>""",
772
+ "options": [
773
+ { "text": "Head towards the central tower", "next": 25 },
774
+ { "text": "Search for the dungeons", "next": 26 },
775
+ { "text": "Follow a group of mages", "next": 27 }
776
+ ],
777
+ "randomBattle": true,
778
+ "illustration": "fortress-interior"
779
+ },
780
+
781
+ "22": {
782
+ "title": "Discovered!",
783
+ "content": """<p>As you make your way through the fortress, an alarm suddenly sounds! Your presence has been detected, and you hear the heavy footsteps of guards approaching.</p>
784
+ <p>"Intruder in the south corridor!" a voice shouts. "Seal all exits!"</p>
785
+ <p>You have moments to react before you're surrounded.</p>""",
786
+ "challenge": {
787
+ "title": "Escape Detection",
788
+ "description": "You need to escape from the approaching guards before they trap you.",
789
+ "stat": "courage",
790
+ "difficulty": 7,
791
+ "success": 25,
792
+ "failure": 28
793
+ },
794
+ "illustration": "fortress-alarm"
795
+ },
796
+
797
+ "23": {
798
+ "title": "Secret Resistance",
799
+ "content": """<p>Through luck or skill, you make contact with members of the secret resistance operating within the fortress. They're skeptical of you at first, but your actions have convinced them of your intentions.</p>
800
+ <p>"We've been working to undermine the Evil Power Master for years," their leader whispers. "Now with your help, we might finally have a chance to end his reign."</p>
801
+ <p>They share crucial information about the fortress layout and the Evil Power Master's weaknesses.</p>""",
802
+ "options": [
803
+ { "text": "Join their planned uprising", "next": 29 },
804
+ { "text": "Ask them to help you reach the Power Master directly", "next": 30 },
805
+ { "text": "Share your knowledge with them", "next": 31 }
806
+ ],
807
+ "illustration": "secret-meeting"
808
+ },
809
+
810
+ "24": {
811
+ "title": "Underground Passage",
812
+ "content": """<p>The ancient tunnel is damp and narrow, forcing you to crouch as you make your way forward. Roots hang from the ceiling, and the air feels thick with age.</p>
813
+ <p>After what seems like hours of careful navigation, you notice light ahead. The tunnel opens into what appears to be a forgotten storeroom beneath the fortress.</p>
814
+ <p>Dust covers everything, but you can hear movement in the rooms above.</p>""",
815
+ "options": [
816
+ { "text": "Explore the storeroom for useful items", "next": 32 },
817
+ { "text": "Find a way up to the main fortress", "next": 33 },
818
+ { "text": "Listen carefully to determine what's happening above", "next": 34 }
819
+ ],
820
+ "illustration": "underground-passage"
821
+ },
822
+
823
+ "25": {
824
+ "title": "The Central Tower",
825
+ "content": """<p>The central tower rises from the heart of the fortress like a black spear. As you get closer, you can feel powerful magic emanating from its peak.</p>
826
+ <p>Guards are more numerous here, and you spot several dark mages performing rituals in alcoves along the walls. Whatever the Evil Power Master is planning, it seems to be approaching its climax.</p>
827
+ <p>A massive door blocks the entrance to the tower, engraved with strange symbols.</p>""",
828
+ "options": [
829
+ { "text": "Try to decipher the symbols", "next": 35 },
830
+ { "text": "Look for another entrance", "next": 36 },
831
+ { "text": "Use magic to open the door (requires any spell)", "next": 37, "requireAnyItem": ["Healing Light Spell", "Shield of Faith Spell", "Binding Runes Scroll", "Water Spirit's Blessing"] }
832
+ ],
833
+ "alternativeOption": { "text": "Wait and observe the mages", "next": 36, "showIf": ["Healing Light Spell", "Shield of Faith Spell", "Binding Runes Scroll", "Water Spirit's Blessing"] },
834
+ "illustration": "central-tower"
835
+ },
836
+
837
+ "26": {
838
+ "title": "The Dungeons",
839
+ "content": """<p>The dungeons are a maze of dark, damp corridors lined with cells. Moans and whispers echo off the stone walls, creating an eerie atmosphere of despair.</p>
840
+ <p>Many of the cells contain prisoners - ordinary people from villages conquered by the Evil Power Master, resistance fighters, and even a few magical creatures.</p>
841
+ <p>At the end of one corridor, you spot a heavily guarded cell that seems more important than the others.</p>""",
842
+ "options": [
843
+ { "text": "Try to free some prisoners to cause a distraction", "next": 38 },
844
+ { "text": "Investigate the heavily guarded cell", "next": 39 },
845
+ { "text": "Look for a passage leading upward", "next": 40 }
846
+ ],
847
+ "illustration": "dungeon-corridors"
848
+ },
849
+
850
+ "27": {
851
+ "title": "The Ritual Chamber",
852
+ "content": """<p>Following the group of mages leads you to a large circular chamber. Hidden in the shadows, you observe as they prepare for what appears to be an important ritual.</p>
853
+ <p>In the center of the room hovers a dark crystal, pulsing with malevolent energy. The mages arrange themselves around it, beginning a chant in an ancient language.</p>
854
+ <p>"Soon the master's power will be unstoppable," one of them mutters. "The alignment is nearly perfect."</p>""",
855
+ "options": [
856
+ { "text": "Disrupt the ritual", "next": 41 },
857
+ { "text": "Quietly observe to learn more", "next": 42 },
858
+ { "text": "Steal the crystal when they're distracted", "next": 43 }
859
+ ],
860
+ "illustration": "ritual-chamber"
861
+ },
862
+
863
+ "28": {
864
+ "title": "Captured Again",
865
+ "content": """<p>The guards overwhelm you, and this time, there's no easy escape. You're brought before a high-ranking officer, who smiles coldly.</p>
866
+ <p>"The Master will be most pleased," he says. "He so rarely gets to meet those foolish enough to challenge him directly."</p>
867
+ <p>You're escorted under heavy guard toward the central tower, where the Evil Power Master awaits.</p>""",
868
+ "options": [
869
+ { "text": "Look for another chance to escape", "next": 44 },
870
+ { "text": "Prepare yourself mentally to face the Power Master", "next": 45 },
871
+ { "text": "Try to gather information from the guards", "next": 46 }
872
+ ],
873
+ "illustration": "prisoner-escort"
874
+ },
875
+
876
+ "29": {
877
+ "title": "The Uprising",
878
+ "content": """<p>The resistance has planned carefully. When the signal is given, chaos erupts throughout the fortress. Guards find themselves fighting servants, and magical wards fail as saboteurs destroy key components.</p>
879
+ <p>In the confusion, you and a small team of resistance fighters make your way toward the central tower where the Evil Power Master resides.</p>
880
+ <p>"This is our only chance," the resistance leader whispers. "We must reach him before he realizes what's happening."</p>""",
881
+ "options": [
882
+ { "text": "Lead the charge directly", "next": 47 },
883
+ { "text": "Split up to create more distractions", "next": 48 },
884
+ { "text": "Sneak ahead while the others draw attention", "next": 49 }
885
+ ],
886
+ "illustration": "fortress-uprising"
887
+ },
888
+
889
+ "30": {
890
+ "title": "The Final Approach",
891
+ "content": """<p>With the resistance's help, you navigate through secret passages unknown to most of the fortress inhabitants. These narrow corridors, built during the fortress's construction, lead directly to the upper levels.</p>
892
+ <p>"The Power Master's chambers are at the top of the central tower," your guide explains. "He rarely leaves them these days, too focused on some grand ritual. This may be our only chance to stop him."</p>
893
+ <p>The passage ends at a hidden door, beyond which lies the base of the central tower.</p>""",
894
+ "options": [
895
+ { "text": "Enter the tower cautiously", "next": 50 },
896
+ { "text": "Ask about the ritual the Power Master is performing", "next": 51 },
897
+ { "text": "Request additional help for the final confrontation", "next": 52 }
898
+ ],
899
+ "illustration": "secret-passage"
900
+ },
901
+
902
+ "31": {
903
+ "title": "Knowledge Exchange",
904
+ "content": """<p>You share everything you've learned on your journey - about the river spirit, the ancient ruins, and any magical artifacts you've collected. In return, the resistance provides crucial information.</p>
905
+ <p>"The Evil Power Master draws his power from an ancient crystal," their sage explains. "It amplifies his natural abilities tenfold, but it's also a weakness. Destroy the crystal, and his power will be greatly diminished."</p>
906
+ <p>They also reveal that the Power Master is preparing for a cosmic alignment that will make him virtually unstoppable.</p>""",
907
+ "options": [
908
+ { "text": "Ask how to locate the crystal", "next": 53 },
909
+ { "text": "Find out when the alignment will occur", "next": 54 },
910
+ { "text": "Learn if there are any weapons that can harm the crystal", "next": 55 }
911
+ ],
912
+ "illustration": "knowledge-sharing"
913
+ },
914
+
915
+ "48": {
916
+ "title": "The Final Confrontation",
917
+ "content": """<p>At last, you stand before the Evil Power Master in his chamber at the top of the central tower. Dark energy crackles around him as he turns to face you, his eyes gleaming with malice.</p>
918
+ <p>"So, you're the one who's caused so much trouble," he says, his voice echoing with unnatural power. "I must admit, I'm impressed you made it this far. But your journey ends here."</p>
919
+ <p>The dark crystal hovers behind him, pulsing with energy. This is the moment all your choices have led to.</p>""",
920
+ "options": [
921
+ { "text": "Attack the Evil Power Master directly", "next": 56 },
922
+ { "text": "Try to destroy the crystal", "next": 57 },
923
+ { "text": "Attempt to reason with him", "next": 58 }
924
+ ],
925
+ "illustration": "final-confrontation"
926
+ },
927
+
928
+ "56": {
929
+ "title": "Direct Confrontation",
930
+ "content": """<p>You charge at the Evil Power Master, drawing on all your courage and strength. He meets your attack with dark magic, the air between you distorting with energy.</p>
931
+ <p>The battle is intense, pushing you to your limits. Each blow you land seems to be absorbed by his power, while his attacks grow increasingly dangerous.</p>
932
+ <p>As the fight continues, you realize that as long as the crystal empowers him, this might be an unwinnable battle.</p>""",
933
+ "challenge": {
934
+ "title": "Battle with the Evil Power Master",
935
+ "description": "You must overcome his dark magic through sheer determination and skill.",
936
+ "stat": "strength",
937
+ "difficulty": 9,
938
+ "success": 59,
939
+ "failure": 60
940
+ },
941
+ "illustration": "power-battle"
942
+ },
943
+
944
+ "57": {
945
+ "title": "Crystal Destruction",
946
+ "content": """<p>Recognizing the true source of his power, you ignore the Evil Power Master and lunge toward the floating crystal. He shouts in alarm, desperately trying to stop you.</p>
947
+ <p>"No! Stay away from that, you fool! You have no idea what forces you're tampering with!"</p>
948
+ <p>As you get closer to the crystal, its energy intensifies, creating a barrier of dark magic that you must break through.</p>""",
949
+ "challenge": {
950
+ "title": "Breaking the Crystal Barrier",
951
+ "description": "You must overcome the crystal's protective magic to reach and destroy it.",
952
+ "stat": "wisdom",
953
+ "difficulty": 8,
954
+ "success": 61,
955
+ "failure": 62
956
+ },
957
+ "illustration": "crystal-barrier"
958
+ },
959
+
960
+ "59": {
961
+ "title": "A Hero's Victory",
962
+ "content": """<p>Through sheer determination and skill, you manage to overcome the Evil Power Master's defenses. As he staggers backwards from your decisive blow, his connection to the crystal weakens momentarily.</p>
963
+ <p>Seizing the opportunity, you strike the crystal with all your remaining strength. It cracks, then shatters in a blinding flash of light and energy.</p>
964
+ <p>The Evil Power Master screams as his power dissipates. "Impossible! I was so close to ultimate power!"</p>
965
+ <p>As the light fades, you stand victorious. The land will heal from his corruption, and the people are free once more.</p>""",
966
+ "gameOver": true,
967
+ "ending": "You've defeated the Evil Power Master and destroyed the source of his power. Songs will be sung of your bravery for generations to come. The land begins to heal, and you are hailed as a hero throughout the realm.",
968
+ "illustration": "hero-victory"
969
+ },
970
+
971
+ "60": {
972
+ "title": "Darkness Prevails",
973
+ "content": """<p>Despite your best efforts, the Evil Power Master's power is too great. His dark magic overwhelms your defenses, bringing you to your knees.</p>
974
+ <p>"Valiant, but futile," he says, looking down at you. "You could have joined me, you know. Now you'll witness my ascension to godhood before your end."</p>
975
+ <p>As your vision fades, you see the crystal's glow intensifying. You've failed, and darkness will soon cover the land.</p>""",
976
+ "gameOver": true,
977
+ "ending": "The Evil Power Master was too powerful, and your quest ends in defeat. Darkness spreads across the land as he completes his ritual and ascends to even greater power. Perhaps another hero will rise in the future to challenge his reign.",
978
+ "illustration": "dark-victory"
979
+ },
980
+
981
+ "61": {
982
+ "title": "The Crystal Shatters",
983
+ "content": """<p>Drawing on all your wisdom and willpower, you break through the crystal's barrier. Reaching out, you touch its surface, which burns cold against your skin.</p>
984
+ <p>The Evil Power Master shrieks in desperation, "Stop! You'll doom us all!"</p>
985
+ <p>With a final effort, you channel your energy into the crystal. Cracks appear across its surface, spreading rapidly until it shatters with a deafening explosion of light and sound.</p>
986
+ <p>When your vision clears, the Evil Power Master lies defeated, his power broken along with the crystal. Peace can now return to the land.</p>""",
987
+ "gameOver": true,
988
+ "ending": "By destroying the source of the Evil Power Master's strength, you've saved the realm from his tyranny. The fortress begins to crumble as its dark magic fades, but you escape to tell the tale. Your name becomes legend throughout the land.",
989
+ "illustration": "crystal-destroyed"
990
+ },
991
+
992
+ "62": {
993
+ "title": "A Desperate Gambit",
994
+ "content": """<p>The crystal's barrier proves too strong, repelling your attempts to break through. As you struggle against it, the Evil Power Master regains his composure and approaches.</p>
995
+ <p>"Did you really think it would be that easy?" he mocks. "The crystal has existed for millennia. It cannot be destroyed by someone like you."</p>
996
+ <p>In a final, desperate move, you use all your remaining strength to hurl your most powerful weapon or spell at the crystal.</p>
997
+ <p>To your surprise and the Evil Power Master's horror, this creates a resonance effect. The crystal begins to vibrate violently, its energy becoming unstable.</p>
998
+ <p>"What have you done?" he cries as the crystal's energy spirals out of control, engulfing both of you in blinding light.</p>""",
999
+ "gameOver": true,
1000
+ "ending": "Your desperate attack destabilized the crystal, causing a catastrophic release of energy that destroyed the Evil Power Master and his fortress. Though you didn't survive, your sacrifice saved the realm from darkness. Bards sing of your heroism for generations to come.",
1001
+ "illustration": "heroic-sacrifice"
1002
+ }
1003
+ }
1004
+
1005
+ # SVG templates for illustrations
1006
+ illustrations = {
1007
+ "city-gates": """
1008
+ <svg viewBox="0 0 400 250" xmlns="http://www.w3.org/2000/svg">
1009
+ <!-- Sky -->
1010
+ <rect x="0" y="0" width="400" height="150" fill="#6b88a2" />
1011
+
1012
+ <!-- Ground -->
1013
+ <rect x="0" y="150" width="400" height="100" fill="#7d6c54" />
1014
+
1015
+ <!-- City walls -->
1016
+ <rect x="50" y="50" width="300" height="100" fill="#c9c0a8" />
1017
+
1018
+ <!-- Gate -->
1019
+ <rect x="150" y="80" width="100" height="120" fill="#5a3c28" />
1020
+ <rect x="195" y="80" width="10" height="120" fill="#3a281e" />
1021
+
1022
+ <!-- Towers -->
1023
+ <rect x="50" y="30" width="40" height="120" fill="#d6cdb7" />
1024
+ <rect x="310" y="30" width="40" height="120" fill="#d6cdb7" />
1025
+
1026
+ <!-- Tower tops -->
1027
+ <polygon points="50,30 70,10 90,30" fill="#bf9969" />
1028
+ <polygon points="310,30 330,10 350,30" fill="#bf9969" />
1029
+
1030
+ <!-- Path -->
1031
+ <path d="M150,250 L250,250 L250,200 L150,200 Z" fill="#a89783" />
1032
+
1033
+ <!-- Flags -->
1034
+ <rect x="70" y="10" width="2" height="20" fill="#222" />
1035
+ <rect x="72" y="10" width="10" height="5" fill="#bf2121" />
1036
+ <rect x="330" y="10" width="2" height="20" fill="#222" />
1037
+ <rect x="332" y="10" width="10" height="5" fill="#bf2121" />
1038
+ </svg>
1039
+ """,
1040
+ "weaponsmith": """
1041
+ <svg viewBox="0 0 400 250" xmlns="http://www.w3.org/2000/svg">
1042
+ <!-- Background -->
1043
+ <rect x="0" y="0" width="400" height="250" fill="#3d3123" />
1044
+
1045
+ <!-- Forge -->
1046
+ <rect x="250" y="100" width="100" height="70" fill="#8c5b3f" />
1047
+ <rect x="270" y="120" width="60" height="30" fill="#e63d16" />
1048
+ <ellipse cx="300" cy="135" rx="25" ry="10" fill="#f7d046" />
1049
+
1050
+ <!-- Anvil -->
1051
+ <rect x="180" y="160" width="40" height="20" fill="#888888" />
1052
+ <rect x="190" y="150" width="20" height="10" fill="#999999" />
1053
+ <rect x="195" y="140" width="10" height="10" fill="#aaaaaa" />
1054
+
1055
+ <!-- Weapons on wall -->
1056
+ <line x1="50" y1="60" x2="90" y2="70" stroke="#c0c0c0" stroke-width="4" />
1057
+ <line x1="120" y1="50" x2="150" y2="70" stroke="#c0c0c0" stroke-width="3" />
1058
+ <rect x="60" y="90" width="30" height="80" fill="#814d2b" />
1059
+ <rect x="65" y="90" width="20" height="5" fill="#c0c0c0" />
1060
+ <rect x="140" y="90" width="5" height="100" fill="#814d2b" />
1061
+ <ellipse cx="142.5" cy="90" rx="15" ry="3" fill="#c0c0c0" />
1062
+
1063
+ <!-- Table -->
1064
+ <rect x="30" y="180" width="120" height="10" fill="#8c5b3f" />
1065
+
1066
+ <!-- Weaponsmith -->
1067
+ <circle cx="220" cy="120" r="25" fill="#d8a77a" />
1068
+ <rect x="210" y="145" width="20" height="35" fill="#603813" />
1069
+ <rect x="205" y="110" width="30" height="20" fill="#d8a77a" />
1070
+ <circle cx="213" cy="115" r="3" fill="#000" />
1071
+ <circle cx="227" cy="115" r="3" fill="#000" />
1072
+ <path d="M215,125 Q220,130 225,125" fill="none" stroke="#000" stroke-width="1" />
1073
+
1074
+ <!-- Special weapons -->
1075
+ <rect x="60" y="60" width="10" height="30" fill="#603813" />
1076
+ <rect x="62" y="30" width="6" height="30" fill="#ff5722" opacity="0.7">
1077
+ <animate attributeName="opacity" values="0.7;1;0.7" dur="2s" repeatCount="indefinite" />
1078
+ </rect>
1079
+
1080
+ <rect x="130" y="50" width="6" height="40" fill="#603813" />
1081
+ <ellipse cx="133" cy="50"