|
|
|
@ -25,6 +25,7 @@ var Game = {
|
|
|
|
|
success: function(data) {
|
|
|
|
|
self.cards = data;
|
|
|
|
|
self.displayCards.call(self);
|
|
|
|
|
self.existingSet(data);
|
|
|
|
|
self.setCardListeners();
|
|
|
|
|
self.setPageListeners();
|
|
|
|
|
}
|
|
|
|
@ -51,6 +52,7 @@ var Game = {
|
|
|
|
|
var shapes;
|
|
|
|
|
var fills;
|
|
|
|
|
var numbers;
|
|
|
|
|
var cartes = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$.each(this.cards, function(index, card){
|
|
|
|
@ -64,7 +66,7 @@ var Game = {
|
|
|
|
|
'number': card.number
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var shapeNode = $('<span>');
|
|
|
|
|
var shapeNode = $('<canvas>');
|
|
|
|
|
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -78,33 +80,40 @@ var Game = {
|
|
|
|
|
self.$board.append($('<div>'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
colors = $.map(cardNode, function(ele) { return $(ele).data("color");});
|
|
|
|
|
/*colors = $.map(cardNode, function(ele) { return $(ele).data("color");});
|
|
|
|
|
shapes = $.map(cardNode, function(ele) { return $(ele).data("shape"); });
|
|
|
|
|
fills= $.map(cardNode, function(ele) { return $(ele).data("fill"); });
|
|
|
|
|
numbers = $.map(cardNode, function(ele) { return $(ele).data("number"); });
|
|
|
|
|
|
|
|
|
|
var a = self.existingSet(colors) && self.existingSet(shapes) && self.existingSet(fills) && self.existingSet(numbers);
|
|
|
|
|
|
|
|
|
|
if (!a){
|
|
|
|
|
self.nbSets++;
|
|
|
|
|
}
|
|
|
|
|
numbers = $.map(cardNode, function(ele) { return $(ele).data("number"); });*/
|
|
|
|
|
|
|
|
|
|
cartes = $.map(cardNode, function(ele) { return $(ele).data();});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.$nbSets.html(self.nbSets);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
existingSet: function(cartes) {
|
|
|
|
|
|
|
|
|
|
console.log(cartes);
|
|
|
|
|
|
|
|
|
|
existingSet: function(arr) {
|
|
|
|
|
var reduced = $.unique(arr);
|
|
|
|
|
//console.log(arr);
|
|
|
|
|
return reduced.length === 1 || reduced.length === 3 || reduced.length === 6 || reduced.length === 9 || reduced.length === 12;
|
|
|
|
|
/* var i;
|
|
|
|
|
var isSet = [];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cartes.length-2; ++i) {
|
|
|
|
|
isSet[0] = cartes[i];
|
|
|
|
|
for (i = 0; i < cartes1.length-1; ++i) {
|
|
|
|
|
isSet[1] = cartes1[i];
|
|
|
|
|
for (i = 0; i < cartes2.length; ++i) {
|
|
|
|
|
isSet[2] = cartes2[i];
|
|
|
|
|
isSet = [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
console.log(isSet);
|
|
|
|
|
|
|
|
|
|
this.$nbSets.html(self.nbSets);*/
|
|
|
|
|
},
|
|
|
|
|
setCardListeners: function() {
|
|
|
|
|
var self = this;
|
|
|
|
@ -269,7 +278,38 @@ var Game = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(document).ready(Game.deal());
|
|
|
|
|
|
|
|
|
|
$(document).ready(Game.deal());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
var canvases = document.getElementsByClassName('shape diamond red solid');
|
|
|
|
|
console.log(canvases);
|
|
|
|
|
for (let canvas of canvases) {
|
|
|
|
|
var context = canvas.getContext('2d');
|
|
|
|
|
|
|
|
|
|
drawDiamond(context, 50, 50, 75, 100);
|
|
|
|
|
canvas.fillStyle("#FF0000");
|
|
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function drawDiamond(context, x, y, width, height){
|
|
|
|
|
context.save();
|
|
|
|
|
context.beginPath();
|
|
|
|
|
context.moveTo(x, y);
|
|
|
|
|
// top left edge
|
|
|
|
|
context.lineTo(x - width / 2, y + height / 2);
|
|
|
|
|
// bottom left edge
|
|
|
|
|
context.lineTo(x, y + height);
|
|
|
|
|
// bottom right edge
|
|
|
|
|
context.lineTo(x + width / 2, y + height / 2);
|
|
|
|
|
|
|
|
|
|
// closing the path automatically creates
|
|
|
|
|
// the top right edge
|
|
|
|
|
context.closePath();
|
|
|
|
|
|
|
|
|
|
context.fillStyle = "red";
|
|
|
|
|
context.fill();
|
|
|
|
|
context.restore();
|
|
|
|
|
}*/
|