Source Code : test_gameSettings.html
<script type="text/javascript">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Όνομα Ζώο Φυτό - Το παιχνίδι </title>
<script src="tests_pretty.js"></script>
</head>
<body>
Example :
<mark>Services Word Games</mark>
<br/> <br/>
<script>
displayInfo(" api : " + URL, null, 'url');
let sPlugin = "gameSettings";
let gameDBPin = null;
let gameDBMaterKey = null;
// action = create
let data = {
"configuration": [sPlugin, 'create', ""],
'pin': '',
'description': 'new game - info - client '
};
fetch(URL, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-type": "application/json;
charset=UTF-8"
}
}).then(response => response.json())
.then(dataRet => {
displayInfo(" Service Call ", data, 'retCall');
let returnJSON = dataRet;
gameDBPin = returnJSON.pin;
gameDBMaterKey = returnJSON.masterKey;
// Administration
displayInfo(sPlugin + " Returns Json ", returnJSON, 'retInfo');
// *********************** close gamec - GAMEOVER
// several call API with -- serviceCoreData
// action = terminate
serviceCoreData(URL, {
"configuration": [sPlugin, 'play', ''],
'pin': gameDBPin,
})
.then(data => {
displayInfo(" info play ", data, 'infoplay');
});
serviceCoreData(URL, {
"configuration": ["playerSettings", 'create', ''],
'pin': gameDBPin,
'nickname': 'testingPlayer'
})
.then(data => {
displayInfo(" Game PIN "+ gameDBPin + " joined NEW player testingPlayer " , data, 'playersss');
});
var characters = 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ';
var charactersLength = characters.length;
var startL = characters.charAt(Math.floor(Math.random() * charactersLength));
serviceCoreData(URL, {
"configuration": ['gameSettings', 'playLetter', ''],
'pin': gameDBPin,
'letter': startL,
})
.then(data => {
displayInfo(" Play with Letter ", data, 'playnasow');
});
serviceCoreData(URL, {
"configuration": [sPlugin, 'info', ''],
})
.then(data => {
displayInfo(" info ", data, 'informartaion');
});
serviceCoreData(URL, {
"configuration": [sPlugin, 'terminate', ''],
'pin': gameDBPin,
})
.then(data => {
displayInfo(" Terminate Game ", data, 'terminate');
});
serviceCoreData(URL, {
"configuration": [sPlugin, 'getPlayers', ''],
'pin': gameDBPin,
})
.then(data => {
displayInfo(" getPlayers ", data, 'terminatdse');
});
})
.catch((error) => {
displayInfo(" Error : " + error, data);
});
</script>
</body>
</html>
</script>
Typical Syntax Call
<script type="text/javascript">
let URL = 'https://xxx.xxx.xxx.xxx/service.php'
let sPlugin = "plugin";
//
const data = { "configuration": [sPlugin, "action", "extra"],
'word': ' Απόδειξη ',
};
//
fetch(URL, { method: "POST", body: JSON.stringify(data),
headers: { "Content-type": "application/json;
charset=UTF-8"
}
}).then(response => response.json())
.then(dataRet => {
const returnJSON = JSON.parse(dataRet);
// returnJSON
// ....
///
})
.catch((error) => {
displayInfo(" Error : " + error, data);
});
</script>