-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOpponentBoard.js
More file actions
40 lines (36 loc) · 1.33 KB
/
OpponentBoard.js
File metadata and controls
40 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var OpponentBoard = (function() {
"use strict";
var OpponentBoard = function(target, view, settings, scale) {
this.target = target;
this.settings = settings;
var squareWidth = Math.round(scale*Constants.SQUAREWIDTH);
this.graphics = new Graphics(squareWidth, target, settings);
this.deserialize(view);
}
OpponentBoard.prototype.deserialize = function(view) {
if (this.gameIndex === view.gameIndex && this.syncIndex === view.syncIndex) {
// Even if the opponent has made a move, if they've been attacked, we have
// to update their UI. We check the two conditions that can occur:
if (!maybeArraysEqual(this.attacks, view.attacks) ||
this.attackIndex !== view.attackIndex) {
$.extend(this, view);
this.graphics.drawUI(this);
this.graphics.flip();
}
return;
}
$.extend(this, view);
// Delete the blockType property and construct a block of that type instead.
delete this.blockType;
this.block = new Block(view.blockType);
this.block.rowsFree = Physics.calculateRowsFree(this.block, this.data);
this.graphics.reset(this);
}
OpponentBoard.prototype.set_scale = function(scale) {
this.target.empty();
var squareWidth = Math.round(scale*Constants.SQUAREWIDTH);
this.graphics = new Graphics(squareWidth, this.target, this.settings);
this.graphics.reset(this);
}
return OpponentBoard;
})();