From 6c4fea36c2c6ef1023769dcaee31fbaedc7db5a4 Mon Sep 17 00:00:00 2001 From: kplaczek Date: Mon, 14 Aug 2017 20:21:31 +0200 Subject: [PATCH] =?UTF-8?q?nie=20mo=C5=BCna=20wybra=C4=87=20wi=C4=99cej=20?= =?UTF-8?q?ni=C5=BC=207=20monet=20na=20raz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- js/script.js | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e64484e..1d481ca 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,10 @@ Do zrobienia: - [x] wyświetlenie żetonu wielbłąda - [x] przydzielenie żetonu wielbłąda przed wyświetleniem wyniku - [ ] rozwiązywanie sprawy z remisem -- [ ] przydzielanie bonusów nawet jak nie żetonów danej karty +- [x] przydzielanie bonusów nawet jak nie żetonów danej karty - [x] pobieranie żetonów po kliknięciu na żetonu - [x] losowanie wartości bonusowych żetonów kart - [x] zliczanie punków - [x] informowanie o zakończeniu rundy -- [x] przydzielanie żetonu Maharadży \ No newline at end of file +- [x] przydzielanie żetonu Maharadży +- [x] nie można wybrać więcej niż 7 monet na raz \ No newline at end of file diff --git a/js/script.js b/js/script.js index 3777555..aec9cee 100644 --- a/js/script.js +++ b/js/script.js @@ -131,7 +131,17 @@ function game(player1, player2, board) { }; this.showAcceptButton = function () { - if (!!jaipur.activePlayer && !!document.querySelector('.coin.selected')) { + + console.info(jaipur.selectedCointType); + if (!!jaipur.activePlayer && !!document.querySelector('.coin.selected') && + ((document.querySelectorAll('.coin.selected').length >= 2 && + !!['silver', 'gold', 'diamond'].indexOf(jaipur.selectedCointType) + ) || ( + document.querySelectorAll('.coin.selected').length >= 1 && + !!['fabric', 'spice', 'leather'].indexOf(jaipur.selectedCointType) + ) + ) + ) { document.querySelector('.accept').style.visibility = 'visible'; } }; @@ -170,6 +180,8 @@ function game(player1, player2, board) { jaipur.selectedCointType = this.dataset.group; } + + if (jaipur.selectedCointType == this.dataset.group) { //ustawienie active inactive na wszystkich grupach @@ -197,6 +209,10 @@ function game(player1, player2, board) { jaipur.removeBlankCoin(jaipur.selectedCointType); } else { + //jesli jest już wybranych 7 lub więcej monet to nie można więcej bo to max + if(document.querySelectorAll('.coin.selected.'+jaipur.selectedCointType).length >=7 ){ + return false; + } //ustawienie selected na elemencie z kliniętej grupy var coinsFromRow = document.querySelectorAll('.coin.' + this.dataset.group + ':not(.selected)'); [].slice.call(coinsFromRow).pop().classList.add('selected'); @@ -219,14 +235,15 @@ function game(player1, player2, board) { blankCoin.classList.add(groupName); blankCoin.classList.add('blank'); blankCoin.innerText = '0'; - blankCoin.dataset.group=groupName; + blankCoin.dataset.group = groupName; blankCoin.addEventListener('click', jaipur.coinClick); var firstElementInGroup = document.querySelector('.coin.' + groupName); document.querySelector('.group.' + groupName).insertBefore(blankCoin, firstElementInGroup); }; this.removeBlankCoin = function (groupName) { - document.querySelector('.coin.blank.' + groupName).remove(); + if (!!document.querySelector('.coin.blank.' + groupName)) + document.querySelector('.coin.blank.' + groupName).remove(); }; this.showScoreBoard = function () {