ayush2917 commited on
Commit
3fc8e81
·
verified ·
1 Parent(s): 3bcc021

Update templates/adventure.html

Browse files
Files changed (1) hide show
  1. templates/adventure.html +111 -6
templates/adventure.html CHANGED
@@ -8,16 +8,121 @@
8
 
9
  {% block content %}
10
  <div class="container">
11
- <div class="adventure-container">
12
- <h1>Explore Vrindavan with Krishna!</h1>
13
- <div id="adventure-scene" class="adventure-scene">
14
- <p>Loading your Vrindavan adventure...</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  </div>
16
- <div id="adventure-choices" class="adventure-choices"></div>
17
  </div>
18
  </div>
19
  {% endblock %}
20
 
21
  {% block scripts %}
22
- <script src="{{ url_for('static', filename='js/adventure.js') }}"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  {% endblock %}
 
8
 
9
  {% block content %}
10
  <div class="container">
11
+ <h1>Vrindavan Adventure with Little Krishna</h1>
12
+
13
+ <div class="adventure-game">
14
+ <!-- Scene display area -->
15
+ <div id="scene-container" class="scene-container">
16
+ <div id="scene-content" class="scene-content">
17
+ <p>Welcome to Vrindavan! Let's begin our adventure with Little Krishna.</p>
18
+ </div>
19
+ </div>
20
+
21
+ <!-- Choices will appear here -->
22
+ <div id="choices-container" class="choices-container">
23
+ <button id="start-btn" class="choice-btn">Begin Adventure</button>
24
+ </div>
25
+
26
+ <!-- Krishna image that changes based on scene -->
27
+ <div class="krishna-character">
28
+ <img id="krishna-img" src="{{ url_for('static', filename='assets/krishna_normal.png') }}" alt="Little Krishna">
29
  </div>
 
30
  </div>
31
  </div>
32
  {% endblock %}
33
 
34
  {% block scripts %}
35
+ <script>
36
+ document.addEventListener('DOMContentLoaded', function() {
37
+ const sceneContent = document.getElementById('scene-content');
38
+ const choicesContainer = document.getElementById('choices-container');
39
+ const startBtn = document.getElementById('start-btn');
40
+ const krishnaImg = document.getElementById('krishna-img');
41
+
42
+ let currentScene = 'start';
43
+
44
+ // Start the adventure
45
+ startBtn.addEventListener('click', function() {
46
+ loadScene(currentScene);
47
+ this.remove(); // Remove the start button
48
+ });
49
+
50
+ // Function to load a scene
51
+ async function loadScene(sceneId, choice = '') {
52
+ try {
53
+ // Show loading state
54
+ sceneContent.innerHTML = '<p>Krishna is thinking...</p>';
55
+ choicesContainer.innerHTML = '';
56
+
57
+ // Send request to server
58
+ const response = await fetch('/adventure', {
59
+ method: 'POST',
60
+ headers: {
61
+ 'Content-Type': 'application/x-www-form-urlencoded',
62
+ },
63
+ body: `current_scene=${sceneId}&choice=${encodeURIComponent(choice)}`
64
+ });
65
+
66
+ const data = await response.json();
67
+
68
+ if (data.scene) {
69
+ // Update scene content
70
+ sceneContent.innerHTML = `<p>${data.scene}</p>`;
71
+ currentScene = data.current_scene || sceneId;
72
+
73
+ // Update Krishna image based on scene
74
+ updateKrishnaImage(currentScene);
75
+
76
+ // If there are choices, show them
77
+ if (data.choices && data.choices.length > 0) {
78
+ choicesContainer.innerHTML = '';
79
+ data.choices.forEach(choiceText => {
80
+ const choiceBtn = document.createElement('button');
81
+ choiceBtn.className = 'choice-btn';
82
+ choiceBtn.textContent = choiceText;
83
+ choiceBtn.addEventListener('click', () => {
84
+ loadScene(currentScene, choiceText);
85
+ });
86
+ choicesContainer.appendChild(choiceBtn);
87
+ });
88
+ } else {
89
+ // No more choices - end of adventure
90
+ choicesContainer.innerHTML = `
91
+ <button class="choice-btn restart-btn" onclick="location.reload()">
92
+ Play Again
93
+ </button>
94
+ `;
95
+ }
96
+ } else {
97
+ throw new Error('Invalid scene data');
98
+ }
99
+ } catch (error) {
100
+ console.error('Error:', error);
101
+ sceneContent.innerHTML = `
102
+ <p>Oh no! Something went wrong in Vrindavan.</p>
103
+ <button class="choice-btn" onclick="loadScene('start')">
104
+ Start Over
105
+ </button>
106
+ `;
107
+ }
108
+ }
109
+
110
+ // Change Krishna's image based on the scene
111
+ function updateKrishnaImage(sceneId) {
112
+ let imageName = 'krishna_normal.png';
113
+
114
+ if (sceneId.includes('peacock') || sceneId.includes('tree')) {
115
+ imageName = 'krishna_playing.png';
116
+ } else if (sceneId.includes('butter') || sceneId.includes('yamuna')) {
117
+ imageName = 'krishna_mischievous.png';
118
+ } else if (sceneId.includes('flute')) {
119
+ imageName = 'krishna_flute.png';
120
+ } else if (!choicesContainer.querySelector('.choice-btn')) {
121
+ imageName = 'krishna_smiling.png';
122
+ }
123
+
124
+ krishnaImg.src = `{{ url_for('static', filename='assets/') }}${imageName}`;
125
+ }
126
+ });
127
+ </script>
128
  {% endblock %}