Add switching players after each move
This commit is contained in:
parent
4c874945d9
commit
188608bf84
@ -36,6 +36,8 @@ class Game {
|
|||||||
this.blackPlayer = new Player('black');
|
this.blackPlayer = new Player('black');
|
||||||
this.chosenFigure = new Figure(0,0);
|
this.chosenFigure = new Figure(0,0);
|
||||||
this.fields = [];
|
this.fields = [];
|
||||||
|
this.currentPlayer = 'white';
|
||||||
|
this.otherPlayer = (this.currentPlayer == 'white') ? 'black' : 'white';
|
||||||
}
|
}
|
||||||
drawGamePanel(x,y, widthAndHeight) {
|
drawGamePanel(x,y, widthAndHeight) {
|
||||||
var boxes = new Array();
|
var boxes = new Array();
|
||||||
@ -93,6 +95,10 @@ class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleClick(item) {
|
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')) {
|
if(item.classList.contains('shogun') || item.classList.contains('farmer')) {
|
||||||
this.chosenFigure.setX(item.getAttribute('data-x'));
|
this.chosenFigure.setX(item.getAttribute('data-x'));
|
||||||
this.chosenFigure.setY(item.getAttribute('data-y'));
|
this.chosenFigure.setY(item.getAttribute('data-y'));
|
||||||
@ -353,6 +359,13 @@ class Game {
|
|||||||
this.showPossibleMoves();
|
this.showPossibleMoves();
|
||||||
this.chosenFigure.reset();
|
this.chosenFigure.reset();
|
||||||
game.updateLists();
|
game.updateLists();
|
||||||
|
this.switchPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
|
switchPlayers() {
|
||||||
|
var currentPlayer = this.currentPlayer;
|
||||||
|
this.currentPlayer = this.otherPlayer;
|
||||||
|
this.otherPlayer = currentPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
removeIndicator() {
|
removeIndicator() {
|
||||||
@ -364,8 +377,6 @@ class Game {
|
|||||||
updateLists() {
|
updateLists() {
|
||||||
var whiteList = document.querySelector('.whitePlayer');
|
var whiteList = document.querySelector('.whitePlayer');
|
||||||
var blackList = document.querySelector('.blackPlayer');
|
var blackList = document.querySelector('.blackPlayer');
|
||||||
console.log(whiteList)
|
|
||||||
console.log(blackList)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user