MarioWeb/templates/play.html

103 lines
2.9 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>
2022-10-24 11:48:43 +00:00
//The Funtions
function PlayLevel(group, level){
var returnVal = cjCall("Play", "playGameMain", group, level);
return returnVal.then(function(){
console.log("the return val is ready");
console.log(returnVal.value);
PostToServer(returnVal.value);
});
}
function Replay(){
cjCall("Play", "replayGameMain", "test2", "test2");
};
function GameOver(){
if(alert("Game Over!")){
2022-10-21 09:46:57 +00:00
}
2022-10-24 11:48:43 +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) {
2022-10-24 11:48:43 +00:00
//alert('添加成功');
2022-10-20 14:48:14 +00:00
}
}
2022-10-24 11:48:43 +00:00
// console.log(typeof Array.from(data));
// console.log(Array.from(data));
2022-10-20 14:48:14 +00:00
httpRequest.send(JSON.stringify(Array.from(data))); //设置为发送给服务器数据
}
2022-10-21 09:46:57 +00:00
</script>
2022-10-24 11:48:43 +00:00
2022-10-21 09:46:57 +00:00
</head>
<body>
2022-10-24 11:48:43 +00:00
<div align="center">
<h1>Mario Game User Test</h1>
</div>
<div align="center" id = "GameWindow">
</div>
<div align="center"><button onClick="Replay()">Replay Game</button></div>
2022-10-21 09:46:57 +00:00
</body>
2022-10-24 11:48:43 +00:00
<script>
//Init Cheerpj Framework
2022-10-21 09:46:57 +00:00
cheerpjInit();
2022-10-24 11:48:43 +00:00
/*
function cheerpjCreateDisplay(w, h, oldElem)
{
// Create a div element that will contain all Java Windows
var element = document.createElement("div");
cjDisplay = element;
element.id="cheerpjDisplay";
if(oldElem && w<0 && h<0)
{
// Compute the sizes from the parent
element.style.width="100%";
element.style.height="100%";
}
else
{
element.style.width=w+"px";
element.style.height=h+"px";
}
element.classList.add("cheerpjLoading");
element.classList.add("bordered");
if(oldElem)
oldElem.appendChild(element);
else
document.body.appendChild(element);
cheerpjSetStatus(cjStatus, element);
return element;
}*/
var divElement = document.getElementById("GameWindow");
cheerpjCreateDisplay(500,500,divElement);
2022-10-21 09:46:57 +00:00
cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
2022-10-24 11:48:43 +00:00
console.log("Cheerpj Initialize Succeed!");
2022-10-20 14:48:14 +00:00
2022-10-24 11:48:43 +00:00
PlayLevel("test1", "test1")
.then(function (){alert("Game Over!")})
.then(PlayLevel("test2", "test2")
.then(function (){
alert("Go to Evaluation Window")
window.location.href = window.location.href + "\eval"
}));
2022-10-21 09:46:57 +00:00
2022-10-24 11:48:43 +00:00
</script>
2022-10-21 09:46:57 +00:00
2022-10-20 14:48:14 +00:00
</html>