You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4567 lines
107 KiB

var Game = {
cards: [],
selected: [],
score: 0,
set: 0,
$board: $('[data-display="game-board"]'),
$score: $('[data-display="score"]'),
$nbSets: $('[data-display="nbSets"]'),
cards1 : [],
selected1: [],
score1: 0 ,
set1: 0,
$score1: $('[data-display="score1"]'),
$nbSets1: $('[data-display="nbSets1"]'),
$board1: $('[data-display="game-board1"]'),
cards2 : [],
selected2: [],
score2: 0 ,
set2: 0,
$score2: $('[data-display="score2"]'),
$nbSets2: $('[data-display="nbSets2"]'),
$board2: $('[data-display="game-board2"]'),
cards3 : [],
selected3: [],
score3: 0 ,
set3: 0,
$score3: $('[data-display="score3"]'),
$nbSets3: $('[data-display="nbSets3"]'),
$board3: $('[data-display="game-board3"]'),
cards4: [],
selected4 : [],
score4: 0,
set4: 0,
$score4: $('[data-display="score4"]'),
$nbSets4: $('[data-display="nbSets4"]'),
$board4: $('[data-display="game-board4"]'),
cards0: [],
selected0 : [],
score0: 0,
set0: 0,
$score0: $('[data-display="score0"]'),
$nbSets0: $('[data-display="nbSets0"]'),
$board0: $('[data-display="game-board0"]'),
cardsHS: [],
selectedHS : [],
scoreHS: 0,
setHS: 0,
$scoreHS: $('[data-display="scoreHS"]'),
$nbSetsHS: $('[data-display="nbSetsHS"]'),
$boardHS: $('[data-display="game-boardHS"]'),
cardsHS0: [],
selectedHS0 : [],
scoreHS0: 0,
setHS0: 0,
$scoreHS0: $('[data-display="scoreHS0"]'),
$nbSetsHS0: $('[data-display="nbSetsHS0"]'),
$boardHS0: $('[data-display="game-boardHS0"]'),
cardsHS1: [],
selectedHS1 : [],
scoreHS1: 0,
setHS1: 0,
$scoreHS1: $('[data-display="scoreHS1"]'),
$nbSetsHS1: $('[data-display="nbSetsHS1"]'),
$boardHS1: $('[data-display="game-boardHS1"]'),
cardsHS2: [],
selectedHS2 : [],
scoreHS2: 0,
setHS2: 0,
$scoreHS2: $('[data-display="scoreHS2"]'),
$nbSetsHS2: $('[data-display="nbSetsHS2"]'),
$boardHS2: $('[data-display="game-boardHS2"]'),
deal: function() {
var self = this;
var dealRequest;
var dealRequest1;
var dealRequest2;
var dealRequest3;
var dealRequest4;
var dealRequest0;
var dealRequestHS;
var dealRequestHS0;
var dealRequestHS1;
var dealRequestHS2;
// ajax request to get initial set of cards
dealRequest = $.ajax({
url: 'set.php?action=deal',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards = data;
self.existingSet();
self.displayCards.call(self);
self.setCardListeners();
//self.setPageListeners();
}
});
dealRequest1 = $.ajax({
url: 'set.php?action=deal1',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards1 = data;
self.existingSet1();
self.displayCards1.call(self);
self.setCardListeners1();
//self.setPageListeners1();
}
});
dealRequest2 = $.ajax({
url: 'set.php?action=deal2',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards2 = data;
self.displayCards2.call(self);
self.existingSet2();
self.setCardListeners2();
//self.setPageListeners2();
}
});
dealRequest3 = $.ajax({
url: 'set.php?action=deal3',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards3 = data;
self.displayCards3.call(self);
//self.existingSet3();
self.setCardListeners3();
//self.setPageListeners3();
}
});
dealRequest4 = $.ajax({
url: 'set.php?action=deal4',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards4 = data;
self.displayCards4.call(self);
//self.existingSet4();
self.setCardListeners4();
//self.setPageListeners4();
}
});
dealRequest0 = $.ajax({
url: 'set.php?action=deal0',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards0 = data;
self.displayCards0.call(self);
self.existingSet0();
self.setCardListeners0();
//self.setPageListeners0();
}
});
dealRequestHS= $.ajax({
url: 'set.php?action=dealHS',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cardsHS = data;
self.displayCardsHS.call(self);
self.setCardListenersHS();
//self.setPageListenersHS();
}
});
dealRequestHS0= $.ajax({
url: 'set.php?action=dealHS0',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cardsHS0 = data;
self.displayCardsHS0.call(self);
self.setCardListenersHS0();
//self.setPageListenersHS0();
}
});
dealRequestHS1= $.ajax({
url: 'set.php?action=dealHS1',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cardsHS1 = data;
self.displayCardsHS1.call(self);
self.setCardListenersHS1();
//self.setPageListenersHS1();
}
});
dealRequestHS2= $.ajax({
url: 'set.php?action=dealHS2',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cardsHS2 = data;
self.displayCardsHS2.call(self);
self.setCardListenersHS2();
//self.setPageListenersHS2();
}
});
},
displayCards: function() {
var self = this;
if (self.cards.length == 0) {
return false;
}
$.each(self.cards, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$board);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$board.append(cardNode);
// display 4 cards per row
if ((index+1) % 4 === 0) {
self.$board.append($('<div>'));
}
});
},
displayCards1: function() {
var self = this;
if (self.cards1.length == 0) {
return false;
}
$.each(self.cards1, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$board1);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'border': card.border,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill + ' ' + card.border);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$board1.append(cardNode);
// display 4 cards per row
if ((index+1) % 5 === 0) {
self.$board1.append($('<div>'));
}
});
},
displayCards2: function() {
var self = this;
if (self.cards2.length == 0) {
return false;
}
$.each(self.cards2, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$board2);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill );
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$board2.append(cardNode);
// display 4 cards per row
if ((index+1) % 5 === 0) {
self.$board2.append($('<div>'));
}
});
},
displayCards3: function() {
var self = this;
if (self.cards3.length == 0) {
return false;
}
$.each(self.cards3, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$board3);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'border': card.border,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill + ' ' + card.border);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$board3.append(cardNode);
// display 4 cards per row
if ((index+1) % 4 === 0) {
self.$board3.append($('<div>'));
}
});
},
displayCards4: function() {
var self = this;
if (self.cards4.length == 0) {
return false;
}
$.each(self.cards4, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$board4);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'border': card.border,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill + ' ' + card.border);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$board4.append(cardNode);
// display 4 cards per row
if ((index+1) % 4 === 0) {
self.$board4.append($('<div>'));
}
});
},
displayCards0: function() {
var self = this;
if (self.cards0.length == 0) {
return false;
}
$.each(self.cards0, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$board0);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$board0.append(cardNode);
// display 4 cards per row
if ((index+1) % 3 === 0) {
self.$board0.append($('<div>'));
}
});
},
displayCardsHS: function() {
var self = this;
if (self.cardsHS.length == 0) {
return false;
}
$.each(self.cardsHS, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$boardHS);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$boardHS.append(cardNode);
// display 4 cards per row
if ((index+1) % 4 === 0) {
self.$boardHS.append($('<div>'));
}
});
},
displayCardsHS0: function() {
var self = this;
if (self.cardsHS0.length == 0) {
return false;
}
$.each(self.cardsHS0, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$boardHS0);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$boardHS0.append(cardNode);
// display 4 cards per row
if ((index+1) % 4 === 0) {
self.$boardHS0.append($('<div>'));
}
});
},
displayCardsHS1: function() {
var self = this;
if (self.cardsHS1.length == 0) {
return false;
}
$.each(self.cardsHS1, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$boardHS1);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'border': card.border,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill + ' '+ card.border);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$boardHS1.append(cardNode);
// display 4 cards per row
if ((index+1) % 5 === 0) {
self.$boardHS1.append($('<div>'));
}
});
},
displayCardsHS2: function() {
var self = this;
if (self.cardsHS2.length == 0) {
return false;
}
$.each(self.cardsHS2, function(index, card){
var cardNode = $('<div>', {
class: "card"
}).appendTo(self.$boardHS2);
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
'color': card.color,
'number': card.number
});
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill);
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
}
self.$boardHS2.append(cardNode);
// display 4 cards per row
if ((index+1) % 5 === 0) {
self.$boardHS2.append($('<div>'));
}
});
},
// PARLER SUR CET ALGO SUR LE RAPPORT
/*existingSet: function() {
var colors = [];
var shapes =[];
var fills= [];
var numbers= [];
var valid;
var self = this;
var cartes = self.cards;
var cartes1 = cartes;
var cartes2 = cartes;
var cpt=0;
var carte1;
var carte2;
var carte3;
var i, j, k;
for(i=0; i<cartes.length-2; i++) {
for (j = i+1; j < cartes1.length-1; j++) {
for (k = j+1; k < cartes2.length; k++) {
carte1 = cartes[i];
carte2 = cartes1[j];
carte3 = cartes2[k];
colors.splice(0,1,carte1.color);
colors.splice(1,1,carte2.color);
colors.splice(2,1,carte3.color);
shapes.splice(0,1,carte1.shape);
shapes.splice(1,1,carte2.shape);
shapes.splice(2,1,carte3.shape);
fills.splice(0,1,carte1.fill);
fills.splice(1,1,carte2.fill);
fills.splice(2,1,carte3.fill);
numbers.splice(0,1,carte1.number);
numbers.splice(1,1,carte2.number);
numbers.splice(2,1,carte3.number);
valid = self.isSet(colors) && self.isSet(shapes) && self.isSet(fills) && self.isSet(numbers);
if (valid) {
self.set = self.set + 1;
}
}
}
}
this.$nbSets.html(self.set);
},*/
existingSet: function() {
var colors1 = [];
var shapes1 =[];
var fills1= [];
var numbers1= [];
var self = this;
var cartes = self.cards;
var cartes1 = cartes;
var carte1;
var carte2;
var i, j, a;
var colorsall= $.map(this.cards, function(el) { return el.color;});
var shapesall = $.map(this.cards, function(el) { return el.shape; });
var fillsall= $.map(this.cards,function(el) { return el.fill; });
var numbersall = $.map(this.cards, function(el) { return el.number;});
for(i=0; i<cartes.length; i++) {
for (j = i+1; j < cartes1.length; j++) {
carte1 = cartes[i];
carte2 = cartes1[j];
colors1.splice(0,1,carte1.color);
colors1.splice(1,1,carte2.color);
shapes1.splice(0,1,carte1.shape);
shapes1.splice(1,1,carte2.shape);
fills1.splice(0,1,carte1.fill);
fills1.splice(1,1,carte2.fill);
numbers1.splice(0,1,carte1.number);
numbers1.splice(1,1,carte2.number);
if(colors1[0] === colors1 [1]){
colors1.splice(2,1,colors1[0]);
}
else{
if(colors1[0] === 'red' && colors1[1] === 'green'){
colors1.splice(2,1,'purple');
}
if(colors1[0] === 'red' && colors1[1] === 'purple'){
colors1.splice(2,1,'green');
}
if(colors1[0] === 'green' && colors1[1] === 'purple'){
colors1.splice(2,1,'red');
}
if(colors1[0] === 'green' && colors1[1] === 'red'){
colors1.splice(2,1,'purple');
}
if(colors1[0] === 'purple' && colors1[1] === 'red'){
colors1.splice(2,1,'green');
}
if(colors1[0] === 'purple' && colors1[1] === 'green'){
colors1.splice(2,1,'red');
}
}
if(shapes1[0] === shapes1 [1]){
shapes1.splice(2,1,shapes1[0]);
}
else{
if(shapes1[0] === 'oval' && shapes1[1] === 'diamond'){
shapes1.splice(2,1,'wave');
}
if(shapes1[0] === 'oval' && shapes1[1] === 'wave'){
shapes1.splice(2,1,'diamond');
}
if(shapes1[0] === 'diamond' && shapes1[1] === 'oval'){
shapes1.splice(2,1,'wave');
}
if(shapes1[0] === 'diamond' && shapes1[1] === 'wave'){
shapes1.splice(2,1,'oval');
}
if(shapes1[0] === 'wave' && shapes1[1] === 'diamond'){
shapes1.splice(2,1,'oval');
}
if(shapes1[0] === 'wave' && shapes1[1] === 'oval'){
shapes1.splice(2,1,'diamond');
}
}
if(fills1[0] === fills1 [1]){
fills1.splice(2,1,fills1[0]);
}
else {
if (fills1[0] === 'solid' && fills1[1] === 'stripped') {
fills1.splice(2, 1, 'open');
}
if (fills1[0] === 'solid' && fills1[1] === 'open') {
fills1.splice(2, 1, 'stripped');
}
if (fills1[0] === 'stripped' && fills1[1] === 'open') {
fills1.splice(2, 1, 'solid');
}
if (fills1[0] === 'open' && fills1[1] === 'stripped') {
fills1.splice(2, 1, 'solid');
}
if (fills1[0] === 'stripped' && fills1[1] === 'solid') {
fills1.splice(2, 1, 'open');
}
if (fills1[0] === 'open' && fills1[1] === 'solid') {
fills1.splice(2, 1, 'stripped');
}
}
if(numbers1[0] === numbers1[1]){
numbers1.splice(2,1,numbers1[0]);
}
else{
if(numbers1[0] === 1 && numbers1[1] === 2){
numbers1.splice(2,1,3);
}
if(numbers1[0] === 1 && numbers1[1] === 3){
numbers1.splice(2,1,2);
}
if(numbers1[0] === 2 && numbers1[1] === 1){
numbers1.splice(2,1,3);
}
if(numbers1[0] === 2 && numbers1[1] === 3){
numbers1.splice(2,1,1);
}
if(numbers1[0] === 3 && numbers1[1] === 1){
numbers1.splice(2,1,2);
}
if(numbers1[0] === 3 && numbers1[1] === 2){
numbers1.splice(2,1,1);
}
}
for (a = j+1; a<this.cards.length; a++) {
if (shapes1[2] === shapesall[a] && colors1[2] === colorsall[a] && fills1[2] === fillsall[a] && numbers1[2] === numbersall[a]) {
if (this.isSet(shapes1) && this.isSet(colors1) && this.isSet(fills1) && this.isSet(numbers1)) {
self.set = self.set + 1;
}
}
}
}
}
this.$nbSets.html(self.set);
},
existingSet0: function() {
var colors1 = [];
var shapes1 =[];
var numbers1= [];
var self = this;
var cartes = self.cards0;
var cartes1 = cartes;
var carte1;
var carte2;
var i, j, a;
var colorsall= $.map(this.cards0, function(el) { return el.color;});
var shapesall = $.map(this.cards0, function(el) { return el.shape; });
var numbersall = $.map(this.cards0, function(el) { return el.number;});
for(i=0; i<cartes.length-1; i++) {
for (j = i+1; j < cartes1.length; j++) {
carte1 = cartes[i];
carte2 = cartes1[j];
colors1.splice(0,1,carte1.color);
colors1.splice(1,1,carte2.color);
shapes1.splice(0,1,carte1.shape);
shapes1.splice(1,1,carte2.shape);
numbers1.splice(0,1,carte1.number);
numbers1.splice(1,1,carte2.number);
if(colors1[0] === colors1 [1]){
colors1.splice(2,1,colors1[0]);
}
else{
if(colors1[0] === 'red' && colors1[1] === 'green'){
colors1.splice(2,1,'purple');
}
if(colors1[0] === 'red' && colors1[1] === 'purple'){
colors1.splice(2,1,'green');
}
if(colors1[0] === 'green' && colors1[1] === 'purple'){
colors1.splice(2,1,'red');
}
if(colors1[0] === 'green' && colors1[1] === 'red'){
colors1.splice(2,1,'purple');
}
if(colors1[0] === 'purple' && colors1[1] === 'red'){
colors1.splice(2,1,'green');
}
if(colors1[0] === 'purple' && colors1[1] === 'green'){
colors1.splice(2,1,'red');
}
}
if(shapes1[0] === shapes1 [1]){
shapes1.splice(2,1,shapes1[0]);
}
else{
if(shapes1[0] === 'oval' && shapes1[1] === 'diamond'){
shapes1.splice(2,1,'wave');
}
if(shapes1[0] === 'oval' && shapes1[1] === 'wave'){
shapes1.splice(2,1,'diamond');
}
if(shapes1[0] === 'diamond' && shapes1[1] === 'oval'){
shapes1.splice(2,1,'wave');
}
if(shapes1[0] === 'diamond' && shapes1[1] === 'wave'){
shapes1.splice(2,1,'oval');
}
if(shapes1[0] === 'wave' && shapes1[1] === 'diamond'){
shapes1.splice(2,1,'oval');
}
if(shapes1[0] === 'wave' && shapes1[1] === 'oval'){
shapes1.splice(2,1,'diamond');
}
}
if(numbers1[0] === numbers1[1]){
numbers1.splice(2,1,numbers1[0]);
}
else{
if(numbers1[0] === 1 && numbers1[1] === 2){
numbers1.splice(2,1,3);
}
if(numbers1[0] === 1 && numbers1[1] === 3){
numbers1.splice(2,1,2);
}
if(numbers1[0] === 2 && numbers1[1] === 1){
numbers1.splice(2,1,3);
}
if(numbers1[0] === 2 && numbers1[1] === 3){
numbers1.splice(2,1,1);
}
if(numbers1[0] === 3 && numbers1[1] === 1){
numbers1.splice(2,1,2);
}
if(numbers1[0] === 3 && numbers1[1] === 2){
numbers1.splice(2,1,1);
}
}
for (a = j+1; a<this.cards0.length; a++) {
if (shapes1[2] === shapesall[a] && colors1[2] === colorsall[a] && numbers1[2] === numbersall[a]) {
if (this.isSet(shapes1) && this.isSet(colors1) && this.isSet(numbers1)) {
self.set0 = self.set0 + 1;
}
}
}
}
}
this.$nbSets0.html(self.set0);
},
existingSet1: function() {
var colors1 = [];
var shapes1 =[];
var fills1= [];
var borders1= [];
var numbers1= [];
var self = this;
var cartes = self.cards1;
var cartes1 = cartes;
var carte1;
var carte2;
var i, j, a;
var colorsall= $.map(this.cards1, function(el) { return el.color;});
var shapesall = $.map(this.cards1, function(el) { return el.shape; });
var fillsall= $.map(this.cards1,function(el) { return el.fill; });
var bordersall= $.map(this.cards1,function(el) { return el.border; });
var numbersall = $.map(this.cards1, function(el) { return el.number;});
for(i=0; i<cartes.length-1; i++) {
for (j = i+1; j < cartes1.length; j++) {
carte1 = cartes[i];
carte2 = cartes1[j];
colors1.splice(0,1,carte1.color);
colors1.splice(1,1,carte2.color);
shapes1.splice(0,1,carte1.shape);
shapes1.splice(1,1,carte2.shape);
fills1.splice(0,1,carte1.fill);
fills1.splice(1,1,carte2.fill);
borders1.splice(0,1,carte1.border);
borders1.splice(1,1,carte2.border);
numbers1.splice(0,1,carte1.number);
numbers1.splice(1,1,carte2.number);
if(colors1[0] === colors1 [1]){
colors1.splice(2,1,colors1[0]);
}
else{
if(colors1[0] === 'red' && colors1[1] === 'green'){
colors1.splice(2,1,'purple');
}
if(colors1[0] === 'red' && colors1[1] === 'purple'){
colors1.splice(2,1,'green');
}
if(colors1[0] === 'green' && colors1[1] === 'purple'){
colors1.splice(2,1,'red');
}
if(colors1[0] === 'green' && colors1[1] === 'red'){
colors1.splice(2,1,'purple');
}
if(colors1[0] === 'purple' && colors1[1] === 'red'){
colors1.splice(2,1,'green');
}
if(colors1[0] === 'purple' && colors1[1] === 'green'){
colors1.splice(2,1,'red');
}
}
if(shapes1[0] === shapes1 [1]){
shapes1.splice(2,1,shapes1[0]);
}
else{
if(shapes1[0] === 'oval' && shapes1[1] === 'diamond'){
shapes1.splice(2,1,'wave');
}
if(shapes1[0] === 'oval' && shapes1[1] === 'wave'){
shapes1.splice(2,1,'diamond');
}
if(shapes1[0] === 'diamond' && shapes1[1] === 'oval'){
shapes1.splice(2,1,'wave');
}
if(shapes1[0] === 'diamond' && shapes1[1] === 'wave'){
shapes1.splice(2,1,'oval');
}
if(shapes1[0] === 'wave' && shapes1[1] === 'diamond'){
shapes1.splice(2,1,'oval');
}
if(shapes1[0] === 'wave' && shapes1[1] === 'oval'){
shapes1.splice(2,1,'diamond');
}
}
if(fills1[0] === fills1 [1]){
fills1.splice(2,1,fills1[0]);
}
else{
if(fills1[0] === 'solid' && fills1[1] === 'stripped'){
fills1.splice(2,1,'open');
}
if(fills1[0] === 'solid' && fills1[1] === 'open'){
fills1.splice(2,1,'stripped');
}
if(fills1[0] === 'stripped' && fills1[1] === 'open'){
fills1.splice(2,1,'solid');
}
if(fills1[0] === 'open' && fills1[1] === 'stripped'){
fills1.splice(2,1,'solid');
}
if(fills1[0] === 'stripped' && fills1[1] === 'solid'){
fills1.splice(2,1,'open');
}
if(fills1[0] === 'open' && fills1[1] === 'solid'){
fills1.splice(2,1,'stripped');
}
}
if(borders1[0] === borders1 [1]){
borders1.splice(2,1,borders1[0]);
}
else{
if(borders1[0] === 'plein' && borders1[1] === 'point'){
borders1.splice(2,1,'rond');
}
if(borders1[0] === 'point' && borders1[1] === 'plein'){
borders1.splice(2,1,'rond');
}
if(borders1[0] === 'rond' && borders1[1] === 'plein'){
borders1.splice(2,1,'point');
}
if(borders1[0] === 'plein' && borders1[1] === 'rond'){
borders1.splice(2,1,'point');
}
if(borders1[0] === 'rond' && borders1[1] === 'point'){
borders1.splice(2,1,'plein');
}
if(borders1[0] === 'point' && borders1[1] === 'rond'){
borders1.splice(2,1,'plein');
}
}
if(numbers1[0] === numbers1[1]){
numbers1.splice(2,1,numbers1[0]);
}
else{
if(numbers1[0] === 1 && numbers1[1] === 2){
numbers1.splice(2,1,3);
}
if(numbers1[0] === 1 && numbers1[1] === 3){
numbers1.splice(2,1,2);
}
if(numbers1[0] === 2 && numbers1[1] === 1){
numbers1.splice(2,1,3);
}
if(numbers1[0] === 2 && numbers1[1] === 3){
numbers1.splice(2,1,1);
}
if(numbers1[0] === 3 && numbers1[1] === 1){
numbers1.splice(2,1,2);
}
if(numbers1[0] === 3 && numbers1[1] === 2){
numbers1.splice(2,1,1);
}
}
for (a = j+1; a<this.cards1.length; a++) {
if (shapes1[2] === shapesall[a] && colors1[2] === colorsall[a] && fills1[2] === fillsall[a] && borders1[2] === bordersall[a] && numbers1[2] === numbersall[a]) {
if (this.isSet(shapes1) && this.isSet(colors1) && this.isSet(fills1) && this.isSet(borders1) && this.isSet(numbers1)) {
console.log(shapes1, colors1, fills1, borders1, numbers1);
self.set1 = self.set1 + 1;
}
}
}
}
}
this.$nbSets1.html(self.set1);
},
existingSet2: function() {
var colors1 = [];
var shapes1 =[];
var fills1= [];
var numbers1= [];
var self = this;
var cartes = self.cards2;
var cartes1 = cartes;
var cartes2 = cartes;
var carte1, carte3;
var carte2;
var i, j, a, k;
var colorsall= $.map(this.cards2, function(el) { return el.color;});
var shapesall = $.map(this.cards2, function(el) { return el.shape; });
var fillsall= $.map(this.cards2,function(el) { return el.fill; });
var numbersall = $.map(this.cards2, function(el) { return el.number;});
for(i=0; i < cartes.length-2; i++) {
for (j = i + 1; j < cartes1.length - 1; j++) {
for (k = j + 1; k < cartes2.length; k++) {
carte1 = cartes[i];
carte2 = cartes1[j];
carte3 = cartes2[k];
colors1.splice(0, 1, carte1.color);
colors1.splice(1, 1, carte2.color);
colors1.splice(2, 1, carte3.color);
shapes1.splice(0, 1, carte1.shape);
shapes1.splice(1, 1, carte2.shape);
shapes1.splice(2, 1, carte3.shape);
fills1.splice(0, 1, carte1.fill);
fills1.splice(1, 1, carte2.fill);
fills1.splice(2, 1, carte3.fill);
numbers1.splice(0, 1, carte1.number);
numbers1.splice(1, 1, carte2.number);
numbers1.splice(2, 1, carte3.number);
if (colors1[0] === colors1[1] && colors1[0] === colors1[2]) {
colors1.splice(3,1,colors1[0]);
} else {
if (colors1[0] === 'red' && colors1[1] === 'green' && colors1[2] === 'purple') {
colors1.splice(3, 1, 'lightblue');
}
if (colors1[0] === 'red' && colors1[1] === 'purple' && colors1[2] === 'green') {
colors1.splice(3, 1, 'lightblue');
}
if (colors1[0] === 'purple' && colors1[1] === 'red' && colors1[2] === 'green') {
colors1.splice(3, 1, 'lightblue');
}
if (colors1[0] === 'purple' && colors1[1] === 'green' && colors1[2] === 'red') {
colors1.splice(3, 1, 'lightblue');
}
if (colors1[0] === 'green' && colors1[1] === 'purple' && colors1[2] === 'red') {
colors1.splice(3, 1, 'lightblue');
}
if (colors1[0] === 'green' && colors1[1] === 'red' && colors1[2] === 'purple') {
colors1.splice(3, 1, 'lightblue');
}
if (colors1[0] === 'green' && colors1[1] === 'purple' && colors1[2] === 'lightblue') {
colors1.splice(3, 1, 'red');
}
if (colors1[0] === 'green' && colors1[1] === 'lightblue' && colors1[2] === 'purple') {
colors1.splice(3, 1, 'red');
}
if (colors1[0] === 'purple' && colors1[1] === 'lightblue' && colors1[2] === 'green') {
colors1.splice(3, 1, 'red');
}
if (colors1[0] === 'purple' && colors1[1] === 'green' && colors1[2] === 'lightblue') {
colors1.splice(3, 1, 'red');
}
if (colors1[0] === 'lightblue' && colors1[1] === 'purple' && colors1[2] === 'green') {
colors1.splice(3, 1, 'red');
}
if (colors1[0] === 'lightblue' && colors1[1] === 'green' && colors1[2] === 'purple') {
colors1.splice(3, 1, 'red');
}
if (colors1[0] === 'red' && colors1[1] === 'green' && colors1[2] === 'lightblue') {
colors1.splice(3, 1, 'purple');
}
if (colors1[0] === 'red' && colors1[1] === 'lightblue' && colors1[2] === 'green') {
colors1.splice(3, 1, 'purple');
}
if (colors1[0] === 'lightblue' && colors1[1] === 'green' && colors1[2] === 'red') {
colors1.splice(3, 1, 'purple');
}
if (colors1[0] === 'lightblue' && colors1[1] === 'red' && colors1[2] === 'green') {
colors1.splice(3, 1, 'purple');
}
if (colors1[0] === 'green' && colors1[1] === 'lightblue' && colors1[2] === 'red') {
colors1.splice(3, 1, 'purple');
}
if (colors1[0] === 'green' && colors1[1] === 'red' && colors1[2] === 'lightblue') {
colors1.splice(3, 1, 'purple');
}
if (colors1[0] === 'red' && colors1[1] === 'purple' && colors1[2] === 'lightblue') {
colors1.splice(3, 1, 'green');
}
if (colors1[0] === 'red' && colors1[1] === 'lightblue' && colors1[2] === 'purple') {
colors1.splice(3, 1, 'green');
}
if (colors1[0] === 'lightblue' && colors1[1] === 'purple' && colors1[2] === 'red') {
colors1.splice(3, 1, 'green');
}
if (colors1[0] === 'lightblue' && colors1[1] === 'red' && colors1[2] === 'purple') {
colors1.splice(3, 1, 'green');
}
if (colors1[0] === 'purple' && colors1[1] === 'lightblue' && colors1[2] === 'red') {
colors1.splice(3, 1, 'green');
}
if (colors1[0] === 'purple' && colors1[1] === 'red' && colors1[2] === 'lightblue') {
colors1.splice(3, 1, 'green');
}
}
if (shapes1[0] === shapes1 [1] && shapes1[0] === shapes1 [2]) {
shapes1.splice(3, 1, shapes1[0]);
} else {
if (shapes1[0] === 'oval' && shapes1[1] === 'diamond' && shapes1[2] === 'wave') {
shapes1.splice(3, 1, 'rectangle');
}
if (shapes1[0] === 'oval' && shapes1[1] === 'wave' && shapes1[2] === 'diamond') {
shapes1.splice(3, 1, 'rectangle');
}
if (shapes1[0] === 'wave' && shapes1[1] === 'diamond' && shapes1[2] === 'oval') {
shapes1.splice(3, 1, 'rectangle');
}
if (shapes1[0] === 'wave' && shapes1[1] === 'oval' && shapes1[2] === 'diamond') {
shapes1.splice(3, 1, 'rectangle');
}
if (shapes1[0] === 'diamond' && shapes1[1] === 'oval' && shapes1[2] === 'wave') {
shapes1.splice(3, 1, 'rectangle');
}
if (shapes1[0] === 'diamond' && shapes1[1] === 'wave' && shapes1[2] === 'oval') {
shapes1.splice(3,1,'rectangle');
}
if (shapes1[0] === 'oval' && shapes1[1] === 'diamond' && shapes1[2] === 'rectangle') {
shapes1.splice(3, 1, 'wave');
}
if (shapes1[0] === 'oval' && shapes1[1] === 'rectangle' && shapes1[2] === 'diamond') {
shapes1.splice(3, 1, 'wave');
}
if (shapes1[0] === 'rectangle' && shapes1[1] === 'oval' && shapes1[2] === 'diamond') {
shapes1.splice(3, 1, 'wave');
}
if (shapes1[0] === 'rectangle' && shapes1[1] === 'diamond' && shapes1[2] === 'oval') {
shapes1.splice(3, 1, 'wave');
}
if (shapes1[0] === 'diamond' && shapes1[1] === 'oval' && shapes1[2] === 'rectangle') {
shapes1.splice(3, 1, 'wave');
}
if (shapes1[0] === 'diamond' && shapes1[1] === 'rectangle' && shapes1[2] === 'oval') {
shapes1.splice(3, 1, 'wave');
}
if (shapes1[0] === 'oval' && shapes1[1] === 'wave' && shapes1[2] === 'rectangle') {
shapes1.splice(3, 1, 'diamond');
}
if (shapes1[0] === 'oval' && shapes1[1] === 'rectangle' && shapes1[2] === 'wave') {
shapes1.splice(3, 1, 'diamond');
}
if (shapes1[0] === 'rectangle' && shapes1[1] === 'wave' && shapes1[2] === 'oval') {
shapes1.splice(3, 1, 'diamond');
}
if (shapes1[0] === 'rectangle' && shapes1[1] === 'oval' && shapes1[2] === 'wave') {
shapes1.splice(3,1,'diamond');
}
if (shapes1[0] === 'wave' && shapes1[1] === 'oval' && shapes1[2] === 'rectangle') {
shapes1.splice(3, 1, 'diamond');
}
if (shapes1[0] === 'wave' && shapes1[1] === 'rectangle' && shapes1[2] === 'oval') {
shapes1.splice(3, 1, 'diamond');
}
if (shapes1[0] === 'diamond' && shapes1[1] === 'wave' && shapes1[2] === 'rectangle') {
shapes1.splice(3, 1, 'oval');
}
if (shapes1[0] === 'diamond' && shapes1[1] === 'rectangle' && shapes1[2] === 'wave') {
shapes1.splice(3, 1, 'oval');
}
if (shapes1[0] === 'rectangle' && shapes1[1] === 'wave' && shapes1[2] === 'diamond') {
shapes1.splice(3, 1, 'oval');
}
if (shapes1[0] === 'rectangle' && shapes1[1] === 'diamond' && shapes1[2] === 'wave') {
shapes1.splice(3, 1, 'oval');
}
if (shapes1[0] === 'wave' && shapes1[1] === 'diamond' && shapes1[2] === 'rectangle') {
shapes1.splice(3, 1, 'oval');
}
if (shapes1[0] === 'wave' && shapes1[1] === 'rectangle' && shapes1[2] === 'diamond') {
shapes1.splice(3, 1, 'oval');
}
}
if (fills1[0] === fills1 [1] && fills1[0] === fills1 [2]) {
fills1.splice(3, 1, fills1[0]);
} else {
if (fills1[0] === 'solid' && fills1[1] === 'stripped' && fills1[2] === 'open') {
fills1.splice(3, 1, 'quadrillage');
}
if (fills1[0] === 'solid' && fills1[1] === 'open' && fills1[2] === 'stripped') {
fills1.splice(3, 1, 'quadrillage');
}
if (fills1[0] === 'stripped' && fills1[1] === 'open' && fills1[2] === 'solid') {
fills1.splice(3, 1, 'quadrillage');
}
if (fills1[0] === 'stripped' && fills1[1] === 'solid' && fills1[2] === 'open') {
fills1.splice(3, 1, 'quadrillage');
}
if (fills1[0] === 'open' && fills1[1] === 'stripped' && fills1[2] === 'solid') {
fills1.splice(3, 1, 'quadrillage');
}
if (fills1[0] === 'open' && fills1[1] === 'solid' && fills1[2] === 'stripped') {
fills1.splice(3, 1, 'quadrillage');
}
if (fills1[0] === 'solid' && fills1[1] === 'stripped' && fills1[2] === 'quadrillage') {
fills1.splice(3, 1, 'open');
}
if (fills1[0] === 'solid' && fills1[1] === 'quadrillage' && fills1[2] === 'stripped') {
fills1.splice(3, 1, 'open');
}
if (fills1[0] === 'quadrillage' && fills1[1] === 'solid' && fills1[2] === 'stripped') {
fills1.splice(3, 1, 'open');
}
if (fills1[0] === 'quadrillage' && fills1[1] === 'stripped' && fills1[2] === 'solid') {
fills1.splice(3, 1, 'open');
}
if (fills1[0] === 'stripped' && fills1[1] === 'quadrillage' && fills1[2] === 'solid') {
fills1.splice(3, 1, 'open');
}
if (fills1[0] === 'stripped' && fills1[1] === 'solid' && fills1[2] === 'quadrillage') {
fills1.splice(3, 1, 'open');
}
if (fills1[0] === 'solid' && fills1[1] === 'open' && fills1[2] === 'quadrillage') {
fills1.splice(3, 1, 'stripped');
}
if (fills1[0] === 'solid' && fills1[1] === 'quadrillage' && fills1[2] === 'open') {
fills1.splice(3, 1, 'stripped');
}
if (fills1[0] === 'quadrillage' && fills1[1] === 'solid' && fills1[2] === 'open') {
fills1.splice(3, 1, 'stripped');
}
if (fills1[0] === 'quadrillage' && fills1[1] === 'open' && fills1[2] === 'solid') {
fills1.splice(3, 1, 'stripped');
}
if (fills1[0] === 'open' && fills1[1] === 'quadrillage' && fills1[2] === 'solid') {
fills1.splice(3, 1, 'stripped');
}
if (fills1[0] === 'open' && fills1[1] === 'solid' && fills1[2] === 'quadrillage') {
fills1.splice(3, 1, 'stripped');
}
if (fills1[0] === 'stripped' && fills1[1] === 'open' && fills1[2] === 'quadrillage') {
fills1.splice(3, 1, 'solid');
}
if (fills1[0] === 'stripped' && fills1[1] === 'quadrillage' && fills1[2] === 'open') {
fills1.splice(3, 1, 'solid');
}
if (fills1[0] === 'quadrillage' && fills1[1] === 'stripped' && fills1[2] === 'open') {
fills1.splice(3, 1, 'solid');
}
if (fills1[0] === 'quadrillage' && fills1[1] === 'open' && fills1[2] === 'stripped') {
fills1.splice(3, 1, 'solid');
}
if (fills1[0] === 'open' && fills1[1] === 'quadrillage' && fills1[2] === 'stripped') {
fills1.splice(3, 1, 'solid');
}
if (fills1[0] === 'open' && fills1[1] === 'stripped' && fills1[2] === 'quadrillage') {
fills1.splice(3, 1, 'solid');
}
}
if (numbers1[0] === numbers1[1] && numbers1[0] === numbers1[2]) {
numbers1.splice(3, 1, numbers1[0]);
} else {
if (numbers1[0] === 1 && numbers1[1] === 2 && numbers1[2] === 3) {
numbers1.splice(3, 1, 4);
}
if (numbers1[0] === 1 && numbers1[1] === 3 && numbers1[2] === 2) {
numbers1.splice(3, 1, 4);
}
if (numbers1[0] === 2 && numbers1[1] === 1 && numbers1[2] === 3) {
numbers1.splice(3, 1, 4);
}
if (numbers1[0] === 2 && numbers1[1] === 3 && numbers1[2] === 1) {
numbers1.splice(3, 1, 4);
}
if (numbers1[0] === 3 && numbers1[1] === 1 && numbers1[2] === 2) {
numbers1.splice(3, 1, 4);
}
if (numbers1[0] === 3 && numbers1[1] === 2 && numbers1[2] === 1) {
numbers1.splice(3, 1, 4);
}
if (numbers1[0] === 1 && numbers1[1] === 2 && numbers1[2] === 4) {
numbers1.splice(3, 1, 3);
}
if (numbers1[0] === 1 && numbers1[1] === 4 && numbers1[2] === 2) {
numbers1.splice(3, 1, 3);
}
if (numbers1[0] === 2 && numbers1[1] === 1 && numbers1[2] === 4) {
numbers1.splice(3, 1, 3);
}
if (numbers1[0] === 2 && numbers1[1] === 4 && numbers1[2] === 1) {
numbers1.splice(3, 1, 3);
}
if (numbers1[0] === 4 && numbers1[1] === 1 && numbers1[2] === 2) {
numbers1.splice(3, 1, 3);
}
if (numbers1[0] === 4 && numbers1[1] === 2 && numbers1[2] === 1) {
numbers1.splice(3, 1, 3);
}
if (numbers1[0] === 1 && numbers1[1] === 3 && numbers1[2] === 4) {
numbers1.splice(3, 1, 2);
}
if (numbers1[0] === 1 && numbers1[1] === 4 && numbers1[2] === 3) {
numbers1.splice(3, 1, 2);
}
if (numbers1[0] === 3 && numbers1[1] === 1 && numbers1[2] === 4) {
numbers1.splice(3, 1, 2);
}
if (numbers1[0] === 3 && numbers1[1] === 4 && numbers1[2] === 1) {
numbers1.splice(3, 1, 2);
}
if (numbers1[0] === 4 && numbers1[1] === 1 && numbers1[2] === 3) {
numbers1.splice(3, 1, 2);
}
if (numbers1[0] === 4 && numbers1[1] === 3 && numbers1[2] === 1) {
numbers1.splice(3, 1, 2);
}
if (numbers1[0] === 2 && numbers1[1] === 3 && numbers1[2] === 4) {
numbers1.splice(3, 1, 1);
}
if (numbers1[0] === 2 && numbers1[1] === 4 && numbers1[2] === 3) {
numbers1.splice(3, 1, 1);
}
if (numbers1[0] === 3 && numbers1[1] === 2 && numbers1[2] === 4) {
numbers1.splice(3, 1, 1);
}
if (numbers1[0] === 3 && numbers1[1] === 4 && numbers1[2] === 2) {
numbers1.splice(3, 1, 1);
}
if (numbers1[0] === 4 && numbers1[1] === 2 && numbers1[2] === 3) {
numbers1.splice(3, 1, 1);
}
if (numbers1[0] === 4 && numbers1[1] === 3 && numbers1[2] === 2) {
numbers1.splice(3, 1, 1);
}
}
for (a = k + 1; a < self.cards2.length; a++) {
if (shapes1[3] === shapesall[a] && colors1[3] === colorsall[a] && fills1[3] === fillsall[a] && numbers1[3] === numbersall[a]) {
if (this.isSet4(shapes1) && this.isSet4(colors1) && this.isSet4(fills1) && this.isSet4(numbers1)) {
self.set2 = self.set2 + 1;
}
}
}
}
}
}
this.$nbSets2.html(self.set2);
},
setCardListeners0: function() {
var self = this;
// what happens when a card is clicked:
this.$board0.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selected0, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCard0(card);
} else {
self.selectCard0(card);
}
if (self.selected0.length === 3) {
self.silentSubmission0();
}
});
},
setCardListeners: function() {
var self = this;
// what happens when a card is clicked:
this.$board.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selected, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCard(card);
} else {
self.selectCard(card);
}
if (self.selected.length === 3) {
self.silentSubmission();
}
});
},
setCardListeners1: function() {
var self = this;
// what happens when a card is clicked:
this.$board1.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selected1, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCard1(card);
} else {
self.selectCard1(card);
}
if (self.selected1.length === 3) {
self.silentSubmission1();
}
});
},
setCardListeners2: function() {
var self = this;
// what happens when a card is clicked:
this.$board2.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selected2, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCard2(card);
} else {
self.selectCard2(card);
}
if (self.selected2.length === 4) {
self.silentSubmission2();
}
});
},
setCardListeners3: function() {
var self = this;
// what happens when a card is clicked:
this.$board3.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selected3, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCard3(card);
} else {
self.selectCard3(card);
}
if (self.selected3.length === 4) {
self.silentSubmission3();
}
});
},
setCardListeners4: function() {
var self = this;
// what happens when a card is clicked:
this.$board4.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selected4, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCard4(card);
} else {
self.selectCard4(card);
}
if (self.selected4.length === 5) {
self.silentSubmission4();
}
});
},
setCardListenersHS: function() {
var self = this;
// what happens when a card is clicked:
this.$boardHS.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selectedHS, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCardHS(card);
} else {
self.selectCardHS(card);
}
if (self.selectedHS.length === 4) {
self.silentSubmissionHS();
}
});
},
setCardListenersHS0: function() {
var self = this;
// what happens when a card is clicked:
this.$boardHS0.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selectedHS0, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCardHS0(card);
} else {
self.selectCardHS0(card);
}
if (self.selectedHS0.length === 4) {
self.silentSubmissionHS0();
}
});
},
setCardListenersHS1: function() {
var self = this;
// what happens when a card is clicked:
this.$boardHS1.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selectedHS1, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCardHS1(card);
} else {
self.selectCardHS1(card);
}
if (self.selectedHS1.length === 4) {
self.silentSubmissionHS1();
}
});
},
setCardListenersHS2: function() {
var self = this;
// what happens when a card is clicked:
this.$boardHS2.on('click', '.card', function(e) {
e.stopImmediatePropagation();
var card = e.currentTarget;
// if card is new, add it, otherwise remove it
var ids = $.map(self.selectedHS2, function(el) { return $(el).data("id");});
if (ids.indexOf($(card).data('id')) >= 0) {
self.deselectCardHS2(card);
} else {
self.selectCardHS2(card);
}
if (self.selectedHS2.length === 6) {
self.silentSubmissionHS2();
}
});
},
setPageListeners0: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelections0.call(self);
});
},
setPageListeners: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelections.call(self);
});
},
setPageListeners1: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelections1.call(self);
});
},
setPageListeners2: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelections2.call(self);
});
},
setPageListeners3: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelections3.call(self);
});
},
setPageListeners4: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelections4.call(self);
});
},
setPageListenersHS: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelectionsHS.call(self);
});
},
setPageListenersHS0: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelectionsHS0.call(self);
});
},
setPageListenersHS1: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelectionsHS1.call(self);
});
},
setPageListenersHS2: function() {
var self = this;
// if the user clicks on the page outside the game board, clear selected
$(document).on('click', function() {
self.clearSelectionsHS2.call(self);
});
},
selectCard0: function(card) {
if (this.selected0.length < 3) {
$(card).addClass('selected');
this.selected0.push(card);
}
},
selectCard: function(card) {
if (this.selected.length < 3) {
$(card).addClass('selected');
this.selected.push(card);
}
},
selectCard1: function(card) {
if (this.selected1.length < 3) {
$(card).addClass('selected');
this.selected1.push(card);
}
},
selectCard2: function(card) {
if (this.selected2.length < 4) {
$(card).addClass('selected');
this.selected2.push(card);
}
},
selectCard3: function(card) {
if (this.selected3.length < 4) {
$(card).addClass('selected');
this.selected3.push(card);
}
},
selectCard4: function(card) {
if (this.selected4.length < 5) {
$(card).addClass('selected');
this.selected4.push(card);
}
},
selectCardHS: function(card) {
if (this.selectedHS.length < 4) {
$(card).addClass('selected');
this.selectedHS.push(card);
}
},
selectCardHS0: function(card) {
if (this.selectedHS0.length < 4) {
$(card).addClass('selected');
this.selectedHS0.push(card);
}
},
selectCardHS1: function(card) {
if (this.selectedHS1.length < 4) {
$(card).addClass('selected');
this.selectedHS1.push(card);
}
},
selectCardHS2: function(card) {
if (this.selectedHS2.length < 6) {
$(card).addClass('selected');
this.selectedHS2.push(card);
}
},
deselectCard0: function(card) {
var self = this;
var index = self.selected0.indexOf(card);
if (index > -1) {
self.selected0.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCard: function(card) {
var self = this;
var index = self.selected.indexOf(card);
if (index > -1) {
self.selected.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCard1: function(card) {
var self = this;
var index = self.selected1.indexOf(card);
if (index > -1) {
self.selected1.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCard2: function(card) {
var self = this;
var index = self.selected2.indexOf(card);
if (index > -1) {
self.selected2.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCard3: function(card) {
var self = this;
var index = self.selected3.indexOf(card);
if (index > -1) {
self.selected3.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCard4: function(card) {
var self = this;
var index = self.selected4.indexOf(card);
if (index > -1) {
self.selected4.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCardHS: function(card) {
var self = this;
var index = self.selectedHS.indexOf(card);
if (index > -1) {
self.selectedHS.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCardHS0: function(card) {
var self = this;
var index = self.selectedHS0.indexOf(card);
if (index > -1) {
self.selectedHS0.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCardHS1: function(card) {
var self = this;
var index = self.selectedHS1.indexOf(card);
if (index > -1) {
self.selectedHS1.splice(index, 1);
}
$(card).removeClass('selected');
},
deselectCardHS2: function(card) {
var self = this;
var index = self.selectedHS2.indexOf(card);
if (index > -1) {
self.selectedHS2.splice(index, 1);
}
$(card).removeClass('selected');
},
clearSelections0: function() {
$.each(this.selected0, function(index, card) {
$(card).removeClass('selected');
});
this.selected0 = [];
},
clearSelections: function() {
$.each(this.selected, function(index, card) {
$(card).removeClass('selected');
});
this.selected = [];
},
clearSelections1: function() {
$.each(this.selected1, function(index, card) {
$(card).removeClass('selected');
});
this.selected1 = [];
},
clearSelections2: function() {
$.each(this.selected2, function(index, card) {
$(card).removeClass('selected');
});
this.selected2 = [];
},
clearSelections3: function() {
$.each(this.selected3, function(index, card) {
$(card).removeClass('selected');
});
this.selected3 = [];
},
clearSelections4: function() {
$.each(this.selected4, function(index, card) {
$(card).removeClass('selected');
});
this.selected4 = [];
},
clearSelectionsHS: function() {
$.each(this.selectedHS, function(index, card) {
$(card).removeClass('selected');
});
this.selectedHS = [];
},
clearSelectionsHS0: function() {
$.each(this.selectedHS0, function(index, card) {
$(card).removeClass('selected');
});
this.selectedHS0 = [];
},
clearSelectionsHS1: function() {
$.each(this.selectedHS1, function(index, card) {
$(card).removeClass('selected');
});
this.selectedHS1 = [];
},
clearSelectionsHS2: function() {
$.each(this.selectedHS2, function(index, card) {
$(card).removeClass('selected');
});
this.selectedHS2 = [];
},
// cards1 combinaison ab, cards2 combinaison cd, selectedCards(taille toujours 2) pré-effectuer les combinaison 0 et 1, 0 et 2, 0 et 3...
generateVirtualCard34: function(cards1, cards2){
var colors2= $.map(cards1, function(el) { return $(el).data("color");});
var shapes2 = $.map(cards1, function(el) { return $(el).data("shape");});
var fills2 = $.map(cards1, function(el) { return $(el).data("fills");});
var numbers2 = $.map(cards1, function(el) { return $(el).data("number");});
var colors3= $.map(cards2, function(el) { return $(el).data("color");});
var shapes3 = $.map(cards2, function(el) { return $(el).data("shape");});
var fills3 = $.map(cards2, function(el) { return $(el).data("fills");});
var numbers3 = $.map(cards2, function(el) { return $(el).data("number");});
if(colors2[0] === colors2 [1]){
colors2.push(colors2[0]);
colors3.push(colors2[0]);
}
else{
if(colors2[0] === 'red' && colors2[1] === 'green'){
colors3.push('purple');
colors2.push('purple');
}
if(colors2[0] === 'red' && colors2[1] === 'purple'){
colors3.push('green');
colors2.push('green');
}
if(colors2[0] === 'green' && colors2[1] === 'purple'){
colors3.push('red');
colors2.push('red');
}
if(colors2[0] === 'green' && colors2[1] === 'red'){
colors3.push('purple');
colors2.push('purple');
}
if(colors2[0] === 'purple' && colors2[1] === 'red'){
colors3.push('green');
colors2.push('green');
}
if(colors2[0] === 'purple' && colors2[1] === 'green'){
colors3.push('red');
colors2.push('red');
}
}
if(shapes2[0] === shapes2 [1]){
shapes3.push(shapes2[0]);
shapes2.push(shapes2[0]);
}
else{
if(shapes2[0] === 'oval' && shapes2[1] === 'diamond'){
shapes3.push('wave');
shapes2.push('wave');
}
if(shapes2[0] === 'oval' && shapes2[1] === 'wave'){
shapes3.push('diamond');
shapes2.push('diamond');
}
if(shapes2[0] === 'diamond' && shapes2[1] === 'oval'){
shapes3.push('wave');
shapes2.push('wave');
}
if(shapes2[0] === 'diamond' && shapes2[1] === 'wave'){
shapes3.push('oval');
shapes2.push('oval');
}
if(shapes2[0] === 'wave' && shapes2[1] === 'diamond'){
shapes3.push('oval');
shapes2.push('oval');
}
if(shapes2[0] === 'wave' && shapes2[1] === 'oval'){
shapes3.push('diamond');
shapes2.push('diamond');
}
}
if(fills2[0] === fills2 [1]){
fills3.push(fills2[0]);
fills2.push(fills2[0]);
}
else{
if(fills2[0] === 'solid' && fills2[1] === 'stripped'){
fills3.push('open');
fills2.push('open');
}
if(fills2[0] === 'solid' && fills2[1] === 'open'){
fills3.push('stripped');
fills2.push('stripped');
}
if(fills2[0] === 'stripped' && fills2[1] === 'open'){
fills3.push('solid');
fills2.push('solid');
}
if(fills2[0] === 'open' && fills2[1] === 'stripped'){
fills3.push('solid');
fills2.push('solid');
}
if(fills2[0] === 'stripped' && fills2[1] === 'solid'){
fills3.push('open');
fills2.push('open');
}
if(fills2[0] === 'open' && fills2[1] === 'solid'){
fills3.push('stripped');
fills2.push('stripped');
}
}
if(numbers2[0] === numbers2[1]){
numbers3.push(numbers2[0]);
numbers2.push(numbers2[0]);
}
else{
if(numbers2[0] === 1 && numbers2[1] === 2){
numbers3.push(3);
numbers2.push(3);
}
if(numbers2[0] === 1 && numbers2[1] === 3){
numbers3.push(2);
numbers2.push(2);
}
if(numbers2[0] === 2 && numbers2[1] === 1){
numbers3.push(3);
numbers2.push(3);
}
if(numbers2[0] === 2 && numbers2[1] === 3){
numbers3.push(1);
numbers2.push(1);
}
if(numbers2[0] === 3 && numbers2[1] === 1){
numbers3.push(2);
numbers2.push(2);
}
if(numbers2[0] === 3 && numbers2[1] === 2){
numbers3.push(1);
numbers2.push(1);
}
}
if(this.isSet(colors2) && this.isSet(shapes2) && this.isSet(fills2) && this.isSet(numbers2)) {
return this.isSet(colors3) && this.isSet(shapes3) && this.isSet(fills3) && this.isSet(numbers3)
}
},
generateVirtualCard33: function(cards1, cards2){
var colors2= $.map(cards1, function(el) { return $(el).data("color");});
var shapes2 = $.map(cards1, function(el) { return $(el).data("shape");});
var numbers2 = $.map(cards1, function(el) { return $(el).data("number");});
var colors3= $.map(cards2, function(el) { return $(el).data("color");});
var shapes3 = $.map(cards2, function(el) { return $(el).data("shape");});
var numbers3 = $.map(cards2, function(el) { return $(el).data("number");});
if(colors2[0] === colors2 [1]){
colors2.push(colors2[0]);
colors3.push(colors2[0]);
}
else{
if(colors2[0] === 'red' && colors2[1] === 'green'){
colors3.push('purple');
colors2.push('purple');
}
if(colors2[0] === 'red' && colors2[1] === 'purple'){
colors3.push('green');
colors2.push('green');
}
if(colors2[0] === 'green' && colors2[1] === 'purple'){
colors3.push('red');
colors2.push('red');
}
if(colors2[0] === 'green' && colors2[1] === 'red'){
colors3.push('purple');
colors2.push('purple');
}
if(colors2[0] === 'purple' && colors2[1] === 'red'){
colors3.push('green');
colors2.push('green');
}
if(colors2[0] === 'purple' && colors2[1] === 'green'){
colors3.push('red');
colors2.push('red');
}
}
if(shapes2[0] === shapes2 [1]){
shapes3.push(shapes2[0]);
shapes2.push(shapes2[0]);
}
else{
if(shapes2[0] === 'oval' && shapes2[1] === 'diamond'){
shapes3.push('wave');
shapes2.push('wave');
}
if(shapes2[0] === 'oval' && shapes2[1] === 'wave'){
shapes3.push('diamond');
shapes2.push('diamond');
}
if(shapes2[0] === 'diamond' && shapes2[1] === 'oval'){
shapes3.push('wave');
shapes2.push('wave');
}
if(shapes2[0] === 'diamond' && shapes2[1] === 'wave'){
shapes3.push('oval');
shapes2.push('oval');
}
if(shapes2[0] === 'wave' && shapes2[1] === 'diamond'){
shapes3.push('oval');
shapes2.push('oval');
}
if(shapes2[0] === 'wave' && shapes2[1] === 'oval'){
shapes3.push('diamond');
shapes2.push('diamond');
}
}
if(numbers2[0] === numbers2[1]){
numbers3.push(numbers2[0]);
numbers2.push(numbers2[0]);
}
else{
if(numbers2[0] === 1 && numbers2[1] === 2){
numbers3.push(3);
numbers2.push(3);
}
if(numbers2[0] === 1 && numbers2[1] === 3){
numbers3.push(2);
numbers2.push(2);
}
if(numbers2[0] === 2 && numbers2[1] === 1){
numbers3.push(3);
numbers2.push(3);
}
if(numbers2[0] === 2 && numbers2[1] === 3){
numbers3.push(1);
numbers2.push(1);
}
if(numbers2[0] === 3 && numbers2[1] === 1){
numbers3.push(2);
numbers2.push(2);
}
if(numbers2[0] === 3 && numbers2[1] === 2){
numbers3.push(1);
numbers2.push(1);
}
}
if(this.isSet(colors2) && this.isSet(shapes2) && this.isSet(numbers2)) {
return this.isSet(colors3) && this.isSet(shapes3) && this.isSet(numbers3)
}
},
generateVirtualCard35: function(cards1, cards2){
// modalité des combinaison de carte (ab ac ad ...) pour verifier si forme un set
var colors2= $.map(cards1, function(el) { return $(el).data("color");});
var shapes2 = $.map(cards1, function(el) { return $(el).data("shape");});
var fills2 = $.map(cards1, function(el) { return $(el).data("fills");});
var borders2 = $.map(cards1, function(el) { return $(el).data("border");});
var numbers2 = $.map(cards1, function(el) { return $(el).data("number");});
var colors3= $.map(cards2, function(el) { return $(el).data("color");});
var shapes3 = $.map(cards2, function(el) { return $(el).data("shape");});
var fills3 = $.map(cards2, function(el) { return $(el).data("fills");});
var borders3 = $.map(cards2, function(el) { return $(el).data("border");});
var numbers3 = $.map(cards2, function(el) { return $(el).data("number");});
if(colors2[0] === colors2 [1]){
colors2.push(colors2[0]);
colors3.push(colors2[0]);
}
else{
if(colors2[0] === 'red' && colors2[1] === 'green'){
colors3.push('purple');
colors2.push('purple');
}
if(colors2[0] === 'red' && colors2[1] === 'purple'){
colors3.push('green');
colors2.push('green');
}
if(colors2[0] === 'green' && colors2[1] === 'purple'){
colors3.push('red');
colors2.push('red');
}
if(colors2[0] === 'green' && colors2[1] === 'red'){
colors3.push('purple');
colors2.push('purple');
}
if(colors2[0] === 'purple' && colors2[1] === 'red'){
colors3.push('green');
colors2.push('green');
}
if(colors2[0] === 'purple' && colors2[1] === 'green'){
colors3.push('red');
colors2.push('red');
}
}
if(shapes2[0] === shapes2 [1]){
shapes3.push(shapes2[0]);
shapes2.push(shapes2[0]);
}
else{
if(shapes2[0] === 'oval' && shapes2[1] === 'diamond'){
shapes3.push('wave');
shapes2.push('wave');
}
if(shapes2[0] === 'oval' && shapes2[1] === 'wave'){
shapes3.push('diamond');
shapes2.push('diamond');
}
if(shapes2[0] === 'diamond' && shapes2[1] === 'oval'){
shapes3.push('wave');
shapes2.push('wave');
}
if(shapes2[0] === 'diamond' && shapes2[1] === 'wave'){
shapes3.push('oval');
shapes2.push('oval');
}
if(shapes2[0] === 'wave' && shapes2[1] === 'diamond'){
shapes3.push('oval');
shapes2.push('oval');
}
if(shapes2[0] === 'wave' && shapes2[1] === 'oval'){
shapes3.push('diamond');
shapes2.push('diamond');
}
}
if(fills2[0] === fills2 [1]){
fills3.push(fills2[0]);
fills2.push(fills2[0]);
}
else{
if(fills2[0] === 'solid' && fills2[1] === 'stripped'){
fills3.push('open');
fills2.push('open');
}
if(fills2[0] === 'solid' && fills2[1] === 'open'){
fills3.push('stripped');
fills2.push('stripped');
}
if(fills2[0] === 'stripped' && fills2[1] === 'open'){
fills3.push('solid');
fills2.push('solid');
}
if(fills2[0] === 'open' && fills2[1] === 'stripped'){
fills3.push('solid');
fills2.push('solid');
}
if(fills2[0] === 'stripped' && fills2[1] === 'solid'){
fills3.push('open');
fills2.push('open');
}
if(fills2[0] === 'open' && fills2[1] === 'solid'){
fills3.push('stripped');
fills2.push('stripped');
}
}
if(borders2[0] === borders2 [1]){
borders3.push(borders2[0]);
borders2.push(borders2[0]);
}
else{
if(borders2[0] === 'plein' && borders2[1] === 'point'){
borders3.push('rond');
borders2.push('rond');
}
if(borders2[0] === 'point' && borders2[1] === 'plein'){
borders3.push('rond');
borders2.push('rond');
}
if(borders2[0] === 'rond' && borders2[1] === 'plein'){
borders3.push('point');
borders2.push('point');
}
if(borders2[0] === 'plein' && borders2[1] === 'rond'){
borders3.push('point');
borders2.push('point');
}
if(borders2[0] === 'rond' && borders2[1] === 'point'){
borders3.push('plein');
borders2.push('plein');
}
if(borders2[0] === 'point' && borders2[1] === 'rond'){
borders3.push('plein');
borders2.push('plein');
}
}
if(numbers2[0] === numbers2[1]){
numbers3.push(numbers2[0]);
numbers2.push(numbers2[0]);
}
else{
if(numbers2[0] === 1 && numbers2[1] === 2){
numbers3.push(3);
numbers2.push(3);
}
if(numbers2[0] === 1 && numbers2[1] === 3){
numbers3.push(2);
numbers2.push(2);
}
if(numbers2[0] === 2 && numbers2[1] === 1){
numbers3.push(3);
numbers2.push(3);
}
if(numbers2[0] === 2 && numbers2[1] === 3){
numbers3.push(1);
numbers2.push(1);
}
if(numbers2[0] === 3 && numbers2[1] === 1){
numbers3.push(2);
numbers2.push(2);
}
if(numbers2[0] === 3 && numbers2[1] === 2){
numbers3.push(1);
numbers2.push(1);
}
}
if(this.isSet(colors2) && this.isSet(shapes2) && this.isSet(fills2) && this.isSet(borders2) && this.isSet(numbers2)) {
return this.isSet(colors3) && this.isSet(shapes3) && this.isSet(fills3) && this.isSet(borders3) && this.isSet(numbers3)
}
},
generateVirtualCard44: function(cards1, cards2){
var colors2= $.map(cards1, function(el) { return $(el).data("color");});
var shapes2 = $.map(cards1, function(el) { return $(el).data("shape");});
var fills2 = $.map(cards1, function(el) { return $(el).data("fills");});
var numbers2 = $.map(cards1, function(el) { return $(el).data("number");});
var colors3= $.map(cards2, function(el) { return $(el).data("color");});
var shapes3 = $.map(cards2, function(el) { return $(el).data("shape");});
var fills3 = $.map(cards2, function(el) { return $(el).data("fills");});
var numbers3 = $.map(cards2, function(el) { return $(el).data("number");});
if (colors2[0] === colors2[1] && colors2[0] === colors2[2]) {
colors2.push(colors2[0]);
colors3.push(colors2[0]);
} else {
if (colors2[0] === 'red' && colors2[1] === 'green' && colors2[2] === 'purple') {
colors3.push('lightblue');
colors2.push('lightblue');
}
if (colors2[0] === 'red' && colors2[1] === 'purple' && colors2[2] === 'green') {
colors3.push('lightblue');
colors2.push('lightblue');
}
if (colors2[0] === 'purple' && colors2[1] === 'red' && colors2[2] === 'green') {
colors3.push('lightblue');
colors2.push('lightblue');
}
if (colors2[0] === 'purple' && colors2[1] === 'green' && colors2[2] === 'red') {
colors3.push('lightblue');
colors2.push('lightblue');
}
if (colors2[0] === 'green' && colors2[1] === 'purple' && colors2[2] === 'red') {
colors3.push('lightblue');
colors2.push('lightblue');
}
if (colors2[0] === 'green' && colors2[1] === 'red' && colors2[2] === 'purple') {
colors3.push('lightblue');
colors2.push('lightblue');
}
if (colors2[0] === 'green' && colors2[1] === 'purple' && colors2[2] === 'lightblue') {
colors3.push('red');
colors2.push('red');
}
if (colors2[0] === 'green' && colors2[1] === 'lightblue' && colors2[2] === 'purple') {
colors3.push('red');
colors2.push('red');
}
if (colors2[0] === 'purple' && colors2[1] === 'lightblue' && colors2[2] === 'green') {
colors3.push('red');
colors2.push('red');
}
if (colors2[0] === 'purple' && colors2[1] === 'green' && colors2[2] === 'lightblue') {
colors3.push('red');
colors2.push('red');
}
if (colors2[0] === 'lightblue' && colors2[1] === 'purple' && colors2[2] === 'green') {
colors3.push('red');
colors2.push('red');
}
if (colors2[0] === 'lightblue' && colors2[1] === 'green' && colors2[2] === 'purple') {
colors3.push('red');
colors2.push('red');
}
if (colors2[0] === 'red' && colors2[1] === 'green' && colors2[2] === 'lightblue') {
colors3.push('purple');
colors2.push('purple');
}
if (colors2[0] === 'red' && colors2[1] === 'lightblue' && colors2[2] === 'green') {
colors3.push('purple');
colors2.push('purple');
}
if (colors2[0] === 'lightblue' && colors2[1] === 'green' && colors2[2] === 'red') {
colors3.push('purple');
colors2.push('purple');
}
if (colors2[0] === 'lightblue' && colors2[1] === 'red' && colors2[2] === 'green') {
colors3.push('purple');
colors2.push('purple');
}
if (colors2[0] === 'green' && colors2[1] === 'lightblue' && colors2[2] === 'red') {
colors3.push('purple');
colors2.push('purple');
}
if (colors2[0] === 'green' && colors2[1] === 'red' && colors2[2] === 'lightblue') {
colors3.push('purple');
colors2.push('purple');
}
if (colors2[0] === 'red' && colors2[1] === 'purple' && colors2[2] === 'lightblue') {
colors3.push('green');
colors2.push('green');
}
if (colors2[0] === 'red' && colors2[1] === 'lightblue' && colors2[2] === 'purple') {
colors3.push('green');
colors2.push('green');
}
if (colors2[0] === 'lightblue' && colors2[1] === 'purple' && colors2[2] === 'red') {
colors3.push('green');
colors2.push('green');
}
if (colors2[0] === 'lightblue' && colors2[1] === 'red' && colors2[2] === 'purple') {
colors3.push('green');
colors2.push('green');
}
if (colors2[0] === 'purple' && colors2[1] === 'lightblue' && colors2[2] === 'red') {
colors3.push('green');
colors2.push('green');
}
if (colors2[0] === 'purple' && colors2[1] === 'red' && colors2[2] === 'lightblue') {
colors3.push('green');
colors2.push('green');
}
}
if (shapes2[0] === shapes2 [1] && shapes2[0] === shapes2 [2]) {
shapes3.push(shapes2[0]);
shapes2.push(shapes2[0]);
} else {
if (shapes2[0] === 'oval' && shapes2[1] === 'diamond' && shapes2[2] === 'wave') {
shapes3.push('rectangle');
shapes2.push('rectangle');
}
if (shapes2[0] === 'oval' && shapes2[1] === 'wave' && shapes2[2] === 'diamond') {
shapes3.push('rectangle');
shapes2.push('rectangle');
}
if (shapes2[0] === 'wave' && shapes2[1] === 'diamond' && shapes2[2] === 'oval') {
shapes3.push('rectangle');
shapes2.push('rectangle');
}
if (shapes2[0] === 'wave' && shapes2[1] === 'oval' && shapes2[2] === 'diamond') {
shapes3.push('rectangle');
shapes2.push('rectangle');
}
if (shapes2[0] === 'diamond' && shapes2[1] === 'oval' && shapes2[2] === 'wave') {
shapes3.push('rectangle');
shapes2.push('rectangle');
}
if (shapes2[0] === 'diamond' && shapes2[1] === 'wave' && shapes2[2] === 'oval') {
shapes3.push('rectangle');
shapes2.push('rectangle');
}
if (shapes2[0] === 'oval' && shapes2[1] === 'diamond' && shapes2[2] === 'rectangle') {
shapes3.push('wave');
shapes2.push('wave');
}
if (shapes2[0] === 'oval' && shapes2[1] === 'rectangle' && shapes2[2] === 'diamond') {
shapes3.push('wave');
shapes2.push('wave');
}
if (shapes2[0] === 'rectangle' && shapes2[1] === 'oval' && shapes2[2] === 'diamond') {
shapes3.push('wave');
shapes2.push('wave');
}
if (shapes2[0] === 'rectangle' && shapes2[1] === 'diamond' && shapes2[2] === 'oval') {
shapes3.push('wave');
shapes2.push('wave');
}
if (shapes2[0] === 'diamond' && shapes2[1] === 'oval' && shapes2[2] === 'rectangle') {
shapes3.push('wave');
shapes2.push('wave');
}
if (shapes2[0] === 'diamond' && shapes2[1] === 'rectangle' && shapes2[2] === 'oval') {
shapes3.push('wave');
shapes2.push('wave');
}
if (shapes2[0] === 'oval' && shapes2[1] === 'wave' && shapes2[2] === 'rectangle') {
shapes3.push('diamond');
shapes2.push('diamond');
}
if (shapes2[0] === 'oval' && shapes2[1] === 'rectangle' && shapes2[2] === 'wave') {
shapes3.push('diamond');
shapes2.push('diamond');
}
if (shapes2[0] === 'rectangle' && shapes2[1] === 'wave' && shapes2[2] === 'oval') {
shapes3.push('diamond');
shapes2.push('diamond');
}
if (shapes2[0] === 'rectangle' && shapes2[1] === 'oval' && shapes2[2] === 'wave') {
shapes3.push('diamond');
shapes2.push('diamond');
}
if (shapes2[0] === 'wave' && shapes2[1] === 'oval' && shapes2[2] === 'rectangle') {
shapes3.push('diamond');
shapes2.push('diamond');
}
if (shapes2[0] === 'wave' && shapes2[1] === 'rectangle' && shapes2[2] === 'oval') {
shapes3.push('diamond');
shapes2.push('diamond');
}
if (shapes2[0] === 'diamond' && shapes2[1] === 'wave' && shapes2[2] === 'rectangle') {
shapes3.push('oval');
shapes2.push('oval');
}
if (shapes2[0] === 'diamond' && shapes2[1] === 'rectangle' && shapes2[2] === 'wave') {
shapes3.push('oval');
shapes2.push('oval');
}
if (shapes2[0] === 'rectangle' && shapes2[1] === 'wave' && shapes2[2] === 'diamond') {
shapes3.push('oval');
shapes2.push('oval');
}
if (shapes2[0] === 'rectangle' && shapes2[1] === 'diamond' && shapes2[2] === 'wave') {
shapes3.push('oval');
shapes2.push('oval');
}
if (shapes2[0] === 'wave' && shapes2[1] === 'diamond' && shapes2[2] === 'rectangle') {
shapes3.push('oval');
shapes2.push('oval');
}
if (shapes2[0] === 'wave' && shapes2[1] === 'rectangle' && shapes2[2] === 'diamond') {
shapes3.push('oval');
shapes2.push('oval');
}
}
if (fills2[0] === fills2 [1] && fills2[0] === fills2 [2]) {
fills3.push(fills2[0]);
fills2.push(fills2[0]);
} else {
if (fills2[0] === 'solid' && fills2[1] === 'stripped' && fills2[2] === 'open') {
fills3.push('quadrillage');
fills2.push('quadrillage');
}
if (fills2[0] === 'solid' && fills2[1] === 'open' && fills2[2] === 'stripped') {
fills3.push('quadrillage');
fills2.push('quadrillage');
}
if (fills2[0] === 'stripped' && fills2[1] === 'open' && fills2[2] === 'solid') {
fills3.push('quadrillage');
fills2.push('quadrillage');
}
if (fills2[0] === 'stripped' && fills2[1] === 'solid' && fills2[2] === 'open') {
fills3.push('quadrillage');
fills2.push('quadrillage');
}
if (fills2[0] === 'open' && fills2[1] === 'stripped' && fills2[2] === 'solid') {
fills3.push('quadrillage');
fills2.push('quadrillage');
}
if (fills2[0] === 'open' && fills2[1] === 'solid' && fills2[2] === 'stripped') {
fills3.push('quadrillage');
fills2.push('quadrillage');
}
if (fills2[0] === 'solid' && fills2[1] === 'stripped' && fills2[2] === 'quadrillage') {
fills3.push('open');
fills2.push('open');
}
if (fills2[0] === 'solid' && fills2[1] === 'quadrillage' && fills2[2] === 'stripped') {
fills3.push('open');
fills2.push('open');
}
if (fills2[0] === 'quadrillage' && fills2[1] === 'solid' && fills2[2] === 'stripped') {
fills3.push('open');
fills2.push('open');
}
if (fills2[0] === 'quadrillage' && fills2[1] === 'stripped' && fills2[2] === 'solid') {
fills3.push('open');
fills2.push('open');
}
if (fills2[0] === 'stripped' && fills2[1] === 'quadrillage' && fills2[2] === 'solid') {
fills3.push('open');
fills2.push('open');
}
if (fills2[0] === 'stripped' && fills2[1] === 'solid' && fills2[2] === 'quadrillage') {
fills3.push('open');
fills2.push('open');
}
if (fills2[0] === 'solid' && fills2[1] === 'open' && fills2[2] === 'quadrillage') {
fills3.push('stripped');
fills2.push('stripped');
}
if (fills2[0] === 'solid' && fills2[1] === 'quadrillage' && fills2[2] === 'open') {
fills3.push('stripped');
fills2.push('stripped');
}
if (fills2[0] === 'quadrillage' && fills2[1] === 'solid' && fills2[2] === 'open') {
fills3.push('stripped');
fills2.push('stripped');
}
if (fills2[0] === 'quadrillage' && fills2[1] === 'open' && fills2[2] === 'solid') {
fills3.push('stripped');
fills2.push('stripped');
}
if (fills2[0] === 'open' && fills2[1] === 'quadrillage' && fills2[2] === 'solid') {
fills3.push('stripped');
fills2.push('stripped');
}
if (fills2[0] === 'open' && fills2[1] === 'solid' && fills2[2] === 'quadrillage') {
fills3.push('stripped');
fills2.push('stripped');
}
if (fills2[0] === 'stripped' && fills2[1] === 'open' && fills2[2] === 'quadrillage') {
fills3.push('solid');
fills2.push('solid');
}
if (fills2[0] === 'stripped' && fills2[1] === 'quadrillage' && fills2[2] === 'open') {
fills3.push('solid');
fills2.push('solid');
}
if (fills2[0] === 'quadrillage' && fills2[1] === 'stripped' && fills2[2] === 'open') {
fills3.push('solid');
fills2.push('solid');
}
if (fills2[0] === 'quadrillage' && fills2[1] === 'open' && fills2[2] === 'stripped') {
fills3.push('solid');
fills2.push('solid');
}
if (fills2[0] === 'open' && fills2[1] === 'quadrillage' && fills2[2] === 'stripped') {
fills3.push('solid');
fills2.push('solid');
}
if (fills2[0] === 'open' && fills2[1] === 'stripped' && fills2[2] === 'quadrillage') {
fills3.push('solid');
fills2.push('solid');
}
}
if (numbers2[0] === numbers2[1] && numbers2[0] === numbers2[2]) {
numbers3.push(numbers2[0]);
numbers2.push(numbers2[0]);
} else {
if (numbers2[0] === 1 && numbers2[1] === 2 && numbers2[2] === 3) {
numbers3.push(4);
numbers2.push(4);
}
if (numbers2[0] === 1 && numbers2[1] === 3 && numbers2[2] === 2) {
numbers3.push(4);
numbers2.push(4);
}
if (numbers2[0] === 2 && numbers2[1] === 1 && numbers2[2] === 3) {
numbers3.push(4);
numbers2.push(4);
}
if (numbers2[0] === 2 && numbers2[1] === 3 && numbers2[2] === 1) {
numbers3.push(4);
numbers2.push(4);
}
if (numbers2[0] === 3 && numbers2[1] === 1 && numbers2[2] === 2) {
numbers3.push(4);
numbers2.push(4);
}
if (numbers2[0] === 3 && numbers2[1] === 2 && numbers2[2] === 1) {
numbers3.push(4);
numbers2.push(4);
}
if (numbers2[0] === 1 && numbers2[1] === 2 && numbers2[2] === 4) {
numbers3.push(3);
numbers2.push(3);
}
if (numbers2[0] === 1 && numbers2[1] === 4 && numbers2[2] === 2) {
numbers3.push(3);
numbers2.push(3);
}
if (numbers2[0] === 2 && numbers2[1] === 1 && numbers2[2] === 4) {
numbers3.push(3);
numbers2.push(3);
}
if (numbers2[0] === 2 && numbers2[1] === 4 && numbers2[2] === 1) {
numbers3.push(3);
numbers2.push(3);
}
if (numbers2[0] === 4 && numbers2[1] === 1 && numbers2[2] === 2) {
numbers3.push(3);
numbers2.push(3);
}
if (numbers2[0] === 4 && numbers2[1] === 2 && numbers2[2] === 1) {
numbers3.push(3);
numbers2.push(3);
}
if (numbers2[0] === 1 && numbers2[1] === 3 && numbers2[2] === 4) {
numbers3.push(2);
numbers2.push(2);
}
if (numbers2[0] === 1 && numbers2[1] === 4 && numbers2[2] === 3) {
numbers3.push(2);
numbers2.push(2);
}
if (numbers2[0] === 3 && numbers2[1] === 1 && numbers2[2] === 4) {
numbers3.push(2);
numbers2.push(2);
}
if (numbers2[0] === 3 && numbers2[1] === 4 && numbers2[2] === 1) {
numbers3.push(2);
numbers2.push(2);
}
if (numbers2[0] === 4 && numbers2[1] === 1 && numbers2[2] === 3) {
numbers3.push(2);
numbers2.push(2);
}
if (numbers2[0] === 4 && numbers2[1] === 3 && numbers2[2] === 1) {
numbers3.push(2);
numbers2.push(2);
}
if (numbers2[0] === 2 && numbers2[1] === 3 && numbers2[2] === 4) {
numbers3.push(1);
numbers2.push(1);
}
if (numbers2[0] === 2 && numbers2[1] === 4 && numbers2[2] === 3) {
numbers3.push(1);
numbers2.push(1);
}
if (numbers2[0] === 3 && numbers2[1] === 2 && numbers2[2] === 4) {
numbers3.push(1);
numbers2.push(1);
}
if (numbers2[0] === 3 && numbers2[1] === 4 && numbers2[2] === 2) {
numbers3.push(1);
numbers2.push(1);
}
if (numbers2[0] === 4 && numbers2[1] === 2 && numbers2[2] === 3) {
numbers3.push(1);
numbers2.push(1);
}
if (numbers2[0] === 4 && numbers2[1] === 3 && numbers2[2] === 2) {
numbers3.push(1);
numbers2.push(1);
}
}
if(this.isSet4(colors2) && this.isSet4(shapes2) && this.isSet4(fills2) && this.isSet4(numbers2)) {
return this.isSet4(colors3) && this.isSet4(shapes3) && this.isSet4(fills3) && this.isSet4(numbers3)
}
},
validateHyperSet0: function() {
var carteAB = [];
var carteCD = [];
var carteAC = [];
var carteBD = [];
var carteAD = [];
var carteBC = [];
carteAB.splice(0,1,this.selectedHS0[0]);
carteAB.splice(1,1,this.selectedHS0[1]);
carteCD.splice(0,1,this.selectedHS0[2]);
carteCD.splice(1,1,this.selectedHS0[3]);
carteAC.splice(0,1,this.selectedHS0[0]);
carteAC.splice(1,1,this.selectedHS0[2]);
carteBD.splice(0,1,this.selectedHS0[1]);
carteBD.splice(1,1,this.selectedHS0[3]);
carteAD.splice(0,1,this.selectedHS0[0]);
carteAD.splice(1,1,this.selectedHS0[3]);
carteBC.splice(0,1,this.selectedHS0[1]);
carteBC.splice(1,1,this.selectedHS0[2]);
if (this.generateVirtualCard33(carteAB, carteCD)) {
return true;
}
if (this.generateVirtualCard33(carteAC, carteBD)) {
return true;
}
if (this.generateVirtualCard33(carteAD, carteBC)) {
return true;
}
return false;
},
validateHyperSet: function() {
var carteAB = [];
var carteCD = [];
var carteAC = [];
var carteBD = [];
var carteAD = [];
var carteBC = [];
carteAB.splice(0,1,this.selectedHS[0]);
carteAB.splice(1,1,this.selectedHS[1]);
carteCD.splice(0,1,this.selectedHS[2]);
carteCD.splice(1,1,this.selectedHS[3]);
carteAC.splice(0,1,this.selectedHS[0]);
carteAC.splice(1,1,this.selectedHS[2]);
carteBD.splice(0,1,this.selectedHS[1]);
carteBD.splice(1,1,this.selectedHS[3]);
carteAD.splice(0,1,this.selectedHS[0]);
carteAD.splice(1,1,this.selectedHS[3]);
carteBC.splice(0,1,this.selectedHS[1]);
carteBC.splice(1,1,this.selectedHS[2]);
if (this.generateVirtualCard34(carteAB, carteCD)) {
return true;
}
else if (this.generateVirtualCard34(carteAC, carteBD)){
return true;
}
else if (this.generateVirtualCard34(carteAD, carteBC)) {
return true;
}
else{
return false;
}
},
validateHyperSet1: function() {
var carteAB = [];
var carteCD = [];
var carteAC = [];
var carteBD = [];
var carteAD = [];
var carteBC = [];
carteAB.splice(0,1,this.selectedHS1[0]);
carteAB.splice(1,1,this.selectedHS1[1]);
carteCD.splice(0,1,this.selectedHS1[2]);
carteCD.splice(1,1,this.selectedHS1[3]);
carteAC.splice(0,1,this.selectedHS1[0]);
carteAC.splice(1,1,this.selectedHS1[2]);
carteBD.splice(0,1,this.selectedHS1[1]);
carteBD.splice(1,1,this.selectedHS1[3]);
carteAD.splice(0,1,this.selectedHS1[0]);
carteAD.splice(1,1,this.selectedHS1[3]);
carteBC.splice(0,1,this.selectedHS1[1]);
carteBC.splice(1,1,this.selectedHS1[2]);
if (this.generateVirtualCard35(carteAB, carteCD)) {
return true;
}
else if (this.generateVirtualCard35(carteAC, carteBD)) {
return true;
}
else if (this.generateVirtualCard35(carteAD, carteBC)) {
return true;
}
else{
return false;
}
},
validateHyperSet2: function() {
var carteABC = [];
var carteDEF = [];
var carteABD = [];
var carteCEF = [];
var carteABE = [];
var carteCDF = [];
var carteABF = [];
var carteCDE = [];
var carteACD = [];
var carteBEF = [];
var carteACE = [];
var carteBDF = [];
var carteACF = [];
var carteBDE = [];
var carteADE = [];
var carteBCF = [];
var carteADF = [];
var carteBCE = [];
var carteAEF = [];
var carteBCD = [];
carteABC.splice(0, 1, this.selectedHS2[0]);
carteABC.splice(1, 1, this.selectedHS2[1]);
carteABC.splice(2, 1, this.selectedHS2[2]);
carteDEF.splice(0, 1, this.selectedHS2[3]);
carteDEF.splice(1, 1, this.selectedHS2[4]);
carteDEF.splice(2, 1, this.selectedHS2[5]);
carteABD.splice(0, 1, this.selectedHS2[0]);
carteABD.splice(1, 1, this.selectedHS2[1]);
carteABD.splice(2, 1, this.selectedHS2[3]);
carteCEF.splice(0, 1, this.selectedHS2[2]);
carteCEF.splice(1, 1, this.selectedHS2[4]);
carteCEF.splice(2, 1, this.selectedHS2[5]);
carteABE.splice(0, 1, this.selectedHS2[0]);
carteABE.splice(1, 1, this.selectedHS2[1]);
carteABE.splice(2, 1, this.selectedHS2[4]);
carteCDF.splice(0, 1, this.selectedHS2[2]);
carteCDF.splice(1, 1, this.selectedHS2[3]);
carteCDF.splice(2, 1, this.selectedHS2[5]);
carteABF.splice(0, 1, this.selectedHS2[0]);
carteABF.splice(1, 1, this.selectedHS2[1]);
carteABF.splice(2, 1, this.selectedHS2[5]);
carteCDE.splice(0, 1, this.selectedHS2[2]);
carteCDE.splice(1, 1, this.selectedHS2[3]);
carteCDE.splice(2, 1, this.selectedHS2[4]);
carteACD.splice(0, 1, this.selectedHS2[0]);
carteACD.splice(1, 1, this.selectedHS2[2]);
carteACD.splice(2, 1, this.selectedHS2[3]);
carteBEF.splice(0, 1, this.selectedHS2[1]);
carteBEF.splice(1, 1, this.selectedHS2[4]);
carteBEF.splice(2, 1, this.selectedHS2[5]);
carteACE.splice(0, 1, this.selectedHS2[0]);
carteACE.splice(1, 1, this.selectedHS2[2]);
carteACE.splice(2, 1, this.selectedHS2[4]);
carteBDF.splice(0, 1, this.selectedHS2[1]);
carteBDF.splice(1, 1, this.selectedHS2[3]);
carteBDF.splice(2, 1, this.selectedHS2[5]);
carteACF.splice(0, 1, this.selectedHS2[0]);
carteACF.splice(1, 1, this.selectedHS2[2]);
carteACF.splice(2, 1, this.selectedHS2[5]);
carteBDE.splice(0, 1, this.selectedHS2[1]);
carteBDE.splice(1, 1, this.selectedHS2[3]);
carteBDE.splice(2, 1, this.selectedHS2[4]);
carteADE.splice(0, 1, this.selectedHS2[0]);
carteADE.splice(1, 1, this.selectedHS2[3]);
carteADE.splice(2, 1, this.selectedHS2[4]);
carteBCF.splice(0, 1, this.selectedHS2[1]);
carteBCF.splice(1, 1, this.selectedHS2[2]);
carteBCF.splice(2, 1, this.selectedHS2[5]);
carteADF.splice(0, 1, this.selectedHS2[0]);
carteADF.splice(1, 1, this.selectedHS2[3]);
carteADF.splice(2, 1, this.selectedHS2[5]);
carteBCE.splice(0, 1, this.selectedHS2[1]);
carteBCE.splice(1, 1, this.selectedHS2[2]);
carteBCE.splice(2, 1, this.selectedHS2[4]);
carteAEF.splice(0, 1, this.selectedHS2[0]);
carteAEF.splice(1, 1, this.selectedHS2[4]);
carteAEF.splice(2, 1, this.selectedHS2[5]);
carteBCD.splice(0, 1, this.selectedHS2[1]);
carteBCD.splice(1, 1, this.selectedHS2[2]);
carteBCD.splice(2, 1, this.selectedHS2[3]);
if (this.generateVirtualCard44(carteABC, carteDEF)) {
return true;
}
else if (this.generateVirtualCard44(carteABD, carteCEF)) {
return true;
}
else if (this.generateVirtualCard44(carteABE, carteCDF)) {
return true;
}
else if (this.generateVirtualCard44(carteABF, carteCDE)) {
return true;
}
else if (this.generateVirtualCard44(carteACD, carteBEF)) {
return true;
}
if (this.generateVirtualCard44(carteACE, carteBDF)) {
return true;
}
else if (this.generateVirtualCard44(carteACF, carteBDE)) {
return true;
}
else if (this.generateVirtualCard44(carteADE, carteBCF)) {
return true;
}
else if (this.generateVirtualCard44(carteADF, carteBCE)) {
return true;
}
else if (this.generateVirtualCard44(carteAEF, carteBCD)) {
return true;
}
else{
return false;
}
},
validateSet0: function() {
var self = this;
var colors = $.map(self.selected0, function(el) { return $(el).data("color");});
var shapes = $.map(self.selected0, function(el) { return $(el).data("shape"); });
var numbers= $.map(self.selected0, function(el) { return $(el).data("number"); });
return (self.isSet(colors) && self.isSet(shapes) && self.isSet(numbers));
},
validateSet: function() {
var self = this;
var colors = $.map(self.selected, function(el) { return $(el).data("color");});
var shapes = $.map(self.selected, function(el) { return $(el).data("shape"); });
var fills= $.map(self.selected, function(el) { return $(el).data("fill"); });
var numbers = $.map(self.selected, function(el) { return $(el).data("number"); });
return (self.isSet(colors) && self.isSet(shapes) && self.isSet(fills) && self.isSet(numbers));
},
validateSet35: function() {
var self = this;
var colors = $.map(self.selected1, function(el) { return $(el).data("color");});
var shapes = $.map(self.selected1, function(el) { return $(el).data("shape"); });
var fills= $.map(self.selected1, function(el) { return $(el).data("fill"); });
var borders= $.map(self.selected1, function(el) { return $(el).data("border"); });
var numbers = $.map(self.selected1, function(el) { return $(el).data("number"); });
return (self.isSet(colors) && self.isSet(shapes) && self.isSet(fills) && self.isSet(borders) && self.isSet(numbers));
},
validateSet44: function() {
var self = this;
var colors = $.map(self.selected2, function(el) { return $(el).data("color");});
var shapes = $.map(self.selected2, function(el) { return $(el).data("shape"); });
var fills= $.map(self.selected2, function(el) { return $(el).data("fill"); });
var numbers = $.map(self.selected2, function(el) { return $(el).data("number"); });
return (self.isSet4(colors) && self.isSet4(shapes) && self.isSet4(fills) && self.isSet4(numbers));
},
validateSet45: function() {
var self = this;
var colors = $.map(self.selected3, function(el) { return $(el).data("color");});
var shapes = $.map(self.selected3, function(el) { return $(el).data("shape"); });
var fills= $.map(self.selected3, function(el) { return $(el).data("fill"); });
var borders= $.map(self.selected3, function(el) { return $(el).data("border"); });
var numbers = $.map(self.selected3, function(el) { return $(el).data("number"); });
return (self.isSet4(colors) && self.isSet4(shapes) && self.isSet4(borders) && self.isSet4(fills) && self.isSet4(numbers));
},
validateSet55: function() {
var self = this;
var colors = $.map(self.selected4, function(el) { return $(el).data("color");});
var shapes = $.map(self.selected4, function(el) { return $(el).data("shape"); });
var fills= $.map(self.selected4, function(el) { return $(el).data("fill"); });
var borders= $.map(self.selected4, function(el) { return $(el).data("border"); });
var numbers = $.map(self.selected4, function(el) { return $(el).data("number"); });
return (self.isSet5(colors) && self.isSet5(shapes) && self.isSet5(fills) && self.isSet5(borders) && self.isSet5(numbers));
},
isSet: function(arr) {
var unique = [];
$.each(arr, function(i, el){
if($.inArray(el, unique) === -1) unique.push(el);
});
return unique.length === 1 || unique.length === 3;
},
isSet4: function(arr) {
var unique = [];
$.each(arr, function(i, el){
if($.inArray(el, unique) === -1) unique.push(el);
});
return unique.length === 1 || unique.length === 4;
},
isSet5: function(arr) {
var unique = [];
$.each(arr, function(i, el){
if($.inArray(el, unique) === -1) unique.push(el);
});
return unique.length === 1 || unique.length === 5;
},
silentSubmission0: function() {
var valid = this.validateSet0();
if (valid) {
this.submitSet0();
}
},
silentSubmission: function() {
var valid = this.validateSet();
if (valid) {
this.submitSet();
}
},
silentSubmission1: function() {
var valid = this.validateSet35();
if (valid) {
this.submitSet1();
}
},
silentSubmission2: function() {
var valid = this.validateSet44();
if (valid) {
this.submitSet2();
}
},
silentSubmission3: function() {
var valid = this.validateSet45();
if (valid) {
this.submitSet3();
}
},
silentSubmission4: function() {
var valid = this.validateSet55();
if (valid) {
this.submitSet4();
}
},
silentSubmissionHS: function() {
var valid = this.validateHyperSet();
if (valid) {
this.submitSetHS();
}
},
silentSubmissionHS0: function() {
var valid = this.validateHyperSet0();
if (valid) {
this.submitSetHS0();
}
},
silentSubmissionHS1: function() {
var valid = this.validateHyperSet1();
if (valid) {
this.submitSetHS1();
}
},
silentSubmissionHS2: function() {
var valid = this.validateHyperSet2();
if (valid) {
this.submitSetHS2();
}
},
submitSet0: function() {
var self = this;
var ids = $.map(self.selected0, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submit0',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCards0(ids, data);
// to do - implement game complete check on server
if (!data.gameComplete) {
self.set0 = 0;
//self.updateCards(data);
//self.existingSet0();
self.increaseScore0();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelections0();
},
submitSet: function() {
var self = this;
var ids = $.map(self.selected, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submit',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCards(ids, data);
// to do - implement game complete check on server
if (!data.gameComplete) {
self.set = 0;
//self.updateCards(data);
self.existingSet();
self.increaseScore();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelections();
},
submitSet1: function() {
var self = this;
var ids = $.map(self.selected1, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submit1',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCards1(ids,data);
// to do - implement game complete check on server
if (!data.gameComplete) {
self.set1 = 0;
//self.updateCards1(data);
//self.existingSet1();
self.increaseScore1();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelections1();
},
submitSet2: function() {
var self = this;
var ids = $.map(self.selected2, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submit2',
type: 'GET',
dataType: 'json',
success: function(data) {
self.set2 = 0;
self.clearCards2(ids,data);
// to do - implement game complete check on server
if (!data.gameComplete) {
//self.updateCards2(data);
//self.existingSet2();
self.increaseScore2();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelections2();
},
submitSet3: function() {
var self = this;
var ids = $.map(self.selected3, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submit3',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCards3(ids,data);
// to do - implement game complete check on server
if (!data.gameComplete) {
self.set3 = 0;
//self.updateCards3(data);
//self.existingSet3();
self.increaseScore3();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelections3();
},
submitSet4: function() {
var self = this;
var ids = $.map(self.selected4, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submit4',
type: 'GET',
dataType: 'json',
success: function(data) {
console.log(data);
self.clearCards4(ids,data);
// to do - implement game complete check on server
if (!data.gameComplete) {
self.set4 = 0;
//self.updateCards4(data);
//self.existingSet4();
self.increaseScore4();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelections4();
},
submitSetHS: function() {
var self = this;
var ids = $.map(self.selectedHS, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submitHS',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCardsHS(ids, data);
// to do - implement game complete check on server
if (!data.gameComplete) {
//self.set0 = 0;
//self.updateCards(data);
//self.existingSet0();
self.increaseScoreHS();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelectionsHS();
},
submitSetHS0: function() {
var self = this;
var ids = $.map(self.selectedHS0, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submitHS0',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCardsHS0(ids, data);
// to do - implement game complete check on server
if (!data.gameComplete) {
//self.set0 = 0;
//self.updateCards(data);
//self.existingSet0();
self.increaseScoreHS0();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelectionsHS0();
},
submitSetHS1: function() {
var self = this;
var ids = $.map(self.selectedHS1, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submitHS1',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCardsHS1(ids, data);
// to do - implement game complete check on server
if (!data.gameComplete) {
//self.set0 = 0;
//self.updateCards(data);
//self.existingSet0();
self.increaseScoreHS1();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelectionsHS1();
},
submitSetHS2: function() {
var self = this;
var ids = $.map(self.selectedHS2, function(el) { return $(el).data("id");});
// ajax request to get initial set of cards
var newCardRequest = $.ajax({
url: 'set.php?action=submitHS2',
type: 'GET',
dataType: 'json',
success: function(data) {
self.clearCardsHS2(ids, data);
// to do - implement game complete check on server
if (!data.gameComplete) {
//self.set0 = 0;
//self.updateCards(data);
//self.existingSet0();
self.increaseScoreHS2();
} else {
self.gameWon();
}
},
error: function() {
console.log(arguments);
}
});
this.clearSelectionsHS2();
},
clearCards0: function(ids,data) {
var self = this;
this.selected0 = [];
this.$board0.empty();
var cardIds = $.map(self.cards0, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cards0.splice(location, 1, data[idx]);
cardIds = $.map(self.cards0, function(card) { return card.id; });
}
else{
self.cards0.splice(location, 1);
}
}
});
this.displayCards0();
if(self.cards0.length === 0){
alert("you won!");
}
},
clearCards: function(ids,data) {
var self = this;
this.selected = [];
this.$board.empty();
var cardIds = $.map(self.cards, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cards.splice(location, 1, data[idx]);
cardIds = $.map(self.cards, function(card) { return card.id; });
}
else{
self.cards.splice(location, 1);
}
}
});
this.displayCards();
if(self.cards.length === 0){
alert("you won!");
}
},
clearCards1: function(ids,data) {
// remove submitted cards game's card array and clear the board
var self = this;
this.selected1 = [];
this.$board1.empty();
var cardIds = $.map(self.cards1, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cards1.splice(location, 1, data[idx]);
cardIds = $.map(self.cards1, function(card) { return card.id; });
}
else{
self.cards1.splice(location, 1);
}
}
});
this.displayCards1();
if(self.cards1.length === 0){
alert("you won!");
}
},
clearCards2: function(ids, data) {
// remove submitted cards game's card array and clear the board
var self = this;
this.selected2 = [];
this.$board2.empty();
var cardIds = $.map(self.cards2, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cards2.splice(location, 1, data[idx]);
cardIds = $.map(self.cards2, function(card) { return card.id; });
}
else{
self.cards2.splice(location, 1);
}
}
});
this.displayCards2();
if(self.cards2.length === 0){
alert("you won!");
}
},
clearCards3: function(ids,data) {
// remove submitted cards game's card array and clear the board
var self = this;
this.selected3 = [];
this.$board3.empty();
var cardIds = $.map(self.cards3, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cards3.splice(location, 1, data[idx]);
cardIds = $.map(self.cards3, function(card) { return card.id; });
}
else{
self.cards3.splice(location, 1);
}
}
});
this.displayCards3();
if(self.cards3.length === 0){
alert("you won!");
}
},
clearCards4: function(ids,data) {
// remove submitted cards game's card array and clear the board
var self = this;
this.selected4 = [];
this.$board4.empty();
var cardIds = $.map(self.cards4, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cards4.splice(location, 1, data[idx]);
cardIds = $.map(self.cards4, function(card) { return card.id; });
}
else{
self.cards4.splice(location, 1);
}
}
});
this.displayCards4();
if(self.cards4.length === 0){
alert("you won!");
}
},
clearCardsHS: function(ids,data) {
var self = this;
this.selectedHS = [];
this.$boardHS.empty();
var cardIds = $.map(self.cardsHS, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cardsHS.splice(location, 1, data[idx]);
cardIds = $.map(self.cardsHS, function(card) { return card.id; });
}
else{
self.cardsHS.splice(location, 1);
}
}
});
this.displayCardsHS();
if(self.cardsHS.length === 0){
alert("you won!");
}
},
clearCardsHS0: function(ids,data) {
var self = this;
this.selectedHS0 = [];
this.$boardHS0.empty();
var cardIds = $.map(self.cardsHS0, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cardsHS0.splice(location, 1, data[idx]);
cardIds = $.map(self.cardsHS0, function(card) { return card.id; });
}
else{
self.cardsHS0.splice(location, 1);
}
}
});
this.displayCardsHS0();
if(self.cardsHS0.length === 0){
alert("you won!");
}
},
clearCardsHS1: function(ids,data) {
var self = this;
this.selectedHS1 = [];
this.$boardHS1.empty();
var cardIds = $.map(self.cardsHS1, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cardsHS1.splice(location, 1, data[idx]);
cardIds = $.map(self.cardsHS1, function(card) { return card.id; });
}
else{
self.cardsHS1.splice(location, 1);
}
}
});
this.displayCardsHS1();
if(self.cardsHS1.length === 0){
alert("you won!");
}
},
clearCardsHS2: function(ids,data) {
var self = this;
this.selectedHS2 = [];
this.$boardHS2.empty();
var cardIds = $.map(self.cardsHS2, function(card) { return card.id; });
$.each(ids, function(idx, id) {
var location = cardIds.indexOf(id);
if (location > -1) {
cardIds.splice(location, 1);
if(data[idx] != null){
self.cardsHS2.splice(location, 1, data[idx]);
cardIds = $.map(self.cardsHS2, function(card) { return card.id; });
}
else{
self.cardsHS1.splice(location, 1);
}
}
});
this.displayCardsHS2();
if(self.cardsHS2.length === 0){
alert("you won!");
}
},
updateCards: function(newCards) {
this.cards = this.cards.concat(newCards);
this.displayCards();
},
updateCards1: function(newCards) {
this.cards1 = this.cards1.concat(newCards);
this.displayCards1();
},
updateCards2: function(newCards) {
this.cards2 = this.cards2.concat(newCards);
this.displayCards2();
},
updateCards3: function(newCards) {
this.cards3 = this.cards3.concat(newCards);
this.displayCards3();
},
updateCards4: function(newCards) {
this.cards4 = this.cards4.concat(newCards);
this.displayCards4();
},
increaseScore0: function() {
this.$score0.html(++this.score0);
},
increaseScore: function() {
this.$score.html(++this.score);
},
increaseScore1: function() {
this.$score1.html(++this.score1);
},
increaseScore2: function() {
this.$score2.html(++this.score2);
},
increaseScore3: function() {
this.$score3.html(++this.score3);
},
increaseScore4: function() {
this.$score4.html(++this.score4);
},
increaseScoreHS: function() {
this.$scoreHS.html(++this.scoreHS);
},
increaseScoreHS0: function() {
this.$scoreHS0.html(++this.scoreHS0);
},
increaseScoreHS1: function() {
this.$scoreHS1.html(++this.scoreHS1);
},
increaseScoreHS2: function() {
this.$scoreHS2.html(++this.scoreHS2);
},
startRound: function() {
// todo
// reset timer to 30 seconds
},
gameWon: function() {
alert("you won!");
},
gameLost: function() {
alert("you lost :(");
}
};;;
Game.deal();
/*
var canvases = document.getElementsByClassName(' red solid');
console.log(canvases);
for (let canvas of canvases) {
console.log(canvas);
}
/*
var canvases = $('.red');
console.log(canvases);
canvases.each(function(i, c) {
var context = c.getContext('2d');
console.log(c);
drawDiamond(context, 50, 50, 75, 100);
context.fillStyle = "red";
context.fill();
});
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.restore();
}
/*
var canvases = $( ".red" );
for (let canvas of canvases) {
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'red';
ctx.fillRect(10, 10, 100, 100);
}
/*
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();
}*/