All games on DTML platform should adhere to the following structure. Games which don't follow outline below cannot be published on the platform.
All games should start with standard intro. The intro is available below as well as in the code repository:
Note: It is strongly recommended to use dtml-sdk for all API calls. The code below is for reference purpose only.
Record Game start event. This call record user starting the game:
export default class extends Phaser.State {
...
init() {
var data = { "envelop": null,
"page": "<YOUR GAME NAME>",
"time": null,
"eventType": "GameStarted",
"eventData": navigator.userAgent
};
fetch('https://dtml.org/Activity/Record/',
{ method: 'post',
credentials: 'same-origin',
body: JSON.stringify(data),
headers: {
'content-type': 'application/json'
}
}).catch(err => {
console.log('err', err)
});
}
...
}
recordUserProgress(word, isCorrect) {
var url = 'https://dtml.org/api/GameService/Reinforcement?value=';
var type = isCorrect ? "correct_word" : "wrong_word";
fetch(url + word+'&type='+type +'&source=<YOUR GAME NAME>',
{
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(data => {
console.log(data);
})
.catch(err => {
console.log('err', err)
});
}
callGameOverService(score, complexity) {
var url = ''https://dtml.org/Activity/RecordUserActivity?id=';
fetch(url + '<YOUR GAME NAME>'+'&score=' + score + '&complexity=' + complexity,
{
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(data => {
console.log(data);
})
.catch(err => {
console.log('err', err)
});
}