Update app.js
Browse files
app.js
CHANGED
@@ -1,91 +1,27 @@
|
|
1 |
-
import Phaser from 'phaser';
|
2 |
import axios from 'axios';
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
}
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
function preload() {
|
21 |
-
// load assets
|
22 |
-
}
|
23 |
-
|
24 |
-
function create() {
|
25 |
-
// create game objects{
|
26 |
-
"link": "https://phaser.io/examples/v3/category/physics/arcade",
|
27 |
-
"user_has_request": false
|
28 |
-
}
|
29 |
-
scoreText = this.add.text(16, 16, 'Score: 0', { fontSize: '32px', fill: '#000' });
|
30 |
-
|
31 |
-
// create word objects
|
32 |
-
words = this.physics.add.group();
|
33 |
-
|
34 |
-
// add words to the group
|
35 |
-
sentence.split(' ').forEach((word, index) => {
|
36 |
-
let wordObject = this.physics.add.sprite(100 + index * 50, 100, 'word');
|
37 |
-
wordObject.setBounce(0.2);
|
38 |
-
wordObject.setCollideWorldBounds(true);
|
39 |
-
wordObject.word = word;
|
40 |
-
words.add(wordObject);
|
41 |
-
});
|
42 |
-
|
43 |
-
// create categories
|
44 |
-
categories = this.physics.add.staticGroup();
|
45 |
-
|
46 |
-
// add categories to the group
|
47 |
-
['sustantivo', 'verbo', 'adjetivo', 'artículo'].forEach((category, index) => {
|
48 |
-
let categoryObject = this.physics.add.sprite(100 + index * 200, 500, 'category');
|
49 |
-
categoryObject.category = category;
|
50 |
-
categories.add(categoryObject);
|
51 |
-
});
|
52 |
-
|
53 |
-
// check for correct categorization
|
54 |
-
this.physics.add.collider(words, categories, checkCategorization, null, this);
|
55 |
}
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
.then(function (response) {
|
65 |
-
let correct = response.data.correct;
|
66 |
-
if (correct) {
|
67 |
-
increaseScore(10);
|
68 |
-
wordObject.destroy();
|
69 |
-
} else {
|
70 |
-
// give a hint
|
71 |
-
let hint = response.data.hint;
|
72 |
-
displayHint(hint);
|
73 |
-
}
|
74 |
-
})
|
75 |
-
.catch(function (error) {
|
76 |
-
console.log(error);
|
77 |
-
});
|
78 |
-
}
|
79 |
-
|
80 |
-
function update() {
|
81 |
-
// update game logic
|
82 |
-
scoreText.setText(`Score: ${score}`);
|
83 |
-
}
|
84 |
-
|
85 |
-
function increaseScore(points) {
|
86 |
-
score += points;
|
87 |
-
}
|
88 |
-
|
89 |
-
function displayHint(hint) {
|
90 |
-
// display hint on screen
|
91 |
-
}
|
|
|
|
|
1 |
import axios from 'axios';
|
2 |
|
3 |
+
let chatBox = document.getElementById('chatBox');
|
4 |
+
let inputField = document.getElementById('inputField');
|
5 |
+
|
6 |
+
function sendMessage() {
|
7 |
+
let message = inputField.value;
|
8 |
+
let messageElement = document.createElement('p');
|
9 |
+
messageElement.textContent = 'You: ' + message;
|
10 |
+
chatBox.appendChild(messageElement);
|
11 |
+
|
12 |
+
axios.post('/api/game', { message: message })
|
13 |
+
.then(response => {
|
14 |
+
let botMessageElement = document.createElement('p');
|
15 |
+
botMessageElement.textContent = 'Bot: ' + response.data.message;
|
16 |
+
chatBox.appendChild(botMessageElement);
|
17 |
+
})
|
18 |
+
.catch(error => console.error(error));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
+
inputField.addEventListener('keydown', function(event) {
|
22 |
+
if (event.key === 'Enter') {
|
23 |
+
event.preventDefault();
|
24 |
+
sendMessage();
|
25 |
+
inputField.value = '';
|
26 |
+
}
|
27 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|