MarioWeb/templates/play.html

75 lines
2.0 KiB
HTML
Raw Normal View History

2022-10-20 14:48:14 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CheerpJ test</title>
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
2022-10-21 09:46:57 +00:00
<script>
window.onload = function () {
2022-10-20 14:48:14 +00:00
2022-10-21 09:46:57 +00:00
}
function PostToServer(data) {
2022-10-20 14:48:14 +00:00
var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象
httpRequest.open("POST",""); //调用AddDataToServer
httpRequest.setRequestHeader("Content-Type", "application/json"); //设置请求头信息
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
alert('添加成功');
}
}
console.log(typeof Array.from(data));
console.log(Array.from(data));
httpRequest.send(JSON.stringify(Array.from(data))); //设置为发送给服务器数据
//httpRequest.send((""+data));
}
2022-10-21 09:46:57 +00:00
</script>
</head>
<body>
</body>
<br />{{ py2htmlstr }}
<script>
cheerpjInit();
2022-10-20 14:48:14 +00:00
cheerpjCreateDisplay(800,600);
2022-10-21 09:46:57 +00:00
cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
2022-10-20 14:48:14 +00:00
console.log("done");
2022-10-21 09:46:57 +00:00
//cheerpjRunJar("/app/Mario-AI-Interface.jar");
var returnVal = cjCall("Play", "playGameMain", "0", "f_l");
returnVal.then(function(){
2022-10-20 14:48:14 +00:00
console.log("the return val is ready");
console.log(returnVal.value);
2022-10-21 09:46:57 +00:00
PostToServer(returnVal.value);
});
2022-10-20 14:48:14 +00:00
2022-10-21 09:46:57 +00:00
//.then(function(){console.log(" over2 ");});
//.catch((e) => {});
2022-10-20 14:48:14 +00:00
//console.log(returnVal);
// cheerpjRunJar("/app/Mario-AI-Interface.jar");
// var actionSequenceInBytes = cjCall("MarioProxy", "play", "0", "f_l", "0");
2022-10-21 09:46:57 +00:00
2022-10-20 14:48:14 +00:00
</script>
2022-10-21 09:46:57 +00:00
<form>
<input type="button" id="replayButton" value="Replay">
</form>
<script>
var button = document.getElementById("replayButton");
button.onclick = function(){
//alert("WTF?")
cjCall("Play", "replayGameMain", "0", "f_l");
};
</script>
2022-10-20 14:48:14 +00:00
</html>