nie można wybrać więcej niż 7 monet na raz

This commit is contained in:
kplaczek
2017-08-14 20:21:31 +02:00
parent 9bbcc73b33
commit 6c4fea36c2
2 changed files with 23 additions and 5 deletions

View File

@@ -10,9 +10,10 @@ Do zrobienia:
- [x] wyświetlenie żetonu wielbłąda - [x] wyświetlenie żetonu wielbłąda
- [x] przydzielenie żetonu wielbłąda przed wyświetleniem wyniku - [x] przydzielenie żetonu wielbłąda przed wyświetleniem wyniku
- [ ] rozwiązywanie sprawy z remisem - [ ] 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] pobieranie żetonów po kliknięciu na żetonu
- [x] losowanie wartości bonusowych żetonów kart - [x] losowanie wartości bonusowych żetonów kart
- [x] zliczanie punków - [x] zliczanie punków
- [x] informowanie o zakończeniu rundy - [x] informowanie o zakończeniu rundy
- [x] przydzielanie żetonu Maharadży - [x] przydzielanie żetonu Maharadży
- [x] nie można wybrać więcej niż 7 monet na raz

View File

@@ -131,7 +131,17 @@ function game(player1, player2, board) {
}; };
this.showAcceptButton = function () { 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'; document.querySelector('.accept').style.visibility = 'visible';
} }
}; };
@@ -170,6 +180,8 @@ function game(player1, player2, board) {
jaipur.selectedCointType = this.dataset.group; jaipur.selectedCointType = this.dataset.group;
} }
if (jaipur.selectedCointType == this.dataset.group) { if (jaipur.selectedCointType == this.dataset.group) {
//ustawienie active inactive na wszystkich grupach //ustawienie active inactive na wszystkich grupach
@@ -197,6 +209,10 @@ function game(player1, player2, board) {
jaipur.removeBlankCoin(jaipur.selectedCointType); jaipur.removeBlankCoin(jaipur.selectedCointType);
} else { } 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 //ustawienie selected na elemencie z kliniętej grupy
var coinsFromRow = document.querySelectorAll('.coin.' + this.dataset.group + ':not(.selected)'); var coinsFromRow = document.querySelectorAll('.coin.' + this.dataset.group + ':not(.selected)');
[].slice.call(coinsFromRow).pop().classList.add('selected'); [].slice.call(coinsFromRow).pop().classList.add('selected');
@@ -219,13 +235,14 @@ function game(player1, player2, board) {
blankCoin.classList.add(groupName); blankCoin.classList.add(groupName);
blankCoin.classList.add('blank'); blankCoin.classList.add('blank');
blankCoin.innerText = '0'; blankCoin.innerText = '0';
blankCoin.dataset.group=groupName; blankCoin.dataset.group = groupName;
blankCoin.addEventListener('click', jaipur.coinClick); blankCoin.addEventListener('click', jaipur.coinClick);
var firstElementInGroup = document.querySelector('.coin.' + groupName); var firstElementInGroup = document.querySelector('.coin.' + groupName);
document.querySelector('.group.' + groupName).insertBefore(blankCoin, firstElementInGroup); document.querySelector('.group.' + groupName).insertBefore(blankCoin, firstElementInGroup);
}; };
this.removeBlankCoin = function (groupName) { this.removeBlankCoin = function (groupName) {
if (!!document.querySelector('.coin.blank.' + groupName))
document.querySelector('.coin.blank.' + groupName).remove(); document.querySelector('.coin.blank.' + groupName).remove();
}; };