Compare commits

..

1 Commits

Author SHA1 Message Date
Maik Hagenbruch
188608bf84 Add switching players after each move 2020-04-01 11:12:19 +02:00

View File

@ -36,6 +36,8 @@ class Game {
this.blackPlayer = new Player('black');
this.chosenFigure = new Figure(0,0);
this.fields = [];
this.currentPlayer = 'white';
this.otherPlayer = (this.currentPlayer == 'white') ? 'black' : 'white';
}
drawGamePanel(x,y, widthAndHeight) {
var boxes = new Array();
@ -93,6 +95,10 @@ class Game {
}
handleClick(item) {
if(!item.classList.contains(this.currentPlayer) && !item.classList.contains('possibleMove')) {
alert(this.otherPlayer + ' ist nicht dran');
return;
}
if(item.classList.contains('shogun') || item.classList.contains('farmer')) {
this.chosenFigure.setX(item.getAttribute('data-x'));
this.chosenFigure.setY(item.getAttribute('data-y'));
@ -353,6 +359,13 @@ class Game {
this.showPossibleMoves();
this.chosenFigure.reset();
game.updateLists();
this.switchPlayers();
}
switchPlayers() {
var currentPlayer = this.currentPlayer;
this.currentPlayer = this.otherPlayer;
this.otherPlayer = currentPlayer;
}
removeIndicator() {
@ -364,8 +377,6 @@ class Game {
updateLists() {
var whiteList = document.querySelector('.whitePlayer');
var blackList = document.querySelector('.blackPlayer');
console.log(whiteList)
console.log(blackList)
}
}