ajout des données mode de jeux, affichage a revoir

master
readhame 5 years ago
parent 12101d0ecb
commit 54cd0e64e5

@ -29,8 +29,8 @@
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="HTML File" />
<option value="JavaScript File" />
<option value="HTML File" />
</list>
</option>
</component>
@ -44,16 +44,12 @@
<property name="DefaultHtmlFileTemplate" value="HTML File" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../set-master" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="ReadonlyStatusHandler">
<option name="SHOW_DIALOG" value="false" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\wamp64\www\HyperSet\vues\images" />
<recent name="C:\wamp64\www\HyperSet\vues" />
<recent name="C:\wamp64\www\HyperSet" />
<recent name="C:\wamp64\www\HyperSet\bdd" />
<recent name="C:\wamp64\www\HyperSet\site\vues\js" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\wamp64\www\HyperSet\DAL" />
<recent name="C:\wamp64\www\HyperSet\site\vues" />
@ -61,6 +57,13 @@
<recent name="C:\wamp64\www\HyperSet" />
<recent name="C:\wamp64\www\HyperSet\vues\css" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\wamp64\www\HyperSet\vues" />
<recent name="C:\wamp64\www\HyperSet\vues\images" />
<recent name="C:\wamp64\www\HyperSet" />
<recent name="C:\wamp64\www\HyperSet\bdd" />
<recent name="C:\wamp64\www\HyperSet\site\vues\js" />
</key>
</component>
<component name="SvnConfiguration">
<configuration />
@ -93,6 +96,9 @@
<workItem from="1592564170927" duration="15576000" />
<workItem from="1592817049643" duration="21843000" />
<workItem from="1592908388600" duration="21604000" />
<workItem from="1592989402859" duration="14949000" />
<workItem from="1593080270400" duration="16461000" />
<workItem from="1593102504672" duration="528000" />
</task>
<servers />
</component>
@ -132,9 +138,17 @@
<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="1592908755965">
<state x="1136" y="344" key="com.intellij.ide.util.TipDialog" timestamp="1593102507519">
<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="1593102507519" />
<state x="701" y="162" key="refactoring.ChangeSignatureDialog" timestamp="1593090265720">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="701" y="162" key="refactoring.ChangeSignatureDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1593090265720" />
<state x="202" y="435" key="vcs.readOnlyHandler.ReadOnlyStatusDialog" timestamp="1592990595770">
<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="1592908755965" />
<state x="202" y="435" key="vcs.readOnlyHandler.ReadOnlyStatusDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1592990595770" />
</component>
</project>

