MarioWeb/templates/data.js

87 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-11-02 07:14:16 +00:00
function closeReplayWindow(){
var replayWindow=document.getElementById("replayWindow");
replayWindow.style.visibility = 'hidden';
}
2022-11-03 14:07:08 +00:00
2022-11-02 07:14:16 +00:00
function getValue(){
var radio = document.getElementsByName("gameRadio");
for (i=0; i<radio.length; i++) {
if (radio[i].checked) {
alert(radio[i].value)
}
}
}
// function PostToServer(data) {
// 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('添加成功');
// }
// }
// httpRequest.send(JSON.stringify(data)); //设置为发送给服务器数据
// }
2022-11-03 09:07:12 +00:00
function PostToServer(url,data) {
if(url == null){
$.post(window.location.href, data);
}else{
$.post(url, data);
}
2022-11-02 07:14:16 +00:00
}
function GameLoad(){
return cjCall("Play","initialGame");
}
2022-11-09 14:09:00 +00:00
function PlayLevel(level,control){
console.log("HTML:Start PlayLevel cjCall")
2022-12-14 12:07:02 +00:00
var returnVal = cjCall("Play", "playGameMain", level, 5, control,30,16);
2022-11-02 07:14:16 +00:00
return returnVal.then(function(){
console.log("the return val is ready");
console.log(returnVal.value);
2022-11-09 14:09:00 +00:00
PostToServer(window.location.href+"/data",level+returnVal.value);
2022-11-03 09:07:12 +00:00
//Array.from()
2022-11-02 07:14:16 +00:00
});
}
function GameOver(){
if(alert("Game Over!")){
}
}
function getRadioValue(){
alert("getvalue");
var obj = document.getElementsByName("fun");
var result = " ";
for(var i=0; i<obj.length; i ++){
if(obj[i].checked){
PostToServer(obj[i].value);
result = obj[i].value;
alert(obj[i].value);
}
}
// var radio = document.getElementsByName("gameRadio");
// var addressID = $("input[name='sex']:checked").val();
// alert(addressID)
2022-11-03 12:03:04 +00:00
}
function getLevels(gameLevelstr,num){
2022-11-03 14:07:08 +00:00
console.log(gameLevelstr)
2022-11-03 12:03:04 +00:00
var levels = gameLevelstr.split(",")
var result = []
for (i = 0; i < num; i++) {
result[i] = cleanStr(levels[i])
}
return result;
2022-11-03 14:07:08 +00:00
}
function cleanStr(str){
str=str.replace("&#39;","")
str=str.replace("&#39;","")
str=str.replace("[","")
str=str.replace("]","")
str=str.replace(" ","")
str=str.replace(" ","")
return str;
2022-11-03 12:03:04 +00:00
}