<!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>
    <script>
      window.onload = function () {

        }
      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('添加成功');
        }
      }
      console.log(typeof Array.from(data));
      console.log(Array.from(data));
      httpRequest.send(JSON.stringify(Array.from(data))); //设置为发送给服务器数据
      //httpRequest.send((""+data));
    }


    </script>
  </head>
  <body>
  </body>
  <br />{{ py2htmlstr }}
  <script>






    cheerpjInit();
    cheerpjCreateDisplay(800,600);
    cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
    
    console.log("done");

    //cheerpjRunJar("/app/Mario-AI-Interface.jar"); 
    var returnVal = cjCall("Play", "playGameMain", "0", "f_l");

    returnVal.then(function(){ 
      console.log("the return val is ready");  
      console.log(returnVal.value);
      PostToServer(returnVal.value);    
    });
    
    //.then(function(){console.log(" over2 ");});
    //.catch((e) => {});


    //console.log(returnVal);
    // cheerpjRunJar("/app/Mario-AI-Interface.jar"); 
    // var actionSequenceInBytes = cjCall("MarioProxy", "play", "0", "f_l", "0");

  </script>
  <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>

</html>