HTML and CSS Reference
In-Depth Information
}
// for the last layer
if (layer.length> 0) newComposition.data.push(layer);
return newComposition;
}
4. We add a new method to the Quest method that can compare two mulilayered
patern composiions and check whether they are equal to each other:
Quest.prototype.isEqualToComposition = function(composition) {
var a = this.data;
var b = composition.data;
// sort each level in both array
for (var i=0, len=a.length; i<len; i++) {
a[i].sort();
}
for (var i=0, len=b.length; i<len; i++) {
b[i].sort();
}
// flatten both compositions into sequence.
a = this.toSequence();
b = composition.toSequence();
if (a.length !== b.length) return false;
for (var i=0, len=a.length; i<len; i++) {
if (parseInt(a[i]) !== parseInt(b[i])) return false;
}
return true;
}
5. In the composition-view.js ile, we check whether the player's latest selecion
matches the quest level. Therefore, in both the selectPattern and undo methods,
we keep a composiion from the sequence and check it with the quest level:
selectPattern: function(pattern) {
...
game.composition = game.Composition.createFromSequence(game.
compositionSeq);
if (game.quest.isEqualToComposition(game.composition)){
game.flow.gameWin();
}
},
undo: function() {
...
game.composition = game.Composition.createFromSequence(game.
compositionSeq);
 
Search WWH ::




Custom Search