Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update server of the user's new position

  • Loading branch information...
commit 888ffddf77371073077582eda3d72d5cbb38a45f 1 parent 09d907f
@karenc authored
View
9 app/assets/javascripts/fakesnladders.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');
View
6 app/assets/javascripts/gameRequest.js
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.