diff --git a/HyperSet/.idea/workspace.xml b/HyperSet/.idea/workspace.xml index a80ffc2..5e793e1 100644 --- a/HyperSet/.idea/workspace.xml +++ b/HyperSet/.idea/workspace.xml @@ -109,7 +109,8 @@ - + + @@ -153,10 +154,10 @@ - + - + diff --git a/HyperSet/metiers/deck.php b/HyperSet/metiers/deck.php index ae42223..ce8472c 100644 --- a/HyperSet/metiers/deck.php +++ b/HyperSet/metiers/deck.php @@ -197,6 +197,49 @@ class Deck { } } + }elseif ($changes === 'dealHS1') { + $colors = array('green', 'red', 'purple'); + $shapes = array('oval', 'diamond', 'wave'); + $fills = array('solid', 'stripped', 'open'); + $borders = array('plein', 'point', 'rond'); + $numbers = array(1, 2, 3); + + $index1 = 1; + + foreach ($colors as $color) { + foreach ($shapes as $shape) { + foreach ($fills as $fill) { + foreach ($borders as $border) { + foreach ($numbers as $number) { + $cardAttributes = new CardAttributes($color, $shape, $fill, $border, $number, $index1); + $card = new Card($cardAttributes, $this); + $index1++; + } + } + } + } + + } + }elseif ($changes === 'dealHS2') { + $colors = array('green', 'red', 'purple', 'lightblue'); + $shapes = array('oval', 'diamond', 'wave', 'rectangle'); + $fills = array('solid', 'stripped', 'open','quadrillage'); + $numbers = array(1, 2, 3,4); + $border = 'simple'; + + $index2 = 1; + + foreach ($colors as $color) { + foreach ($shapes as $shape) { + foreach ($fills as $fill) { + foreach ($numbers as $number) { + $cardAttributes = new CardAttributes($color, $shape, $fill,$border, $number, $index2); + $card = new Card($cardAttributes, $this); + $index2++; + } + } + } + } } } public function removeSet($cards) { @@ -229,4 +272,7 @@ class Deck { public function fiveMore() { return array_chop($this->cards, 5); } + public function sixMore() { + return array_chop($this->cards, 6); + } } \ No newline at end of file diff --git a/HyperSet/set.php b/HyperSet/set.php index 910c11c..338de67 100644 --- a/HyperSet/set.php +++ b/HyperSet/set.php @@ -55,9 +55,20 @@ if (isset($_GET['action']) && $_GET['action'] == 'deal') { $_SESSION['gameHS0'] = new Game($_SESSION['deckHS0']); $game = $_SESSION['gameHS0']; echo json_encode($game->start(20)); +}else if (isset($_GET['action']) && $_GET['action'] == 'dealHS1') { + $_SESSION['deckHS1'] = new Deck($_GET['action']); + $_SESSION['gameHS1'] = new Game($_SESSION['deckHS1']); + $game = $_SESSION['gameHS1']; + echo json_encode($game->start(55)); +}else if (isset($_GET['action']) && $_GET['action'] == 'dealHS2') { + $_SESSION['deckHS2'] = new Deck($_GET['action']); + $_SESSION['gameHS2'] = new Game($_SESSION['deckHS2']); + $game = $_SESSION['gameHS2']; + echo json_encode($game->start(55)); } + else if (isset($_GET['action']) && $_GET['action'] == 'submit'){ $deck = $_SESSION['deck']; echo json_encode($deck->threeMore()); @@ -89,3 +100,11 @@ else if (isset($_GET['action']) && $_GET['action'] == 'submitHS0'){ $deck = $_SESSION['deckHS0']; echo json_encode($deck->fourMore()); } +else if (isset($_GET['action']) && $_GET['action'] == 'submitHS1'){ + $deck = $_SESSION['deckHS1']; + echo json_encode($deck->fourMore()); +} +else if (isset($_GET['action']) && $_GET['action'] == 'submitHS2'){ + $deck = $_SESSION['deckHS2']; + echo json_encode($deck->sixMore()); +} \ No newline at end of file diff --git a/HyperSet/vues/css/style.css b/HyperSet/vues/css/style.css index 60081a2..6f49e38 100644 --- a/HyperSet/vues/css/style.css +++ b/HyperSet/vues/css/style.css @@ -86,6 +86,14 @@ h1 { width: 800px; transform: rotate(90deg); } +.game-boardHS1 { + margin-top: -5%; + margin-left: 50%; + height: 800px; + width: 800px; + transform: rotate(90deg); +} + .shape { display: inline-block; diff --git a/HyperSet/vues/homePage.html b/HyperSet/vues/homePage.html index be0c915..601f891 100644 --- a/HyperSet/vues/homePage.html +++ b/HyperSet/vues/homePage.html @@ -60,8 +60,8 @@
- - + +
@@ -177,7 +177,7 @@
+ diff --git a/HyperSet/vues/js/Settings.js b/HyperSet/vues/js/Settings.js index d3a528b..403cada 100644 --- a/HyperSet/vues/js/Settings.js +++ b/HyperSet/vues/js/Settings.js @@ -89,6 +89,12 @@ function showGameHS1(){ document.getElementById('gameHS1').style.display='block'; document.getElementById('selectModeHyperSet').style.display='none'; } +function showGameHS2(){ + document.getElementById('gameHS2').style.display='block'; + document.getElementById('selectModeHyperSet').style.display='none'; +} + + @@ -237,3 +243,7 @@ function goSelectModeHyperSet1(){ document.getElementById('gameHS1').style.display='none'; document.getElementById('selectModeHyperSet').style.display='block'; } +function goSelectModeHyperSet2(){ + document.getElementById('gameHS2').style.display='none'; + document.getElementById('selectModeHyperSet').style.display='block'; +} diff --git a/HyperSet/vues/js/set.js b/HyperSet/vues/js/set.js index 9792e3e..e6d93b6 100644 --- a/HyperSet/vues/js/set.js +++ b/HyperSet/vues/js/set.js @@ -67,6 +67,37 @@ var Game = { $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"]'), + + + + + + + + + + + + + + + + @@ -83,6 +114,8 @@ var Game = { var dealRequestHS; var dealRequestHS0; + var dealRequestHS1; + var dealRequestHS2; // ajax request to get initial set of cards dealRequest = $.ajax({ @@ -189,6 +222,28 @@ var Game = { } }); + 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(); + } + }); }, @@ -505,6 +560,83 @@ var Game = { }, + displayCardsHS1: function() { + var self = this; + if (self.cardsHS1.length == 0) { + return false; + } + + + $.each(self.cardsHS1, function(index, card){ + var cardNode = $('
', { + 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 = $(""); + 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($('
')); + } + + }); + }, + displayCardsHS2: function() { + var self = this; + if (self.cardsHS2.length == 0) { + return false; + } + + + $.each(self.cardsHS2, function(index, card){ + var cardNode = $('
', { + class: "card" + }).appendTo(self.$boardHS2); + + + cardNode.data({ + 'id': card.id, + 'shape': card.shape, + 'fill': card.fill, + 'color': card.color, + 'number': card.number + }); + + var shapeNode = $(""); + 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) % 4 === 0) { + self.$boardHS2.append($('
')); + } + + }); + + }, + + + @@ -1074,7 +1206,48 @@ var Game = { }, + 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 === 4) { + self.silentSubmissionHS2(); + } + }); + }, @@ -1165,6 +1338,22 @@ var Game = { 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); + }); + }, @@ -1260,6 +1449,31 @@ var Game = { }, + selectCardHS1: function(card) { + + if (this.selectedHS1.length < 4) { + $(card).addClass('selected'); + this.selectedHS1.push(card); + + } + + }, + selectCardHS2: function(card) { + + if (this.selectedHS2.length < 4) { + $(card).addClass('selected'); + this.selectedHS2.push(card); + + } + + }, + + + + + + + @@ -1336,6 +1550,25 @@ var Game = { $(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'); + }, + + + @@ -1402,7 +1635,18 @@ var Game = { }); 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 = []; + }, @@ -2096,7 +2340,7 @@ var Game = { fills5.push('stripped'); } } - if(numbers1[0] === numbers1[1]){ + if(numbers1[0] === numbers1[2]){ numbers4.push(numbers1[0]); numbers5.push(numbers1[0]); } @@ -2275,42 +2519,626 @@ var Game = { }, + 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]); + // modalité de toutes les 4 cartes + var colors1= $.map(this.selectedHS1, function(el) { return $(el).data("color");}); + var shapes1 = $.map(this.selectedHS1, function(el) { return $(el).data("shape");}); + var fills1= $.map(this.selectedHS1,function(el) { return $(el).data("fill");}); + var borders1= $.map(this.selectedHS1,function(el) { return $(el).data("border");}); + var numbers1 = $.map(this.selectedHS1, function(el) { return $(el).data("number");}); + // modalité des combinaison de carte (ab ac ad ...) pour verifier si forme un set + var colors2= $.map(carteAB, function(el) { return $(el).data("color");}); + var shapes2 = $.map(carteAB, function(el) { return $(el).data("shape");}); + var fills2= $.map(carteAB, function(el) { return $(el).data("fill");}); + var borders2= $.map(carteAB,function(el) { return $(el).data("border");}); + var numbers2 = $.map(carteAB, function(el) { return $(el).data("number");}); + var colors3= $.map(carteCD, function(el) { return $(el).data("color");}); + var shapes3 = $.map(carteCD, function(el) { return $(el).data("shape");}); + var fills3= $.map(carteCD, function(el) { return $(el).data("fill");}); + var borders3= $.map(carteCD,function(el) { return $(el).data("border");}); + var numbers3 = $.map(carteCD, function(el) { return $(el).data("number");}); + var colors4= $.map(carteAC, function(el) { return $(el).data("color");}); + var shapes4 = $.map(carteAC, function(el) { return $(el).data("shape");}); + var fills4= $.map(carteAC, function(el) { return $(el).data("fill");}); + var borders4= $.map(carteAC,function(el) { return $(el).data("border");}); + var numbers4 = $.map(carteAC, function(el) { return $(el).data("number");}); + var colors5= $.map(carteBD, function(el) { return $(el).data("color");}); + var shapes5 = $.map(carteBD, function(el) { return $(el).data("shape");}); + var fills5= $.map(carteBD, function(el) { return $(el).data("fill");}); + var borders5= $.map(carteBD,function(el) { return $(el).data("border");}); + var numbers5 = $.map(carteBD, function(el) { return $(el).data("number");}); + var colors6= $.map(carteAD, function(el) { return $(el).data("color");}); + var shapes6 = $.map(carteAD, function(el) { return $(el).data("shape");}); + var fills6= $.map(carteAD, function(el) { return $(el).data("fill");}); + var borders6= $.map(carteAD,function(el) { return $(el).data("border");}); + var numbers6 = $.map(carteAD, function(el) { return $(el).data("number");}); + var colors7= $.map(carteBC, function(el) { return $(el).data("color");}); + var shapes7 = $.map(carteBC, function(el) { return $(el).data("shape");}); + var fills7= $.map(carteBC, function(el) { return $(el).data("fill");}); + var borders7= $.map(carteBC,function(el) { return $(el).data("border");}); + var numbers7 = $.map(carteBC, function(el) { return $(el).data("number");}); + if(colors1[0] === colors1 [1]){ + colors2.push(colors1[0]); + colors3.push(colors1[0]); + } + else{ + if(colors1[0] === 'red' && colors1[1] === 'green'){ + colors3.push('purple'); + colors2.push('purple'); + } + if(colors1[0] === 'red' && colors1[1] === 'purple'){ + colors3.push('green'); + colors2.push('green'); + } + if(colors1[0] === 'green' && colors1[1] === 'purple'){ + colors3.push('red'); + colors2.push('red'); + } + if(colors1[0] === 'green' && colors1[1] === 'red'){ + colors3.push('purple'); + colors2.push('purple'); + } + if(colors1[0] === 'purple' && colors1[1] === 'red'){ + colors3.push('green'); + colors2.push('green'); + } + if(colors1[0] === 'purple' && colors1[1] === 'green'){ + colors3.push('red'); + colors2.push('red'); + } + } + if(shapes1[0] === shapes1 [1]){ + shapes3.push(shapes1[0]); + shapes2.push(shapes1[0]); + } + else{ + if(shapes1[0] === 'oval' && shapes1[1] === 'diamond'){ + shapes3.push('wave'); + shapes2.push('wave'); + } + if(shapes1[0] === 'oval' && shapes1[1] === 'wave'){ + shapes3.push('diamond'); + shapes2.push('diamond'); + } + if(shapes1[0] === 'diamond' && shapes1[1] === 'oval'){ + shapes3.push('wave'); + shapes2.push('wave'); + } + if(shapes1[0] === 'diamond' && shapes1[1] === 'wave'){ + shapes3.push('oval'); + shapes2.push('oval'); + } - validateSet0: function() { - var self = this; - - console.log(this.selected0); + if(shapes1[0] === 'wave' && shapes1[1] === 'diamond'){ + shapes3.push('oval'); + shapes2.push('oval'); + } + if(shapes1[0] === 'wave' && shapes1[1] === 'oval'){ + shapes3.push('diamond'); + shapes2.push('diamond'); + } + } + if(fills1[0] === fills1 [1]){ + fills3.push(fills1[0]); + fills2.push(fills1[0]); + } + else{ + if(fills1[0] === 'solid' && fills1[1] === 'stripped'){ + fills3.push('open'); + fills2.push('open'); + } + + if(fills1[0] === 'solid' && fills1[1] === 'open'){ + fills3.push('stripped'); + fills2.push('stripped'); + } + + if(fills1[0] === 'stripped' && fills1[1] === 'open'){ + fills3.push('solid'); + fills2.push('solid'); + } + if(fills1[0] === 'open' && fills1[1] === 'stripped'){ + fills3.push('solid'); + fills2.push('solid'); + } + + if(fills1[0] === 'stripped' && fills1[1] === 'solid'){ + fills3.push('open'); + fills2.push('open'); + } + if(fills1[0] === 'open' && fills1[1] === 'solid'){ + fills3.push('stripped'); + fills2.push('stripped'); + } + } + + if(borders1[0] === borders1 [1]){ + borders3.push(borders1[0]); + borders2.push(borders1[0]); + } + else{ + if(borders1[0] === 'plein' && borders1[1] === 'point'){ + borders3.push('rond'); + borders2.push('rond'); + } + + if(borders1[0] === 'point' && borders1[1] === 'plein'){ + borders3.push('rond'); + borders2.push('rond'); + } + + if(borders1[0] === 'rond' && borders1[1] === 'plein'){ + borders3.push('point'); + borders2.push('point'); + } + if(borders1[0] === 'plein' && borders1[1] === 'rond'){ + borders3.push('point'); + borders2.push('point'); + } + + if(borders1[0] === 'rond' && borders1[1] === 'point'){ + borders3.push('plein'); + borders2.push('plein'); + } + if(borders1[0] === 'point' && borders1[1] === 'rond'){ + borders3.push('plein'); + borders2.push('plein'); + } + } + + if(numbers1[0] === numbers1[1]){ + numbers3.push(numbers1[0]); + numbers2.push(numbers1[0]); + } + else{ + if(numbers1[0] === 1 && numbers1[1] === 2){ + numbers3.push(3); + numbers2.push(3); + } + + if(numbers1[0] === 1 && numbers1[1] === 3){ + numbers3.push(2); + numbers2.push(2); + } + + if(numbers1[0] === 2 && numbers1[1] === 1){ + numbers3.push(3); + numbers2.push(3); + } + if(numbers1[0] === 2 && numbers1[1] === 3){ + numbers3.push(1); + numbers2.push(1); + } + + if(numbers1[0] === 3 && numbers1[1] === 1){ + numbers3.push(2); + numbers2.push(2); + } + if(numbers1[0] === 3 && numbers1[1] === 2){ + numbers3.push(1); + numbers2.push(1); + } + + } + if(colors1[0] === colors1 [2]){ + colors4.push(colors1[0]); + colors5.push(colors1[0]); + } + else{ + if(colors1[0] === 'red' && colors1[2] === 'green'){ + colors4.push('purple'); + colors5.push('purple'); + } + + if(colors1[0] === 'red' && colors1[2] === 'purple'){ + colors4.push('green'); + colors5.push('green'); + } + + if(colors1[0] === 'green' && colors1[2] === 'purple'){ + colors5.push('red'); + colors4.push('red'); + } + if(colors1[0] === 'green' && colors1[2] === 'red'){ + colors4.push('purple'); + colors5.push('purple'); + } + + if(colors1[0] === 'purple' && colors1[2] === 'red'){ + colors4.push('green'); + colors5.push('green'); + } + if(colors1[0]=== 'purple' && colors1[2] === 'green'){ + colors4.push('red'); + colors5.push('red'); + } + } + if(shapes1[0] === shapes1 [2]){ + shapes4.push(shapes1[0]); + shapes5.push(shapes1[0]); + } + else{ + if(shapes1[0] === 'oval' && shapes1[2] === 'diamond'){ + shapes4.push('wave'); + shapes5.push('wave'); + } + + if(shapes1[0] === 'oval' && shapes1[2] === 'wave'){ + shapes4.push('diamond'); + shapes5.push('diamond'); + } + + if(shapes1[0] === 'diamond' && shapes1[2] === 'oval'){ + shapes4.push('wave'); + shapes5.push('wave'); + } + if(shapes1[0] === 'diamond' && shapes1[2] === 'wave'){ + shapes4.push('oval'); + shapes5.push('oval'); + } + + if(shapes1[0] === 'wave' && shapes1[2] === 'diamond'){ + shapes4.push('oval'); + shapes5.push('oval'); + } + if(shapes1[0] === 'wave' && shapes1[2] === 'oval'){ + shapes4.push('diamond'); + shapes5.push('diamond'); + } + + } + if(fills1[0] === fills1 [2]){ + fills5.push(fills1[0]); + fills4.push(fills1[0]); + } + else{ + if(fills1[0] === 'solid' && fills1[2] === 'stripped'){ + fills4.push('open'); + fills5.push('open'); + } + + if(fills1[0] === 'solid' && fills1[2] === 'open'){ + fills4.push('stripped'); + fills5.push('stripped'); + } + + if(fills1[0] === 'stripped' && fills1[2] === 'open'){ + fills4.push('solid'); + fills5.push('solid'); + } + if(fills1[0] === 'open' && fills1[2] === 'stripped'){ + fills4.push('solid'); + fills5.push('solid'); + } + + if(fills1[0] === 'stripped' && fills1[2] === 'solid'){ + fills4.push('open'); + fills5.push('open'); + } + if(fills1[0] === 'open' && fills1[2] === 'solid'){ + fills4.push('stripped'); + fills5.push('stripped'); + } + } + if(borders1[0] === borders1 [2]){ + borders4.push(borders1[0]); + borders5.push(borders1[0]); + } + else{ + if(borders1[0] === 'plein' && borders1[2] === 'point'){ + borders4.push('rond'); + borders5.push('rond'); + } + + if(borders1[0] === 'point' && borders1[2] === 'plein'){ + borders4.push('rond'); + borders5.push('rond'); + } + + if(borders1[0] === 'rond' && borders1[2] === 'plein'){ + borders4.push('point'); + borders5.push('point'); + } + if(borders1[0] === 'plein' && borders1[2] === 'rond'){ + borders4.push('point'); + borders5.push('point'); + } + + if(borders1[0] === 'rond' && borders1[2] === 'point'){ + borders4.push('plein'); + borders5.push('plein'); + } + if(borders1[0] === 'point' && borders1[2] === 'rond'){ + borders4.push('plein'); + borders5.push('plein'); + } + } + if(numbers1[0] === numbers1[2]){ + numbers4.push(numbers1[0]); + numbers5.push(numbers1[0]); + } + else{ + if(numbers1[0] === 1 && numbers1[2] === 2){ + numbers4.push(3); + numbers5.push(3); + } + + if(numbers1[0] === 1 && numbers1[2] === 3){ + numbers4.push(2); + numbers5.push(2); + } + + if(numbers1[0] === 2 && numbers1[2] === 1){ + numbers4.push(3); + numbers5.push(3); + } + if(numbers1[0] === 2 && numbers1[2] === 3){ + numbers4.push(1); + numbers5.push(1); + } + + if(numbers1[0] === 3 && numbers1[2] === 1){ + numbers4.push(2); + numbers5.push(2); + } + if(numbers1[0] === 3 && numbers1[2] === 2){ + numbers4.push(1); + numbers5.push(1); + } + } + if(colors1[0] === colors1 [3]){ + colors6.push(colors1[0]); + colors7.push(colors1[0]); + } + else{ + if(colors1[0] === 'red' && colors1[3] === 'green'){ + colors6.push('purple'); + colors7.push('purple'); + } + + if(colors1[0] === 'red' && colors1[3] === 'purple'){ + colors6.push('green'); + colors7.push('green'); + } + + if(colors1[0] === 'green' && colors1[3] === 'purple'){ + colors6.push('red'); + colors7.push('red'); + } + if(colors1[0] === 'green' && colors1[3] === 'red'){ + colors6.push('purple'); + colors7.push('purple'); + } + + if(colors1[0] === 'purple' && colors1[3] === 'red'){ + colors6.push('green'); + colors7.push('green'); + } + if(colors1[0]=== 'purple' && colors1[3] === 'green'){ + colors6.push('red'); + colors7.push('red'); + } + } + if(shapes1[0] === shapes1 [3]){ + shapes6.push(shapes1[0]); + shapes7.push(shapes1[0]); + } + else{ + if(shapes1[0] === 'oval' && shapes1[3] === 'diamond'){ + shapes6.push('wave'); + shapes7.push('wave'); + } + + if(shapes1[0] === 'oval' && shapes1[3] === 'wave'){ + shapes6.push('diamond'); + shapes7.push('diamond'); + } + + if(shapes1[0] === 'diamond' && shapes1[3] === 'oval'){ + shapes6.push('wave'); + shapes7.push('wave'); + } + if(shapes1[0] === 'diamond' && shapes1[3] === 'wave'){ + shapes6.push('oval'); + shapes7.push('oval'); + } + + if(shapes1[0] === 'wave' && shapes1[3] === 'diamond'){ + shapes6.push('oval'); + shapes7.push('oval'); + } + if(shapes1[0] === 'wave' && shapes1[3] === 'oval'){ + shapes6.push('diamond'); + shapes7.push('diamond'); + } + + } + if(fills1[0] === fills1 [3]){ + fills6.push(fills1[0]); + fills7.push(fills1[0]); + } + else{ + if(fills1[0] === 'solid' && fills1[3] === 'stripped'){ + fills6.push('open'); + fills7.push('open'); + } + + if(fills1[0] === 'solid' && fills1[3] === 'open'){ + fills6.push('stripped'); + fills7.push('stripped'); + } + + if(fills1[0] === 'stripped' && fills1[3] === 'open'){ + fills6.push('solid'); + fills7.push('solid'); + } + if(fills1[0] === 'open' && fills1[3] === 'stripped'){ + fills6.push('solid'); + fills7.push('solid'); + } + + if(fills1[0] === 'stripped' && fills1[3] === 'solid'){ + fills6.push('open'); + fills7.push('open'); + } + if(fills1[0] === 'open' && fills1[3] === 'solid'){ + fills6.push('stripped'); + fills7.push('stripped'); + } + } + if(borders1[0] === borders1 [3]){ + borders6.push(borders1[0]); + borders7.push(borders1[0]); + } + else{ + if(borders1[0] === 'plein' && borders1[3] === 'point'){ + borders6.push('rond'); + borders7.push('rond'); + } + + if(borders1[0] === 'point' && borders1[3] === 'plein'){ + borders6.push('rond'); + borders7.push('rond'); + } + + if(borders1[0] === 'rond' && borders1[3] === 'plein'){ + borders6.push('point'); + borders7.push('point'); + } + if(borders1[0] === 'plein' && borders1[3] === 'rond'){ + borders6.push('point'); + borders7.push('point'); + } + + if(borders1[0] === 'rond' && borders1[3] === 'point'){ + borders6.push('plein'); + borders7.push('plein'); + } + if(borders1[0] === 'point' && borders1[3] === 'rond'){ + borders6.push('plein'); + borders7.push('plein'); + } + } + + if(numbers1[0] === numbers1[3]){ + numbers6.push(numbers1[0]); + numbers7.push(numbers1[0]); + } + else{ + if(numbers1[0] === 1 && numbers1[3] === 2){ + numbers6.push(3); + numbers7.push(3); + } + + if(numbers1[0] === 1 && numbers1[3] === 3){ + numbers6.push(2); + numbers7.push(2); + } + + if(numbers1[0] === 2 && numbers1[3] === 1){ + numbers6.push(3); + numbers7.push(3); + } + if(numbers1[0] === 2 && numbers1[3] === 3){ + numbers6.push(1); + numbers7.push(1); + } + + if(numbers1[0] === 3 && numbers1[3] === 1){ + numbers6.push(2); + numbers7.push(2); + } + if(numbers1[0] === 3 && numbers1[3] === 2){ + numbers6.push(1); + numbers7.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) + } + if(this.isSet(colors4) && this.isSet(shapes4) && this.isSet(fills4) && this.isSet(borders4) && this.isSet(numbers4)){ + return this.isSet(colors5)&& this.isSet(shapes5)&& this.isSet(fills5) && this.isSet(borders5) && this.isSet(numbers5) + } + if(this.isSet(colors6) && this.isSet(shapes6) && this.isSet(fills6) && this.isSet(borders6) && this.isSet(numbers6)) { + return this.isSet(colors7) && this.isSet(shapes7) && this.isSet(fills7) && this.isSet(borders7) && this.isSet(numbers7) + } + + }, + + + validateHyperSet2: function() { + + }, + + + + + + + + + + + + + + + + + + + + + + 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"); }); - console.log(colors); - return (self.isSet(colors) && self.isSet(shapes) && self.isSet(numbers)); }, @@ -2322,8 +3150,6 @@ var Game = { 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)); }, @@ -2406,9 +3232,6 @@ var Game = { if($.inArray(el, unique) === -1) unique.push(el); }); - - - //console.log(unique); return unique.length === 1 || unique.length === 4; }, @@ -2418,9 +3241,6 @@ var Game = { $.each(arr, function(i, el){ if($.inArray(el, unique) === -1) unique.push(el); }); - - - //console.log(unique); return unique.length === 1 || unique.length === 5; }, @@ -2478,18 +3298,27 @@ var Game = { silentSubmissionHS: function() { var valid = this.validateHyperSet(); if (valid) { - console.log(valid); this.submitSetHS(); } }, silentSubmissionHS0: function() { var valid = this.validateHyperSet0(); if (valid) { - console.log(valid); this.submitSetHS0(); } }, - + silentSubmissionHS1: function() { + var valid = this.validateHyperSet1(); + if (valid) { + this.submitSetHS1(); + } + }, + silentSubmissionHS2: function() { + var valid = this.validateHyperSet2(); + if (valid) { + this.submitSetHS2(); + } + }, @@ -2756,6 +3585,68 @@ var Game = { 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(); + }, + + @@ -2977,6 +3868,55 @@ var Game = { } }, + + 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.displayCardsH2(); + if(self.cardsHS2.length === 0){ + alert("you won!"); + } + }, @@ -3060,6 +4000,12 @@ var Game = { increaseScoreHS0: function() { this.$scoreHS0.html(++this.scoreHS0); }, + increaseScoreHS1: function() { + this.$scoreHS1.html(++this.scoreHS1); + }, + increaseScoreHS2: function() { + this.$scoreHS2.html(++this.scoreHS2); + },