Compare commits
No commits in common. "48767c8ad828416734b78b852fb3685c51923cd6" and "558297e42d4d7cee456f672a07e02b603d1e8447" have entirely different histories.
48767c8ad8
...
558297e42d
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
.ddev
|
|
@ -30,11 +30,11 @@
|
|||||||
background-color: rgba(255,255,255,0.7);
|
background-color: rgba(255,255,255,0.7);
|
||||||
text-align:center;
|
text-align:center;
|
||||||
}
|
}
|
||||||
.field.black.farmer {
|
.field.black {
|
||||||
background-image: url(../img/bauer_black.png);
|
background-image: url(../img/bauer_black.png);
|
||||||
}
|
}
|
||||||
|
|
||||||
.field.white.farmer {
|
.field.white {
|
||||||
background-image: url(../img/bauer_weiss.png);
|
background-image: url(../img/bauer_weiss.png);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +56,3 @@
|
|||||||
#gamePanel .field.possibleMove {
|
#gamePanel .field.possibleMove {
|
||||||
background-color: rgba(100,150,20, 0.8);
|
background-color: rgba(100,150,20, 0.8);
|
||||||
}
|
}
|
||||||
#gamePanel .field.field.possibleMove:hover {
|
|
||||||
background-color: rgba(100, 170,20, 0.8);
|
|
||||||
}
|
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
11
js/game.js
@ -95,7 +95,6 @@ class Game {
|
|||||||
item.addEventListener("click", this.pickUpFigure);
|
item.addEventListener("click", this.pickUpFigure);
|
||||||
}
|
}
|
||||||
if(item.classList.contains('black')) {
|
if(item.classList.contains('black')) {
|
||||||
console.log('TEST');
|
|
||||||
var possibleMoves = blackPlayer.figures[item.getAttribute('data-figure')][(parseInt(item.getAttribute('id').replace('field-',''))-1)];
|
var possibleMoves = blackPlayer.figures[item.getAttribute('data-figure')][(parseInt(item.getAttribute('id').replace('field-',''))-1)];
|
||||||
item.setAttribute('data-moves', possibleMoves)
|
item.setAttribute('data-moves', possibleMoves)
|
||||||
var bobble = document.createElement('div');
|
var bobble = document.createElement('div');
|
||||||
@ -103,11 +102,12 @@ class Game {
|
|||||||
bobble.setAttribute('class', 'bobble');
|
bobble.setAttribute('class', 'bobble');
|
||||||
bobble.appendChild(bobbleText);
|
bobble.appendChild(bobbleText);
|
||||||
item.append(bobble);
|
item.append(bobble);
|
||||||
item.addEventListener("click", this.pickupFigure);
|
item.addEventListener("click", this.pickUpFigure);
|
||||||
}
|
}
|
||||||
}, this)
|
}, this)
|
||||||
}
|
}
|
||||||
pickUpFigure() {
|
pickUpFigure() {
|
||||||
|
console.log(this.classList)
|
||||||
if(!this.classList.contains('farmer') && !(this.classList.contains('shogun'))) {
|
if(!this.classList.contains('farmer') && !(this.classList.contains('shogun'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ class Game {
|
|||||||
possibleTargets[5] = new Array(x-1, y-2);
|
possibleTargets[5] = new Array(x-1, y-2);
|
||||||
possibleTargets[6] = new Array(x+1, y-2);
|
possibleTargets[6] = new Array(x+1, y-2);
|
||||||
possibleTargets[7] = new Array(x+1, y+2);
|
possibleTargets[7] = new Array(x+1, y+2);
|
||||||
possibleTargets[8] = new Array(x-1, y+2);
|
possibleTargets[8] = new Array(x-2, y+2);
|
||||||
possibleTargets[9] = new Array(x-2, y+1);
|
possibleTargets[9] = new Array(x-2, y+1);
|
||||||
possibleTargets[10] = new Array(x-2, y-1);
|
possibleTargets[10] = new Array(x-2, y-1);
|
||||||
possibleTargets[11] = new Array(x+2, y-1);
|
possibleTargets[11] = new Array(x+2, y-1);
|
||||||
@ -179,7 +179,6 @@ class Game {
|
|||||||
var allFields = document.querySelectorAll('.field');
|
var allFields = document.querySelectorAll('.field');
|
||||||
allFields.forEach(function(item, index) {
|
allFields.forEach(function(item, index) {
|
||||||
item.classList.remove('possibleMove');
|
item.classList.remove('possibleMove');
|
||||||
item.classList.remove('active');
|
|
||||||
})
|
})
|
||||||
for (var target in possibleTargets) {
|
for (var target in possibleTargets) {
|
||||||
var greenField = document.querySelector('[data-x="'+possibleTargets[target][0]+'"][data-y="'+possibleTargets[target][1]+'"]')
|
var greenField = document.querySelector('[data-x="'+possibleTargets[target][0]+'"][data-y="'+possibleTargets[target][1]+'"]')
|
||||||
@ -188,10 +187,6 @@ class Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseFigure() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Player {
|
class Player {
|
||||||
|
737
web/js/game.js
@ -1,737 +0,0 @@
|
|||||||
class Figure {
|
|
||||||
constructor(x,y) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
setX(x) {
|
|
||||||
this.x = x;
|
|
||||||
}
|
|
||||||
setY(y) {
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
getX() {
|
|
||||||
return parseInt(this.x);
|
|
||||||
}
|
|
||||||
getY() {
|
|
||||||
return parseInt(this.y);
|
|
||||||
}
|
|
||||||
getPosition() {
|
|
||||||
return new Array(parseInt(this.x), parseInt(this.y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class Game {
|
|
||||||
constructor() {
|
|
||||||
this.whitePlayer = new Player('white');
|
|
||||||
this.blackPlayer = new Player('black');
|
|
||||||
this.chosenFigure = new Figure(0,0);
|
|
||||||
}
|
|
||||||
drawGamePanel(x,y, widthAndHeight) {
|
|
||||||
var boxes = new Array();
|
|
||||||
for(var i=0; i<y; i++) {
|
|
||||||
for(var j=0; j<x; j++) {
|
|
||||||
boxes.push(new Array(i+1,j+1))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var rows = new Array();
|
|
||||||
var row = new Array();
|
|
||||||
boxes.forEach(function(item, index) {
|
|
||||||
var domElement = document.createElement('div');
|
|
||||||
domElement.setAttribute('data-x', item[1]);
|
|
||||||
domElement.setAttribute('data-y', item[0]);
|
|
||||||
domElement.setAttribute('id', 'field-'+(index+1))
|
|
||||||
var backgroudColor = '';
|
|
||||||
domElement.setAttribute(
|
|
||||||
'style',
|
|
||||||
'width:'+widthAndHeight+'px; height:'+widthAndHeight+'px;'
|
|
||||||
)
|
|
||||||
if(row.length<8) {
|
|
||||||
row.push(domElement);
|
|
||||||
}
|
|
||||||
if(row.length == 8 ) {
|
|
||||||
rows.push(row)
|
|
||||||
row = new Array();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
var that = this;
|
|
||||||
rows.forEach(function(item, indexRow) {
|
|
||||||
var wrap = document.createElement('div');
|
|
||||||
wrap.setAttribute('id', 'row-'+(indexRow+1));
|
|
||||||
document.getElementById('gamePanel').append(wrap)
|
|
||||||
item.forEach(function(field, indexField) {
|
|
||||||
if(((indexRow+1)+(indexField+1))%2 == 0) {
|
|
||||||
field.setAttribute('class', 'even field')
|
|
||||||
} else {
|
|
||||||
field.setAttribute('class', 'odd field')
|
|
||||||
}
|
|
||||||
wrap.append(field);
|
|
||||||
field.addEventListener(
|
|
||||||
"click",
|
|
||||||
function() {
|
|
||||||
that.handleClick(this)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
passive: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
handleClick(item) {
|
|
||||||
if(item.classList.contains('shogun') || item.classList.contains('farmer')) {
|
|
||||||
this.chosenFigure.setX(item.getAttribute('data-x'));
|
|
||||||
this.chosenFigure.setY(item.getAttribute('data-y'));
|
|
||||||
this.pickUpFigure(item);
|
|
||||||
}
|
|
||||||
else if(item.classList.contains('possibleMove')) {
|
|
||||||
this.releaseFigure(item, this.chosenFigure)
|
|
||||||
} else {
|
|
||||||
this.removeIndicator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setPlayingFigures() {
|
|
||||||
var whiteStartRow = document.getElementById('row-1');
|
|
||||||
var whiteFields = document.querySelectorAll('#row-1 .field')
|
|
||||||
var blackStartRow = document.getElementById('row-8');
|
|
||||||
var blackFields = document.querySelectorAll('#row-8 .field')
|
|
||||||
whiteFields.forEach(function(item, index) {
|
|
||||||
if(index==3) {
|
|
||||||
item.classList.add('white');
|
|
||||||
item.classList.add('shogun');
|
|
||||||
item.setAttribute('data-figure', 'sh');
|
|
||||||
} else {
|
|
||||||
item.classList.add('white');
|
|
||||||
item.classList.add('farmer');
|
|
||||||
item.setAttribute('data-figure', index<3 ? 'b'+(index+1) : 'b'+index );
|
|
||||||
}
|
|
||||||
})
|
|
||||||
blackFields.forEach(function(item, index) {
|
|
||||||
if(index==4) {
|
|
||||||
item.classList.add('black');
|
|
||||||
item.classList.add('shogun');
|
|
||||||
item.setAttribute('data-figure', 'sh');
|
|
||||||
} else {
|
|
||||||
item.classList.add('black');
|
|
||||||
item.classList.add('farmer');
|
|
||||||
item.setAttribute('data-figure', index<4 ? 'b'+(index+1) : 'b'+index );
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
calculateMovesForPlayers() {
|
|
||||||
this.whitePlayer.calculateMoves();
|
|
||||||
this.blackPlayer.calculateMoves();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
showPossibleMoves() {
|
|
||||||
console.log('show possible moves')
|
|
||||||
var whitePlayer = this.whitePlayer;
|
|
||||||
var blackPlayer = this.blackPlayer;
|
|
||||||
var busyFields = document.querySelectorAll('.farmer, .shogun');
|
|
||||||
busyFields.forEach(item => this.addBobbles(item));
|
|
||||||
}
|
|
||||||
addBobbles(item) {
|
|
||||||
var that = this;
|
|
||||||
if(item.classList.contains('white')) {
|
|
||||||
var possibleMoves = this.whitePlayer.figures[item.getAttribute('data-figure')][(parseInt(item.getAttribute('id').replace('field-',''))-1)];
|
|
||||||
item.setAttribute('data-moves', possibleMoves)
|
|
||||||
if(!item.childNodes[0]) {
|
|
||||||
var bobble = document.createElement('div');
|
|
||||||
var bobbleText = document.createTextNode(possibleMoves)
|
|
||||||
bobble.setAttribute('class', 'bobble');
|
|
||||||
bobble.appendChild(bobbleText);
|
|
||||||
item.append(bobble);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if(item.classList.contains('black')) {
|
|
||||||
var possibleMoves = this.blackPlayer.figures[item.getAttribute('data-figure')][(parseInt(item.getAttribute('id').replace('field-',''))-1)];
|
|
||||||
item.setAttribute('data-moves', possibleMoves)
|
|
||||||
if(!item.childNodes[0]) {
|
|
||||||
var bobble = document.createElement('div');
|
|
||||||
var bobbleText = document.createTextNode(possibleMoves);
|
|
||||||
bobble.setAttribute('class', 'bobble');
|
|
||||||
bobble.appendChild(bobbleText);
|
|
||||||
item.append(bobble);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pickUpFigure(item) {
|
|
||||||
if(!item.classList.contains('farmer') && !(item.classList.contains('shogun'))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var possibleMoves = parseInt(item.getAttribute('data-moves'));
|
|
||||||
var possibleTargets = new Object();
|
|
||||||
var x = parseInt(item.getAttribute('data-x'));
|
|
||||||
var y = parseInt(item.getAttribute('data-y'));
|
|
||||||
|
|
||||||
switch(possibleMoves) {
|
|
||||||
case 1:
|
|
||||||
possibleTargets[1] = new Array(x+possibleMoves, y);
|
|
||||||
possibleTargets[2] = new Array(x, y+possibleMoves);
|
|
||||||
possibleTargets[3] = new Array(x-possibleMoves, y);
|
|
||||||
possibleTargets[4] = new Array(x, y-1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
possibleTargets[1] = new Array(x+possibleMoves, y);
|
|
||||||
possibleTargets[2] = new Array(x, y+possibleMoves);
|
|
||||||
possibleTargets[3] = new Array(x-possibleMoves, y);
|
|
||||||
possibleTargets[4] = new Array(x, y-possibleMoves);
|
|
||||||
|
|
||||||
possibleTargets[5] = new Array(x+1, y+1);
|
|
||||||
possibleTargets[6] = new Array(x-1,y-1);
|
|
||||||
possibleTargets[7] = new Array(x+1,y-1);
|
|
||||||
possibleTargets[8] = new Array(x-1, y+1);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
possibleTargets[1] = new Array(x+possibleMoves, y);
|
|
||||||
possibleTargets[2] = new Array(x, y+possibleMoves);
|
|
||||||
possibleTargets[3] = new Array(x-possibleMoves, y);
|
|
||||||
possibleTargets[4] = new Array(x, y-possibleMoves);
|
|
||||||
|
|
||||||
possibleTargets[5] = new Array(x-1, y-2);
|
|
||||||
possibleTargets[6] = new Array(x+1, y-2);
|
|
||||||
possibleTargets[7] = new Array(x+1, y+2);
|
|
||||||
possibleTargets[8] = new Array(x-1, y+2);
|
|
||||||
possibleTargets[9] = new Array(x-2, y+1);
|
|
||||||
possibleTargets[10] = new Array(x-2, y-1);
|
|
||||||
possibleTargets[11] = new Array(x+2, y-1);
|
|
||||||
possibleTargets[12] = new Array(x+2, y+1);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
possibleTargets[1] = new Array(x-possibleMoves, y);
|
|
||||||
possibleTargets[2] = new Array(x+possibleMoves, y);
|
|
||||||
possibleTargets[3] = new Array(x, y+possibleMoves);
|
|
||||||
possibleTargets[4] = new Array(x, y-possibleMoves);
|
|
||||||
|
|
||||||
possibleTargets[5] = new Array(x+1, y-3);
|
|
||||||
possibleTargets[6] = new Array(x-1, y-3);
|
|
||||||
possibleTargets[7] = new Array(x+3, y+1);
|
|
||||||
possibleTargets[8] = new Array(x+3, y-1);
|
|
||||||
possibleTargets[9] = new Array(x+1, y+3);
|
|
||||||
possibleTargets[10] = new Array(x-1, y+3);
|
|
||||||
possibleTargets[11] = new Array(x-3, y-1);
|
|
||||||
possibleTargets[12] = new Array(x-3, y+1);
|
|
||||||
|
|
||||||
possibleTargets[13] = new Array(x+2, y-2);
|
|
||||||
possibleTargets[14] = new Array(x+2, y+2);
|
|
||||||
possibleTargets[15] = new Array(x-2, y+2);
|
|
||||||
possibleTargets[16] = new Array(x-2, y-2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for(var target in possibleTargets) {
|
|
||||||
if(possibleTargets[target][0] > 0 && possibleTargets[target][0] < 9 && possibleTargets[target][1] > 0 && possibleTargets[target][1] < 9) {
|
|
||||||
possibleTargets[target]["fieldsBetween"] = new Array();
|
|
||||||
var fieldsBetween = this.calcFieldsBetween(possibleTargets[target], possibleMoves);
|
|
||||||
var field = document.querySelector('[data-x="'+possibleTargets[target][0]+'"][data-y="'+possibleTargets[target][1]+'"]');
|
|
||||||
if(field.classList.contains('farmer') || field.classList.contains('shogun')) {
|
|
||||||
delete possibleTargets[target];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete possibleTargets[target];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var allFields = document.querySelectorAll('.field');
|
|
||||||
allFields.forEach(function(item, index) {
|
|
||||||
item.classList.remove('possibleMove');
|
|
||||||
item.classList.remove('active');
|
|
||||||
})
|
|
||||||
var that = this;
|
|
||||||
for (var target in possibleTargets) {
|
|
||||||
var way1 = true;
|
|
||||||
var way2 = true;
|
|
||||||
var that = this;
|
|
||||||
if(possibleTargets[target]["fieldsBetween"].hasOwnProperty("way1")) {
|
|
||||||
possibleTargets[target]["fieldsBetween"]["way1"].forEach(function(item) {
|
|
||||||
var field = document.querySelector('[data-x="'+item[0]+'"][data-y="'+item[1]+'"]');
|
|
||||||
if(!that.isFree(field)) {
|
|
||||||
way1 = false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(possibleTargets[target]["fieldsBetween"].hasOwnProperty("way2")) {
|
|
||||||
possibleTargets[target]["fieldsBetween"]["way2"].forEach(function(item) {
|
|
||||||
var field = document.querySelector('[data-x="'+item[0]+'"][data-y="'+item[1]+'"]');
|
|
||||||
if(!that.isFree(field)) {
|
|
||||||
way2 = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
way2 = false;
|
|
||||||
}
|
|
||||||
console.log(way1);
|
|
||||||
console.log(way2);
|
|
||||||
if(!way2 && !way1) {
|
|
||||||
delete possibleTargets[target];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(var target in possibleTargets) {
|
|
||||||
var x = possibleTargets[target][0];
|
|
||||||
var y = possibleTargets[target][1];
|
|
||||||
document.querySelector('[data-x="'+x+'"][data-y="'+y+'"]').classList.add('possibleMove')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isFree(field) {
|
|
||||||
if(field.classList.contains('farmer') || field.classList.contains('shogun')) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
calcFieldsBetween(target, moves) {
|
|
||||||
var sourceX = this.chosenFigure.getX();
|
|
||||||
var sourceY = this.chosenFigure.getY();
|
|
||||||
//console.log('SOURCE: '+sourceX+', '+sourceY+' TARGET: '+target[0], ', '+target[1]);
|
|
||||||
switch(moves) {
|
|
||||||
case 2:
|
|
||||||
//T
|
|
||||||
if( (target[0] == sourceX) && (target[1] == (sourceY-moves) ) ) {
|
|
||||||
//console.log("T")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
}
|
|
||||||
//TR
|
|
||||||
else if((target[0] == (sourceX+1)) && (target[1] == (sourceY-1))) {
|
|
||||||
//console.log("TR")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY));
|
|
||||||
}
|
|
||||||
//R
|
|
||||||
else if((target[0] == (sourceX+moves)) && (target[1] == sourceY)) {
|
|
||||||
//console.log("R")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
}
|
|
||||||
//BR
|
|
||||||
else if((target[0] == (sourceX+1)) && (target[1] == (sourceY+1))) {
|
|
||||||
//console.log("BR")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+1));
|
|
||||||
}
|
|
||||||
//B
|
|
||||||
else if((target[0] == sourceX) && (target[1] == (sourceY+moves)) ) {
|
|
||||||
//console.log("B")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+1));
|
|
||||||
}
|
|
||||||
//BL
|
|
||||||
else if( (target[0] == (sourceX-1) ) && (target[1] == (sourceY+1) ) ) {
|
|
||||||
//console.log("BL")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY));
|
|
||||||
}
|
|
||||||
//L
|
|
||||||
else if( (target[0] == (sourceX-moves) && (target[1] == sourceY) ) ) {
|
|
||||||
//console.log("L")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
}
|
|
||||||
//TL
|
|
||||||
else if( (target[0] == (sourceX-1) && (target[1] == (sourceY-1) ) ) ) {
|
|
||||||
//console.log("TL")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY-1));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log('2 moves - condition not found');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
//T
|
|
||||||
if( (target[0] == sourceX) && (target[1] == (sourceY-moves) ) ) {
|
|
||||||
//console.log("T")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-2));
|
|
||||||
}
|
|
||||||
//TR - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX+1)) && (target[1] == (sourceY-2) ) ) {
|
|
||||||
//console.log("TR");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-2));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY-1));
|
|
||||||
}
|
|
||||||
// RL - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX+2)) && (target[1] == (sourceY-1) ) ) {
|
|
||||||
//console.log("RL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+2, sourceY));
|
|
||||||
}
|
|
||||||
// R
|
|
||||||
else if( (target[0] == (sourceX+moves) ) && (target[1] == sourceY) ) {
|
|
||||||
//console.log("R");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+2, sourceY));
|
|
||||||
}
|
|
||||||
// RR - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX+2) ) && (target[1] == (sourceY+1) ) ) {
|
|
||||||
//console.log("RR")
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+2, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY+1));
|
|
||||||
}
|
|
||||||
//BR - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX+1) ) && (target[1] == (sourceY +2) ) ) {
|
|
||||||
//console.log("BR");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+2));
|
|
||||||
}
|
|
||||||
// B
|
|
||||||
else if( (target[0] == sourceX ) && (target[1] == (sourceY+moves) ) ) {
|
|
||||||
//console.log("B");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+2));
|
|
||||||
}
|
|
||||||
// BL - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX-1) ) && ( target[1] == (sourceY+2) ) ) {
|
|
||||||
//console.log("BL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+2));
|
|
||||||
}
|
|
||||||
// LL - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX-2) ) && (target[1] == (sourceY+1) ) ) {
|
|
||||||
//console.log("LL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-2, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY+1));
|
|
||||||
}
|
|
||||||
// L
|
|
||||||
else if( (target[0] == (sourceX - moves) ) && (target[1] == sourceY) ) {
|
|
||||||
//console.log("L");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-2, sourceY));
|
|
||||||
}
|
|
||||||
// LR - 2 Wege möglich
|
|
||||||
else if( (target[0] == ( sourceX-2) ) && (target[1] == (sourceY-1) ) ) {
|
|
||||||
//console.log("LR");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-2, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY-1));
|
|
||||||
}
|
|
||||||
// TL - 2 Wege möglich
|
|
||||||
else if ( (target[0] == (sourceX-1) ) && (target[1] == (sourceY-2) ) ) {
|
|
||||||
//console.log("TL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY-2));
|
|
||||||
} else {
|
|
||||||
//console.log(" 3 moves - condition not met");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
// T
|
|
||||||
if( (target[0] == sourceX) && (target[1] == (sourceY-moves) ) ) {
|
|
||||||
//console.log("T");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-3));
|
|
||||||
}
|
|
||||||
// TR - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX+1) ) && (target[1] == (sourceY-3) ) ) {
|
|
||||||
//console.log("TR");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-3));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY-2));
|
|
||||||
}
|
|
||||||
// TL - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX-1) ) && (target[1] == (sourceY-3) ) ) {
|
|
||||||
//console.log("TL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-3));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY-2));
|
|
||||||
}
|
|
||||||
// L
|
|
||||||
else if( (target[0] == (sourceX-moves) ) && (target[1] == sourceY) ) {
|
|
||||||
//console.log("L");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-2, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-3, sourceY));
|
|
||||||
}
|
|
||||||
// LR - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX-3) ) && (target[1] == (sourceY-1) ) ) {
|
|
||||||
//console.log("LR");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-2, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-3, sourceY));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-2, sourceY-1));
|
|
||||||
}
|
|
||||||
// LL - 2 Wege möglich
|
|
||||||
else if( (target[0] == (sourceX-3) ) && (target[1] == (sourceY+1) ) ) {
|
|
||||||
//console.log("LL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-2, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-3, sourceY));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-2, sourceY+1));
|
|
||||||
}
|
|
||||||
// B
|
|
||||||
else if( (target[0] == sourceX ) && (target[1] == (sourceY+moves) ) ) {
|
|
||||||
//console.log("B");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+3));
|
|
||||||
}
|
|
||||||
// BL - 2 Wege möglich
|
|
||||||
else if ( (target[0] == (sourceX-1) ) && (target[1] == (sourceY+3) ) ) {
|
|
||||||
//console.log("BL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+3));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY+2));
|
|
||||||
}
|
|
||||||
// BR - 2 Wege möglich
|
|
||||||
else if ( (target[0] == (sourceX+1) ) && (target[1] == (sourceY+3) ) ) {
|
|
||||||
//console.log("BR");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+3));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY+2));
|
|
||||||
}
|
|
||||||
// R
|
|
||||||
else if ( (target[0] == (sourceX+moves) ) && (target[1] == sourceY) ) {
|
|
||||||
//console.log("R");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+2, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+3, sourceY));
|
|
||||||
}
|
|
||||||
//RR - 2 Wege möglich
|
|
||||||
else if ( (target[0] == (sourceX+3) ) && (target[1] == (sourceY+1) ) ) {
|
|
||||||
//console.log("RR");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+2, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+3, sourceY));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+2, sourceY+2));
|
|
||||||
}
|
|
||||||
//RL
|
|
||||||
else if( (target[0] == (sourceX+3) ) && (target[1] == (sourceY-1) ) ) {
|
|
||||||
//console.log("RL");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+2, sourceY));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+3, sourceY));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+2, sourceY-1));
|
|
||||||
}
|
|
||||||
//TRC
|
|
||||||
else if( (target[0] == (sourceX+2) ) && (target[1] == (sourceY-2) ) ) {
|
|
||||||
//console.log("TRC");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY-2));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+2, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+2, sourceY-1));
|
|
||||||
}
|
|
||||||
//TLC
|
|
||||||
else if( (target[0] == (sourceX-2) ) && (target[1] == (sourceY-2) ) ) {
|
|
||||||
//console.log("TLC");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY-2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY-2));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-2, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-2, sourceY-1));
|
|
||||||
}
|
|
||||||
// BRC
|
|
||||||
else if( (target[0] == (sourceX+2) ) && (target[1] == (sourceY+2) ) ) {
|
|
||||||
//console.log("BRC");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX+1, sourceY+2));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+2, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX+2, sourceY+1));
|
|
||||||
}
|
|
||||||
// BLC
|
|
||||||
else if( (target[0] == (sourceX-2) ) && (target[1] == (sourceY+2) ) ) {
|
|
||||||
//console.log("BLC");
|
|
||||||
target["fieldsBetween"]["way1"] = new Array();
|
|
||||||
target["fieldsBetween"]["way2"] = new Array();
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+1));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX, sourceY+2));
|
|
||||||
target["fieldsBetween"]["way1"].push(new Array(sourceX-1, sourceY+2));
|
|
||||||
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-1, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-2, sourceY));
|
|
||||||
target["fieldsBetween"]["way2"].push(new Array(sourceX-2, sourceY+1));
|
|
||||||
} else {
|
|
||||||
//console.log("4 moves - condition not met");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//console.log('not implemented yet')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
releaseFigure(targetField, fromField) {
|
|
||||||
var source = document.querySelector('[data-x="'+fromField.getX()+'"][data-y="'+fromField.getY()+'"]');
|
|
||||||
// klassen die übergeben werden müssen, bzw. vom alten feld runter müssen
|
|
||||||
// farbe, figur
|
|
||||||
var colorClass = source.classList.contains('white') ? 'white' : 'black';
|
|
||||||
var figureClass = source.classList.contains('farmer') ? 'farmer' : 'shogun';
|
|
||||||
var figureData = source.getAttribute('data-figure');
|
|
||||||
source.removeChild(source.childNodes[0]);
|
|
||||||
source.classList.remove('shogun','farmer', 'black', 'white');
|
|
||||||
source.setAttribute('data-figure', '');
|
|
||||||
source.setAttribute('data-moves', '');
|
|
||||||
targetField.classList.add(figureClass, colorClass);
|
|
||||||
targetField.setAttribute('data-figure', figureData);
|
|
||||||
this.removeIndicator();
|
|
||||||
this.showPossibleMoves();
|
|
||||||
this.chosenFigure.setX(0);
|
|
||||||
this.chosenFigure.setY(0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
removeIndicator() {
|
|
||||||
var greenFields = document.querySelectorAll('.possibleMove');
|
|
||||||
greenFields.forEach(item => {
|
|
||||||
item.classList.remove('possibleMove')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Player {
|
|
||||||
constructor(color) {
|
|
||||||
this.figures = {
|
|
||||||
positions: new Array(),
|
|
||||||
b1: new Array(),
|
|
||||||
b2: new Array(),
|
|
||||||
b3: new Array(),
|
|
||||||
b4: new Array(),
|
|
||||||
b5: new Array(),
|
|
||||||
b6: new Array(),
|
|
||||||
b7: new Array(),
|
|
||||||
sh: new Array(),
|
|
||||||
}
|
|
||||||
if(color == 'white') {
|
|
||||||
this.figures.positions["b1"] = new Array(1,1);
|
|
||||||
this.figures.positions["b2"] = new Array(2,1);
|
|
||||||
this.figures.positions["b3"] = new Array(3,1);
|
|
||||||
this.figures.positions["b4"] = new Array(5,1);
|
|
||||||
this.figures.positions["b5"] = new Array(6,1);
|
|
||||||
this.figures.positions["b6"] = new Array(7,1);
|
|
||||||
this.figures.positions["b7"] = new Array(8,1);
|
|
||||||
this.figures.positions["sh"] = new Array(4,1);
|
|
||||||
}
|
|
||||||
if(color == 'black') {
|
|
||||||
this.figures.positions["b1"] = new Array(1,8);
|
|
||||||
this.figures.positions["b2"] = new Array(2,8);
|
|
||||||
this.figures.positions["b3"] = new Array(3,8);
|
|
||||||
this.figures.positions["b4"] = new Array(4,8);
|
|
||||||
this.figures.positions["b5"] = new Array(6,8);
|
|
||||||
this.figures.positions["b6"] = new Array(7,8);
|
|
||||||
this.figures.positions["b7"] = new Array(8,8);
|
|
||||||
this.figures.positions["sh"] = new Array(5,8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
calculateMoves() {
|
|
||||||
for(var figure in this.figures) {
|
|
||||||
if(figure != 'positions') {
|
|
||||||
if(figure != 'sh') {
|
|
||||||
for(var i=1; i<65; i++) {
|
|
||||||
this.figures[figure].push(Math.floor(Math.random() * (5 - 1)) + 1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(var i=1; i<65; i++) {
|
|
||||||
this.figures[figure].push(Math.floor(Math.random() * (3 - 1)) + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|