Przerobienie nieco na grid css. Pozwolenie na dodawanie żetonów o wartości zero i zbieranie bonusów za nie jesli te istnieją.

This commit is contained in:
kplaczek
2017-08-13 22:48:29 +02:00
parent 1410407272
commit 9bbcc73b33
4 changed files with 92 additions and 32 deletions

View File

@@ -1,4 +1,3 @@
function coin(value, group) {
this.value = value;
this.group = group;
@@ -13,7 +12,7 @@ function player(name, id) {
this.id = id;
this.selector = '.player.player' + id;
this.hasCamelCoin = true;
this.hasCamelCoin = false;
this.calculateScore = function () {
var score = 0;
@@ -195,17 +194,41 @@ function game(player1, player2, board) {
}
jaipur.hideAcceptButton();
}
jaipur.removeBlankCoin(jaipur.selectedCointType);
} else {
//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');
jaipur.showAcceptButton();
//dodanie monety o wartości zero jeśli wybrano wszystkie monety z danej grupy
if (!!document.querySelectorAll('.coin.' + this.selectedCointType + ':not(.selected)').length == 0) {
jaipur.addBlankCoin(this.selectedCointType);
}
}
}
};
this.addBlankCoin = function (groupName) {
var blankCoin = document.createElement('span');
blankCoin.classList.add('coin');
blankCoin.classList.add(groupName);
blankCoin.classList.add('blank');
blankCoin.innerText = '0';
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();
};
this.showScoreBoard = function () {
document.querySelector('.scoreTable').classList.add('visible');
@@ -232,7 +255,6 @@ function game(player1, player2, board) {
var group = coins[i].dataset.group;
jaipur.board.goods[group].pop();
// jaipur.activePlayer.coins.push({ value: parseInt(coins[i].innerText), type: 'goods', group: group});
jaipur.activePlayer.coins.push(parseInt(coins[i].innerText));
coins[i].remove();
}
@@ -249,11 +271,9 @@ function game(player1, player2, board) {
}
if (!!bonus) {
// { value: parseInt(coins[i].innerText), type: 'goods', group: group}
// jaipur.activePlayer.bonus.push({ value: parseInt(coins[i].innerText), type: 'goods', group: group});
jaipur.activePlayer.bonus.push(bonus);
}
//
var groups = document.querySelectorAll('.group');
jaipur.selectedCointType = false;