gpt4 book ai didi

javascript - 如何将 this.score 传输到文本文件以获得高分列表? ( Ajax )

转载 作者:行者123 更新时间:2023-12-03 02:07:48 25 4
gpt4 key购买 nike

如何使用 ajax 将 this.score 传输到文本文件,以便在游戏结束时出现高分列表?

并显示“您的分数已成功保存”的提醒。我对 ajax 不太了解,所以一些细节和解释会非常有帮助:)

  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');

最佳答案

您不需要ajax来编写文件ajax用于将数据从一个系统传输到另一个系统:

假设您想在系统中写入一个文本文件

 const fs = require('fs');
gameOverFunction(this.score){
var logStream = fs.createWriteStream('/some/pathtofile/a.txt', {'flags': 'w'});
logStream.write(this.score);
}

关于javascript - 如何将 this.score 传输到文本文件以获得高分列表? ( Ajax ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49729579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com