about summary refs log tree commit diff stats
path: root/html
diff options
context:
space:
mode:
Diffstat (limited to 'html')
-rw-r--r--html/story-teller/index.html13
-rw-r--r--html/story-teller/js/game.js47
-rw-r--r--html/story-teller/js/renderer.js44
-rw-r--r--html/story-teller/js/scenes.js37
-rw-r--r--html/story-teller/js/state.js43
-rw-r--r--html/story-teller/styles.css8
6 files changed, 192 insertions, 0 deletions
diff --git a/html/story-teller/index.html b/html/story-teller/index.html
new file mode 100644
index 0000000..edd44c2
--- /dev/null
+++ b/html/story-teller/index.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Choice-based Game</title>
+  <link rel="stylesheet" href="./styles.css">
+</head>
+<body>
+  <div id="app"></div>
+  <script type="module" src="./js/game.js"></script>
+</body>
+</html>
diff --git a/html/story-teller/js/game.js b/html/story-teller/js/game.js
new file mode 100644
index 0000000..d3e8144
--- /dev/null
+++ b/html/story-teller/js/game.js
@@ -0,0 +1,47 @@
+import { createGameState, saveGameState, loadGameState, resetGameState } from './state.js';
+import { renderScene } from './renderer.js';
+
+let gameState = loadGameState(); // Load state on initialization
+
+const updateAndRender = (newState) => {
+  Object.assign(gameState, newState);
+  saveGameState(gameState); // Save automatically after each update
+  renderScene(gameState, updateAndRender);
+};
+
+document.addEventListener('DOMContentLoaded', () => {
+  const app = document.getElementById('app');
+
+  app.innerHTML = '';
+
+  const controls = document.createElement('div');
+  controls.id = 'controls';
+
+  const saveButton = document.createElement('button');
+  saveButton.textContent = 'Save Progress';
+  saveButton.onclick = () => saveGameState(gameState);
+
+  const loadButton = document.createElement('button');
+  loadButton.textContent = 'Load Progress';
+  loadButton.onclick = () => {
+    const loadedState = loadGameState();
+    updateAndRender(loadedState);
+  };
+
+  const resetButton = document.createElement('button');
+  resetButton.textContent = 'Reset Game';
+  resetButton.onclick = () => {
+    if (confirm('Are you sure you want to reset the game? This will erase all progress.')) {
+      gameState = resetGameState(); // Clear state and reset game
+      updateAndRender(gameState);
+    }
+  };
+
+  controls.appendChild(saveButton);
+  controls.appendChild(loadButton);
+  controls.appendChild(resetButton);
+
+  app.appendChild(controls);
+
+  updateAndRender(gameState);
+});
diff --git a/html/story-teller/js/renderer.js b/html/story-teller/js/renderer.js
new file mode 100644
index 0000000..82ab004
--- /dev/null
+++ b/html/story-teller/js/renderer.js
@@ -0,0 +1,44 @@
+import { scenes } from './scenes.js';
+
+export const renderScene = (state, updateState) => {
+  const scene = scenes[state.currentScene];
+  if (!scene) throw new Error(`Scene "${state.currentScene}" not found`);
+
+  const app = document.getElementById('app');
+  app.innerHTML = '';
+
+  const description = document.createElement('p');
+  description.textContent = scene.description;
+  app.appendChild(description);
+
+  const inventory = document.createElement('div');
+  inventory.textContent = `Inventory: ${Array.from(state.inventory).join(', ') || 'None'}`;
+  app.appendChild(inventory);
+
+  const log = document.createElement('div');
+  log.innerHTML = `<strong>Action Log:</strong><br>${state.actionLog.join('<br>')}`;
+  app.appendChild(log);
+
+  scene.choices.forEach((choice) => {
+    if (choice.condition && !choice.condition(state)) {
+      return; // Skip choices that don't meet their conditions
+    }
+
+    const button = document.createElement('button');
+    button.textContent = choice.text;
+    button.onclick = () => {
+      state.actionLog.push(`You chose: "${choice.text}"`);
+      if (choice.action) choice.action(state); // Perform any action tied to the choice
+
+      // Consume items if specified
+      if (choice.consume) {
+        choice.consume.forEach((item) => state.inventory.delete(item));
+        state.actionLog.push(`You used: ${choice.consume.join(', ')}`);
+      }
+
+      if (choice.nextScene) state.currentScene = choice.nextScene;
+      updateState(state); // Re-render after state update
+    };
+    app.appendChild(button);
+  });
+};
diff --git a/html/story-teller/js/scenes.js b/html/story-teller/js/scenes.js
new file mode 100644
index 0000000..7b8db35
--- /dev/null
+++ b/html/story-teller/js/scenes.js
@@ -0,0 +1,37 @@
+export const scenes = {
+    start: {
+      description: "You are standing in a dark cave. There's a faint glimmer in the distance, and a torch on the ground.",
+      choices: [
+        { text: "Explore further", nextScene: "deepCave" },
+        { text: "Pick up the torch", action: (state) => state.inventory.add("torch") },
+        { 
+          text: "Use a torch to illuminate the cave", 
+          nextScene: "litCave", 
+          condition: (state) => state.inventory.has("torch"), 
+          consume: ["torch"] 
+        },
+      ],
+    },
+    deepCave: {
+      description: "The darkness becomes overwhelming. You can't proceed further.",
+      choices: [
+        { text: "Go back", nextScene: "start" },
+      ],
+    },
+    litCave: {
+      description: "With the torchlight, you see glittering gemstones embedded in the walls.",
+      choices: [
+        { text: "Pick up the key", action: (state) => state.inventory.add("key") },
+        { text: "Collect a gemstone", action: (state) => state.inventory.add("gemstone") },
+        { text: "Go back", nextScene: "start" },
+        { text: "Go deeper into the cave", nextScene: "treasureRoom", condition: (state) => state.inventory.has("key") },
+      ],
+    },
+    treasureRoom: {
+      description: "You find a room filled with treasure. You are rich beyond your wildest dreams.",
+      choices: [
+        { text: "Swim in the treasure", nextScene: "treasureRoom" },
+      ],
+    },
+  };
+  
\ No newline at end of file
diff --git a/html/story-teller/js/state.js b/html/story-teller/js/state.js
new file mode 100644
index 0000000..e6c4fe7
--- /dev/null
+++ b/html/story-teller/js/state.js
@@ -0,0 +1,43 @@
+export const createGameState = () => ({
+    currentScene: 'start',
+    inventory: new Set(),
+    actionLog: [],
+    collectedItems: new Set(),
+  });
+  
+  
+  
+export const updateGameState = (state, updates) => ({
+    ...state,
+    ...updates,
+});
+
+const STORAGE_KEY = 'gameState';
+
+export const saveGameState = (state) => {
+  const stateToSave = {
+    currentScene: state.currentScene,
+    inventory: Array.from(state.inventory),
+    actionLog: state.actionLog,
+  };
+  localStorage.setItem(STORAGE_KEY, JSON.stringify(stateToSave));
+};
+
+export const loadGameState = () => {
+  const savedState = localStorage.getItem(STORAGE_KEY);
+  if (savedState) {
+    const parsedState = JSON.parse(savedState);
+    return {
+      currentScene: parsedState.currentScene,
+      inventory: new Set(parsedState.inventory),
+      actionLog: parsedState.actionLog,
+    };
+  }
+  return createGameState();
+};
+
+export const resetGameState = () => {
+    localStorage.removeItem(STORAGE_KEY);
+    return createGameState();
+  };
+  
\ No newline at end of file
diff --git a/html/story-teller/styles.css b/html/story-teller/styles.css
new file mode 100644
index 0000000..51852ba
--- /dev/null
+++ b/html/story-teller/styles.css
@@ -0,0 +1,8 @@
+body {
+    font-family: 'Roboto', sans-serif;
+    background-color: #f0f0f0;
+    margin: 0 auto;
+    display: block;
+    padding: 0;
+    max-width: 42em;
+}
\ No newline at end of file
uot;, label v2-8-6dev_9' href='/ingrix/lynx-snapshots/commit/src/LYrcFile.h?id=bed9a2c79bfdde6e4ec89d9d02a5d6e88ae12f79'>bed9a2c7 ^
90d33dc9 ^

f6e997b7 ^
90d33dc9 ^

f6e997b7 ^
90d33dc9 ^
24a47fee ^
90d33dc9 ^













1876fe93 ^
90d33dc9 ^


1876fe93 ^
90d33dc9 ^









06cddc6b ^

90d33dc9 ^









0cb11571 ^
90d33dc9 ^
f6e997b7 ^

90d33dc9 ^





50f9f94b ^
90d33dc9 ^








a667eb0b ^
90d33dc9 ^












bed9a2c7 ^

90d33dc9 ^



f6e997b7 ^

90d33dc9 ^

f6e997b7 ^

90d33dc9 ^


f6e997b7 ^
7352a91b ^
f6e997b7 ^
90d33dc9 ^







f6e997b7 ^
90d33dc9 ^






f6e997b7 ^

90d33dc9 ^
6bbc5d0b ^
d1349dd6 ^

06cddc6b ^

d1349dd6 ^


d326f24d ^
b52ca53f ^
d326f24d ^




e087f6d4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268