复制步骤:
预期行为:
每次蛇的头撞到食物时,分数应增加10。
相关的Javascript:
function StatHandler ( totalScoreSelector, fruitEatenSelector )
{
this.scoreElem = $(totalScoreSelector);
this.fruitEeatenElem = $(fruitEatenSelector);
this.incrementScore = function ( incAmount )
{
var that = this;
$.ajax({
type: "POST",
url: "Play/IncrementScore?amount=" + incAmount,
success: function (newScore)
{
that.scoreElem.text(newScore);
console.log(newScore); // TEST
},
error: function ( )
{
alert("error occured!");
}
});
}
}
if (game.food.pos.x == newHeadX && game.food.pos.y == newHeadY) // if new head hit food
{
this.links.push(new game.elementOnGrid(game.board.rect(oldTailX * game.blockWidth, oldTailY * game.blockWidth, game.blockWidth, game.blockWidth).attr('fill', '#19FF19'),
oldTailX,
oldTailY
)); // fill space left by trail before it was translated
// i.e. lengthen the snake
game.coords[oldTailX][oldTailY] = true; // update coordinate list
game.stats.incrementScore(10);
game.placeFood(); // replace food
}
相关C#:
public class PlayController : Controller
{
private ushort score;
// GET: Play
public ActionResult Index ( )
{
ResetScore();
return View ( );
}
[HttpPost]
public ushort IncrementScore ( ushort amount )
{
score += amount;
return score;
}
[HttpPost]
public void ResetScore ( )
{
score = 0;
}
}
关于发生了什么的任何想法?