Compteur de Set

master
readhame 5 years ago
parent 3592d10a3f
commit 12101d0ecb

@ -91,7 +91,8 @@
<workItem from="1592386067985" duration="18199000" />
<workItem from="1592480910771" duration="8909000" />
<workItem from="1592564170927" duration="15576000" />
<workItem from="1592817049643" duration="10891000" />
<workItem from="1592817049643" duration="21843000" />
<workItem from="1592908388600" duration="21604000" />
</task>
<servers />
</component>
@ -131,9 +132,9 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="498" height="446" key="SwitcherDM/0.0.1920.1040@0.0.1920.1040" timestamp="1592141850590" />
<state x="1136" y="344" key="com.intellij.ide.util.TipDialog" timestamp="1592817056336">
<state x="1136" y="344" key="com.intellij.ide.util.TipDialog" timestamp="1592908755965">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="1136" y="344" key="com.intellij.ide.util.TipDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1592817056336" />
<state x="1136" y="344" key="com.intellij.ide.util.TipDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1592908755965" />
</component>
</project>

@ -64,16 +64,13 @@ h1 {
margin-top: 55%;
}
.diamond {
transform: rotate(67deg) skewX(45deg) scaleY( 0.40);
width: 60px;
}
.wave {
border-radius: 15px 180px 15px 180px;
transform: rotate(1deg) skewX(0.5deg) scaleX(0.8);

@ -25,7 +25,7 @@ var Game = {
success: function(data) {
self.cards = data;
self.displayCards.call(self);
self.existingSet(data);
self.existingSet();
self.setCardListeners();
self.setPageListeners();
}
@ -48,11 +48,7 @@ var Game = {
displayCards: function() {
var self = this;
var colors = [];
var shapes;
var fills;
var numbers;
var cartes = [];
$.each(this.cards, function(index, card){
@ -66,9 +62,17 @@ var Game = {
'number': card.number
});
var shapeNode = $('<canvas>');
//var Canvas_width=100;
//var Canvas_height=200;
var shapeNode = $("<canvas></canvas>");
shapeNode.addClass('shape ' + card.color + ' ' + card.shape + ' ' + card.fill);
/*var canvasContext=shapeNode[0].getContext("2d");
canvasContext.beginPath();
canvasContext.rect(0, 0, Canvas_width, Canvas_height);
canvasContext.fillStyle = "#000000";
canvasContext.fill();*/
for (var i = 0; i < card.number; i++) {
cardNode.append(shapeNode.clone());
@ -85,36 +89,80 @@ var Game = {
fills= $.map(cardNode, function(ele) { return $(ele).data("fill"); });
numbers = $.map(cardNode, function(ele) { return $(ele).data("number"); });*/
cartes = $.map(cardNode, function(ele) { return $(ele).data();});
});
},
existingSet: function(cartes) {
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;
console.log(cartes);
var carte1;
var carte2;
var carte3;
/* var i;
//var a[1] = cartes[0];
//console.log(a);
var i, j, k;
var isSet = [];
for (i = 0; i < cartes.length-2; ++i) {
isSet[0] = cartes[i];
for (i = 0; i < cartes1.length-1; ++i) {
isSet[1] = cartes1[i];
for (i = 0; i < cartes2.length; ++i) {
isSet[2] = cartes2[i];
isSet = [];
for(i=0; i<cartes.length-2; i++) {
//isSet.splice(0, 1, cartes[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];
//console.log(carte1, carte2, carte3);
//console.log(i, j , 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) {
cpt = cpt + 1;
}
//console.log(valid);
}
}
}
console.log(isSet);
this.$nbSets.html(self.nbSets);*/
//console.log(carte1, carte2,carte3);
this.$nbSets.html(cpt);
},
setCardListeners: function() {
var self = this;
@ -195,7 +243,7 @@ var Game = {
if($.inArray(el, unique) === -1) unique.push(el);
});
console.log(unique);
//console.log(unique);
return unique.length === 1 || unique.length === 3;
},
@ -223,6 +271,7 @@ var Game = {
// to do - implement game complete check on server
if (!data.gameComplete) {
self.updateCards(data);
self.existingSet();
self.increaseScore();
} else {
self.gameWon();
@ -281,6 +330,14 @@ var Game = {
$(document).ready(Game.deal());
/*
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');

Loading…
Cancel
Save