Update app.js
Browse files
app.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import Phaser from 'phaser';
|
|
|
|
| 2 |
|
| 3 |
const config = {
|
| 4 |
type: Phaser.AUTO,
|
|
@@ -21,8 +22,59 @@ function preload() {
|
|
| 21 |
}
|
| 22 |
|
| 23 |
function create() {
|
| 24 |
-
// create game objects
|
|
|
|
|
|
|
|
|
|
| 25 |
scoreText = this.add.text(16, 16, 'Score: 0', { fontSize: '32px', fill: '#000' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
|
| 28 |
function update() {
|
|
@@ -34,8 +86,6 @@ function increaseScore(points) {
|
|
| 34 |
score += points;
|
| 35 |
}
|
| 36 |
|
| 37 |
-
function
|
| 38 |
-
// display
|
| 39 |
}
|
| 40 |
-
|
| 41 |
-
// integrate with AI assistant to update score and achievements based on performance
|
|
|
|
| 1 |
import Phaser from 'phaser';
|
| 2 |
+
import axios from 'axios';
|
| 3 |
|
| 4 |
const config = {
|
| 5 |
type: Phaser.AUTO,
|
|
|
|
| 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 |
+
function checkCategorization(wordObject, categoryObject) {
|
| 58 |
+
// check if the word belongs to the category
|
| 59 |
+
axios.post('/api/game_logic', {
|
| 60 |
+
sentence: sentence,
|
| 61 |
+
user_word: wordObject.word,
|
| 62 |
+
user_pos: categoryObject.category
|
| 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() {
|
|
|
|
| 86 |
score += points;
|
| 87 |
}
|
| 88 |
|
| 89 |
+
function displayHint(hint) {
|
| 90 |
+
// display hint on screen
|
| 91 |
}
|
|
|
|
|
|