0

我使用 Phaser 制作了一款游戏,并希望我的用户能够在一个表单中填写他们的姓名,其中包含一个“姓名:”字段,然后单击提交按钮,提交他们刚刚输入的姓名和他们的高分。

这是我的javascript页面代码:

Game.Leader = function(game) {
buttonContinue = null;
state = null;
};
Game.Leader.prototype = {
create: function() {
    this.showLeader();      
},


showLeader: function() {
    this.game.add.sprite(0, 0, 'screen-leader');
    this.game.add.sprite(640-213-70, 80, 'spread');
    this.state = 'Leader';
    this.buttonContinue = this.add.button((640-200)/2, 960-103-1, 'button-restartsmall', this.startGame, this);
    this.game.add.button(640-213-10, 20, 'twitter', function() {window.open("https://www.xxxxxxxx.com/", "_blank");}, this);
    this.game.add.button(640-133-10, 20, 'whatsapp', function() {window.open("https://www.xxxxxxxx.com", "_blank");}, this);
    this.game.add.button(640-293-10, 20, 'face', function() {window.open("https://www.xxxxxxxx.com", "_blank");}, this);
    this.game.add.button(640-194-265, 700, 'button-leader2', function() {window.open("leader.htm", "_self");}, this);
    this.game.add.sprite(640-194-220, 300, 'highscore-text');
    highscoreText = this.game.add.text(290, 360, "0", { font: "40px ComicBook", fill: "#FFCC00", align: "right" });

    storageAPI.initUnset('highscore',0);
    var highscore = storageAPI.get('highscore');
    highscoreText.setText(highscore);   

},

startGame: function() {
    this.game.state.start('Game');
}

};

所以他们的高分已经保存在下面的变量中,并在上面的页面上输出

var highscore = storageAPI.get('highscore');

我想抓住这个并通过在上面的脚本中添加一些东西来以表格的形式提交他们的名字——但是什么?

在提交表单时,需要执行以下函数以将其发布到 app42 排行榜服务 - 请参阅我的两个//评论:

function saveScore(n){
    if(n){
      var gameName = "xxxxx";  
      var userName = name; //this is where the name would go from the form
      if(userName == ""){
           userName = "Guest";
      }  
      var gameScore = x;  //what needs to go here to grab the highscore text already available?
      var result;
      var scoreBoardService = new App42ScoreBoard()    
      scoreBoardService.saveUserScore(gameName,userName,gameScore,{ success: function(object){} }); 
    }
}

所以问题:

  1. 我需要添加第一个脚本来纯粹在 javascript 中添加表单吗?
  2. 我需要更改我的两个//评论在第二个脚本中的位置才能发布数据?

非常感谢您的帮助!

4

0 回答 0