doujia8801 2018-04-09 09:22
浏览 98
已采纳

如何将this.score传输到高分列表的文本文件? (AJAX)

How do I transfer this.score to a text file using ajax so when you game over there is a list of highscores?

And a alert with "your score has been saved succesfully". I don't really know alot about ajax so a little detail and explaination would be very helpfull :)

  var game = new Phaser.Game(1520, 740);

  this.score = 0;
      this.labelScore = game.add.text(20, 20, "0", { font: "30px Arial", 
   fill: "#ffffff" });  
  },

  update: function() {
      game.physics.arcade.overlap(this.bird, this.pipes, this.hitPipe, 
  null, this); 

      if (this.bird.y < 0 || this.bird.y > game.world.height)
          this.restartGame(); 

  },

      game.time.events.remove(this.timer);

      this.pipes.forEach(function(p){
          p.body.velocity.x = 0;
      }, this);
  },

  restartGame: function() {
      game.state.start('main');
  },

  addOnePipe: function(x, y) {
      var pipe = game.add.sprite(x, y, 'pipe');
      this.pipes.add(pipe);
      game.physics.arcade.enable(pipe);

      pipe.body.velocity.x = -500;  
      pipe.checkWorldBounds = true;
      pipe.outOfBoundsKill = true;
  },

  addRowOfPipes: function() {
      var hole = Math.floor(Math.random()*5)+1;

      for (var i = 0; i < 12; i++)
          if (i != hole && i != hole +1) 
              this.addOnePipe(1520, i*60+10);   

      this.score += 1;
      this.labelScore.text = this.score;  
      },
  };

  game.state.add('main', mainState);  
  game.state.start('main');  
  • 写回答

1条回答 默认 最新

  • dongziche8030 2018-04-09 09:51
    关注

    You don't need ajax to write a file ajax is used for transferring data from one system to another:

    Assuming you want to write a text file in your system

     const fs = require('fs');
     gameOverFunction(this.score){
       var logStream = fs.createWriteStream('/some/pathtofile/a.txt', {'flags': 'w'});
       logStream.write(this.score);
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退