Permalink
Browse files

Update server of the user's new position

  • Loading branch information...
1 parent 09d907f commit 888ffddf77371073077582eda3d72d5cbb38a45f @karenc committed Jul 29, 2012
Showing with 9 additions and 6 deletions.
  1. +4 −5 app/assets/javascripts/fakesnladders.js
  2. +5 −1 app/assets/javascripts/gameRequest.js
@@ -80,8 +80,9 @@ Ladder.prototype.draw = function(context) {
Ladder.prototype.hit = function(p) {
};
-function Player(game, scoreGrid, image) {
+function Player(game, id, scoreGrid, image) {
this.game = game;
+ this.id = id;
this.scoreGrid = scoreGrid;
this.image = image;
this.rect = this.scoreGrid.rect;
@@ -122,6 +123,7 @@ Player.prototype.moveStraightLine = function(newScoreGrid, myCompletion) {
function everythingCompletion() {
newScoreGrid.doActions(this_);
this_.scoreGrid = newScoreGrid;
+ new GameRequest().updateUserSquare(this_.id, this_.scoreGrid.sqNo);
}
var completion;
if (myCompletion != null) {
@@ -243,12 +245,9 @@ FakesNLadders.prototype.initPlayer = function(userInfo, redraw) {
playerImage.height = 40;
playerImage.onload = redraw;
- this.playerMap[userInfo.id] = new Player(this, this.getGrid(userInfo.position), playerImage);
+ this.playerMap[userInfo.id] = new Player(this, userInfo.id, this.getGrid(userInfo.position), playerImage);
this.layer.addGameObject(this.playerMap[userInfo.id]);
- var p = new Player(this, this.getGrid(0), playerImage);
- this.layer.addGameObject(p);
-
var this_ = this;
document.getElementById('option-a').onclick = function() {
this_.makeChoice('a');
@@ -27,7 +27,11 @@ GameRequest.prototype.updateUserSquare = function(userId, newSquare, optionalCal
optionalCallback(response.id, response.position);
}
};
- this.sendRequest("PUT", url, {"position": newSquare}, reqCallback);
+ $.ajax(url, {
+ type: 'PUT',
+ dataType: 'json',
+ data: {'position': newSquare}
+ }).done(reqCallback);
}
// callback will be passed the question id, option a, and option b

0 comments on commit 888ffdd

Please sign in to comment.