@ -1,17 +1,51 @@
<?php
class CardAttributes {
public $color;
public $shape;
public $fill;
public $number;
public $id;
function __construct($color, $shape, $fill, $number, $id) {
$this->color = $color;
$this->shape = $shape;
$this->fill = $fill;
$this->number = $number;
$this->id = $id;
public $color;
public $shape;
public $fill;
public $number;
public $border;
public $id;
/*
$num=func_num_args();
switch($num)
{
case 1:
//4 paramètres passés
$this->color=func_get_arg(0);
$this->shape=func_get_arg(1);
$this->fill=func_get_arg(2);
$this->number=func_get_arg(3);
$this->id=func_get_arg(4);
break;
case 2:
//5 paramètres passés
$this->color=func_get_arg(0);
$this->shape=func_get_arg(1);
$this->fill=func_get_arg(2);
$this->number=func_get_arg(3);
$this->id=func_get_arg(4);
$this->border=func_get_arg(5);
break;
default:
}
}*/
function __construct($color, $shape, $fill, $border, $number, $id) {
$this->color = $color;
$this->shape = $shape;
$this->fill = $fill;
$this->border = $border;
$this->number = $number;
$this->id = $id;
}
}

@ -14,37 +14,121 @@ class Deck {
private function createDeck($changes)
{
$colors = [];
if ($changes === 'deal') {
$colors = array('green', 'red', 'purple');
}elseif ($changes === 'deal1') {
$colors = array('yellow', 'blue', 'gray');
}
$shapes = array('oval', 'diamond', 'wave');
$fills = array('solid', 'stripped', 'open');
$numbers = array(1, 2, 3);
$index = 1;
foreach ($colors as $color) {
foreach ($shapes as $shape) {
foreach ($fills as $fill) {
foreach ($numbers as $number) {
$cardAttributes = new CardAttributes($color, $shape, $fill, '', $number, $index);
$card = new Card($cardAttributes, $this);
$index++;
}
}
}
}
}elseif ($changes === 'deal1') {
$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);
$index = 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, $index);
$card = new Card($cardAttributes, $this);
$index++;
}
}
}
}
}
}elseif ($changes === 'deal2') {
$colors = array('green', 'red', 'purple', 'lightblue');
$shapes = array('oval', 'diamond', 'wave', 'rectangle');
$fills = array('solid', 'stripped', 'open','quadrillage');
$numbers = array(1, 2, 3,4);
$index = 1;
foreach ($colors as $color) {
foreach ($shapes as $shape) {
foreach ($fills as $fill) {
foreach ($numbers as $number) {
$cardAttributes = new CardAttributes($color, $shape, $fill, $number, $index);
$cardAttributes = new CardAttributes($color, $shape, $fill,'', $number, $index);
$card = new Card($cardAttributes, $this);
$index++;
}
}
}
}
}elseif ($changes === 'deal3') {
$colors = array('green', 'red', 'purple', 'lightblue');
$shapes = array('oval', 'diamond', 'wave', 'rectangle');
$fills = array('solid', 'stripped', 'open','quadrillage');
$borders = array ('plein','point','rond','zigzag');
$numbers = array(1, 2, 3,4);
$index = 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, $index);
$card = new Card($cardAttributes, $this);
$index++;
}
}
}
}
}
}elseif ($changes === 'deal4') {
$colors = array('green', 'red', 'purple', 'lightblue', 'yellow');
$shapes = array('oval', 'diamond', 'wave', 'rectangle','triangle');
$fills = array('solid', 'stripped', 'open', 'quadrillage','pointille');
$borders = array('plein', 'point', 'rond', 'zigzag','hachure');
$numbers = array(1, 2, 3, 4, 5);
$index = 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, $index);
$card = new Card($cardAttributes, $this);
$index++;
}
}
}
}
}
}
}
public function removeSet($cards) {
}
private function shuffle() {

@ -5,14 +5,9 @@ include "metiers/game.php";
session_start();
$deck;
if (isset($_GET['action']) && $_GET['action'] == 'deal') {
$_SESSION['deck'] = new Deck($_GET['action']);
$_SESSION['game'] = new Game($_SESSION['deck']);
$game = $_SESSION['game'];
echo json_encode($game->start());
} else if (isset($_GET['action']) && $_GET['action'] == 'deal1') {
if (isset($_GET['action']) && !empty($_GET['action'])) {
$_SESSION['deck'] = new Deck($_GET['action']);
$_SESSION['game'] = new Game($_SESSION['deck']);
$game = $_SESSION['game'];

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="vues/css/style-page.css" />
<title>Title</title>
</head>
<body>
<div data-display="game-board"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="vues/js/set.js"></script>
</body>
</html>

@ -1,6 +1,6 @@
:root {
--background: #ffffff;
--text-color: #393939;
--text-color: black;
}
.dark {
@ -351,4 +351,56 @@ input:checked + .slider .on {
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/*
.card {
display: table-cell;
border: 1px solid #000;
border-radius: 6px;
width: 300px;
height: 400px;
}*/
.game-button {
font-size: 5vh;
height: 8vh;
margin: 0.7vh;
width: 50vh;
cursor: pointer;
font-family: textFont, sans-serif;
font-weight: bold;
border: 2px solid var(--background);
border-radius: 10px;
transition-duration: 0.4s;
color: var(--background);
padding-left: 5%;
padding-top: 1%;
background: var(--text-color);
left: 10px;
}
.game-button-mode {
position: absolute;
top: 55%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
display: block;
width: 50vh;
}
.disable-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.mode-title {
font-size: 4.5vw;
margin-top: 2%;
position: absolute;
color: var(--text-color);
width: 100%;
font-weight: bold;
text-align: center;
font-family: textFont, sans-serif;
}

@ -32,9 +32,9 @@ h1 {
.card {
display: table-cell;
width: 190px;
margin-right: 5px;
height: 310px;
width: 250px;
height: 200px;
border: 2px solid #ccc;
background: #F5F5F5;
}
@ -50,7 +50,7 @@ h1 {
.game-board {
height: 1000px;
margin-left: 22%;
margin-right: 22%;
transform: rotate(90deg);
}
@ -61,7 +61,9 @@ h1 {
height: 100px;
-webkit-mask-repeat: no-repeat;
-webkit-mask-position: 15px;
margin-top: 55%;
margin-top: 22%;
}

@ -3,17 +3,34 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="vues/css/style-page.css">
<link rel="stylesheet" href="vues/css/style.css" />
<link rel="stylesheet" href="vues/css/style.css">
</head>
<title>Set</title>
</head>
<body>
<H1 class="colortext" >HyperSet</H1>
<div class="play-btn">
<img class="playsmall-btn" id="playBtn" src="vues/images/play.png" onclick=" showGame()" style="display: block;">
<div class="play-btn" id="home">
<img class="playsmall-btn" id="playBtn" src="vues/images/play.png" onclick=" showModeGame()" style="display: block;">
</div>
<div id="selectModeSet" class="select-mode-div divs" style="display: none;">
<h2 class="mode-title disable-select text" id="selectGame">Modes de jeu </h2>
<div class="explain-btn small-btn">
<img class="small-btn" id="homeBtn" onclick="changeDiv('home');" src="vues/images/home.png">
</div>
<div class="game-button-mode">
<button class="game-button text" id="playSimpleSet" onclick="showGame();">SET! 3*4</button>
<button class="game-button text" id="playSimpleSetLast" onclick="showGame1();">SET! 3*5</button>
<button class="game-button text" id="playSetFour" onclick="showGame2();">SET! 4*4</button>
<button class="game-button text" id="playSimpleSetFive" onclick="showGame3();">SET! 4*5</button>
<button class="game-button text" id="playSetFive" onclick="showGame4();">SET! 5*5</button>
</div>
</div>
@ -23,12 +40,50 @@
<p>Find sets.</p>
<p>Sets found: <span data-display="score" class="score">0</span></p>
<p>Number of Sets: <span data-display="nbSets" class="nbSets"></span></p>
<form method="get">
<input type="number" name="nombreC" id="nombreC" placeholder="Nombre de carte" aria-label="Nombre de carte">
<div>
<button type="submit">Envoyer le message</button>
</div>
</form>
<div id="carte" class="game-board" data-display="game-board"></div>
</div>
<div id='game1' class="wrapper" style="display: none;">
<h1>(TEST) Set</h1>
<p>Find sets.</p>
<p>Sets found: <span data-display="score1" class="score"></span></p>
<p>Number of Sets: <span data-display="nbSets1" class="nbSets"></span></p>
<div class="game-board" data-display="game-board1"></div>
</div>
<div id='game2' class="wrapper" style="display: none;">
<h1>(TEST) Set</h1>
<p>Find sets.</p>
<p>Sets found: <span data-display="score2" class="score">0</span></p>
<p>Number of Sets: <span data-display="nbSets2" class="nbSets"></span></p>
<div class="game-board" data-display="game-board2"></div>
</div>
<div id='game3' class="wrapper" style="display: none;">
<h1>(TEST) Set</h1>
<p>Find sets.</p>
<p>Sets found: <span data-display="score3" class="score">0</span></p>
<p>Number of Sets: <span data-display="nbSets3" class="nbSets"></span></p>
<div class="game-board" data-display="game-board3"></div>
</div>
<div id='game4' class="wrapper" style="display: none;">
<h1>(TEST) Set</h1>
<p>Find sets.</p>
<p>Sets found: <span data-display="score4" class="score">0</span></p>
<p>Number of Sets: <span data-display="nbSets4" class="nbSets"></span></p>
<div class="game-board" data-display="game-board4"></div>
</div>
<div class="settings-btn">
@ -110,7 +165,7 @@
<a href="index.php?action=VoirScore">Voir Les Scores</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="vues/js/Settings.js"></script>
<script src="vues/js/set.js"></script>

@ -36,6 +36,19 @@ selectColor.addEventListener('change', function() {
*/
/*var mode;
let selectMode = document.getElementById('mode-selector');
selectMode.addEventListener('change', function() {
var index = selectMode.selectedIndex;
// Rapporter cette donnée au <p>
if (index != null){
mode= index;
}
});*/
var popupSettings = document.getElementById('popupSettings');
var popupExplain = document.getElementById('popupExplain');
@ -48,7 +61,7 @@ window.onclick = function(event) {
if (event.target === popupExplain) {
popupExplain.style.display = "none";
}
}
};
function showSettings(){
document.getElementById('popupSettings').style.display='block';
@ -62,10 +75,32 @@ function showExplain(){
function showGame(){
document.getElementById('game').style.display='block';
}
function showGame1(){
document.getElementById('game1').style.display='block';
}
function showGame2(){
document.getElementById('game2').style.display='block';
}
function showGame3(){
document.getElementById('game3').style.display='block';
}
function showGame4(){
document.getElementById('game4').style.display='block';
}
function showModeGame(){
document.getElementById('selectModeSet').style.display='block';
document.getElementById('playBtn').style.display='none';
}
function closeExplainPopup() {
document.getElementById('popupExplain').style.display='none';
}

@ -1,28 +1,69 @@
var colorr = 0;
var mode = 0;
document.getElementById('playSimpleSet').addEventListener('click', function(){ mode = 0;});
document.getElementById('playSimpleSetLast').addEventListener('click',function(){mode = 1;});
document.getElementById('playSetFour').addEventListener('click',function(){ mode = 2;});
document.getElementById('playSimpleSetFive').addEventListener('click', function(){mode = 3;} );
document.getElementById('playSetFive').addEventListener('click', function(){mode = 4;} );
var Game = {
cards: [],
selected: [],
setCards: [],
nbSets: 0,
score: 0,
$board: $('[data-display="game-board"]'),
$score: $('[data-display="score"]'),
$nbSets: $('[data-display="nbSets"]'),
cards1 : [],
selected1: [],
score1: 0 ,
$score1: $('[data-display="score1"]'),
$nbSets1: $('[data-display="nbSets1"]'),
$board1: $('[data-display="game-board1"]'),
cards2 : [],
selected2: [],
score2: 0 ,
$score2: $('[data-display="score2"]'),
$nbSets2: $('[data-display="nbSets2"]'),
$board2: $('[data-display="game-board2"]'),
cards3 : [],
selected3: [],
score3: 0 ,
$score3: $('[data-display="score3"]'),
$nbSets3: $('[data-display="nbSets3"]'),
$board3: $('[data-display="game-board3"]'),
cards4: [],
selected4 : [],
score4: 0,
$score4: $('[data-display="score4"]'),
$nbSets4: $('[data-display="nbSets4"]'),
$board4: $('[data-display="game-board4"]'),
deal: function() {
var self = this;
if (colorr === 0 || colorr === null) {
var dealRequest;
var dealRequest1;
var dealRequest2;
var dealRequest3;
var dealRequest4;
// ajax request to get initial set of cards
var dealRequest = $.ajax({
dealRequest = $.ajax({
url: 'set.php?action=deal',
type: 'GET',
dataType: 'json',
success: function(data) {
success: function (data) {
self.cards = data;
self.displayCards.call(self);
self.existingSet();
@ -30,31 +71,65 @@ var Game = {
self.setPageListeners();
}
});
}else if (colorr === 1){
var dealRequest1 = $.ajax({
dealRequest1 = $.ajax({
url: 'set.php?action=deal1',
type: 'GET',
dataType: 'json',
success: function(data) {
success: function (data) {
self.cards1 = data;
self.displayCards1.call(self);
self.existingSet1();
}
});
dealRequest2 = $.ajax({
url: 'set.php?action=deal2',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards = data;
self.displayCards.call(self);
self.setCardListeners();
self.setPageListeners();
self.displayCards2.call(self);
}
});
dealRequest3 = $.ajax({
url: 'set.php?action=deal3',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards = data;
self.displayCards3.call(self);
}
});
dealRequest4 = $.ajax({
url: 'set.php?action=deal4',
type: 'GET',
dataType: 'json',
success: function (data) {
self.cards = data;
self.displayCards4.call(self);
}
});
}
},
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);
$.each(this.cards, function(index, card){
var cardNode = $('<div>');
cardNode.addClass('card');
$(cardNode).data({
cardNode.data({
'id': card.id,
'shape': card.shape,
'fill': card.fill,
@ -62,17 +137,8 @@ var Game = {
'number': card.number
});
//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());
@ -84,16 +150,162 @@ var Game = {
self.$board.append($('<div>'));
}
/*colors = $.map(cardNode, function(ele) { return $(ele).data("color");});
shapes = $.map(cardNode, function(ele) { return $(ele).data("shape"); });
fills= $.map(cardNode, function(ele) { return $(ele).data("fill"); });
numbers = $.map(cardNode, function(ele) { return $(ele).data("number"); });*/
});
},
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) % 3 === 0) {
self.$board1.append($('<div>'));
}
});
},
displayCards2: function() {
var self = this;
if (self.cards1.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) % 3 === 0) {
self.$board2.append($('<div>'));
}
});
},
displayCards3: function() {
var self = this;
if (self.cards1.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) % 3 === 0) {
self.$board3.append($('<div>'));
}
});
},
displayCards4: function() {
var self = this;
if (self.cards1.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) % 3 === 0) {
self.$board4.append($('<div>'));
}
});
},
existingSet: function() {
@ -113,24 +325,17 @@ var Game = {
var carte2;
var carte3;
//var a[1] = cartes[0];
//console.log(a);
var i, j, k;
var 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);
@ -153,16 +358,82 @@ var Game = {
if (valid) {
cpt = cpt + 1;
}
//console.log(valid);
}
}
}
//console.log(carte1, carte2,carte3);
this.$nbSets.html(cpt);
},
existingSet1: function() {
var colors = [];
var shapes =[];
var fills= [];
var borders = [];
var numbers= [];
var valid;
var self = this;
var cartes = self.cards1;
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);
borders.splice(0,1,carte1.border);
borders.splice(1,1,carte2.border);
borders.splice(2,1,carte3.border);
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) && self.isSet(borders) ;
if (valid) {
cpt = cpt + 1;
}
}
}
}
this.$nbSets1.html(cpt);
},
setCardListeners: function() {
var self = this;
@ -237,17 +508,93 @@ var Game = {
return (self.isSet(colors) && self.isSet(shapes) && self.isSet(fills) && self.isSet(numbers));
},
validateSet35: 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 borders= $.map(self.selected, function(el) { return $(el).data("border"); });
var numbers = $.map(self.selected, 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.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.isSet4(colors) && self.isSet4(shapes) && self.isSet4(fills) && self.isSet4(numbers));
},
validateSet45: 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 borders= $.map(self.selected, function(el) { return $(el).data("border"); });
var numbers = $.map(self.selected, 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.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 borders= $.map(self.selected, function(el) { return $(el).data("border"); });
var numbers = $.map(self.selected, 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);
});
//console.log(unique);
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);
});
//console.log(unique);
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);
});
//console.log(unique);
return unique.length === 1 || unique.length === 5;
},
silentSubmission: function() {
var valid = this.validateSet();
if (valid) {
@ -328,7 +675,38 @@ var Game = {
$(document).ready(Game.deal());
Game.deal();
/*
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" );

@ -14,14 +14,7 @@
</select>
</div>
<hr class="hr-settings-lang">
<div class="custom-select ">
<h2 id="daltoSettings">RÉGLAGES COULEURS 0</h2>
<select id="color-selector">
<option class="text" id="normal" value="normal" onclick="changeColorMode()">Normale</option>
<option class="text" id="Daltonien" value="Daltonien" onclick="changeColorMode()">Daltonien</option>
</select>
</div>
<hr class="hr-settings-color">
<a href="../set.html">Jouer</a>

Loading…
Cancel
Save