finished moving and claculating possible targets and ways
This commit is contained in:
parent
48767c8ad8
commit
4c874945d9
@ -8,7 +8,17 @@
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#gamePanel {}
|
||||
.game {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.game #gamePanel {
|
||||
flex: 0 50%;
|
||||
}
|
||||
.game .overview {
|
||||
flex: 0 50%;
|
||||
}
|
||||
|
||||
#gamePanel .field {
|
||||
display:inline-block;
|
||||
}
|
||||
@ -58,4 +68,10 @@
|
||||
}
|
||||
#gamePanel .field.field.possibleMove:hover {
|
||||
background-color: rgba(100, 170,20, 0.8);
|
||||
}
|
||||
#gamePanel .field.possibleMove.match {
|
||||
background-color: rgba(255, 37, 37, 0.6);
|
||||
}
|
||||
#gamePanel .field.possibleMove.match:hover {
|
||||
background-color: rgba(255, 0, 0, 0.6);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Shogun</title>
|
||||
<link rel="stylesheet" href="css/styles.css">
|
||||
<script type="text/javascript" src="js/game.js"></script>
|
||||
@ -7,14 +8,24 @@
|
||||
<body>
|
||||
<div id="site">
|
||||
<h2>S H O G U N</h2>
|
||||
<div id="gamePanel">
|
||||
<script type="text/javascript">
|
||||
var game = new Game();
|
||||
game.drawGamePanel(8,8,60);
|
||||
game.setPlayingFigures();
|
||||
game.calculateMovesForPlayers();
|
||||
game.showPossibleMoves();
|
||||
</script>
|
||||
<div class="game">
|
||||
<div id="gamePanel">
|
||||
<script type="text/javascript">
|
||||
var game = new Game();
|
||||
game.drawGamePanel(8,8,60);
|
||||
game.setPlayingFigures();
|
||||
game.calculateMovesForPlayers();
|
||||
game.showPossibleMoves();
|
||||
</script>
|
||||
</div>
|
||||
<div class="overview">
|
||||
<div class="whitePlayer">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<div class="blackPlayer">
|
||||
<ul></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
622
web/js/game.js
622
web/js/game.js
@ -18,22 +18,37 @@ class Figure {
|
||||
getPosition() {
|
||||
return new Array(parseInt(this.x), parseInt(this.y));
|
||||
}
|
||||
reset() {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Field {
|
||||
constructor(x,y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
class Game {
|
||||
constructor() {
|
||||
this.whitePlayer = new Player('white');
|
||||
this.blackPlayer = new Player('black');
|
||||
this.chosenFigure = new Figure(0,0);
|
||||
this.fields = [];
|
||||
}
|
||||
drawGamePanel(x,y, widthAndHeight) {
|
||||
var boxes = new Array();
|
||||
for(var i=0; i<y; i++) {
|
||||
this.fields[(i+1)] = [];
|
||||
for(var j=0; j<x; j++) {
|
||||
this.fields[(i+1)][(j+1)] = new Field((i+1),(j+1));
|
||||
boxes.push(new Array(i+1,j+1))
|
||||
}
|
||||
}
|
||||
var rows = new Array();
|
||||
var row = new Array();
|
||||
var that = this;
|
||||
boxes.forEach(function(item, index) {
|
||||
var domElement = document.createElement('div');
|
||||
domElement.setAttribute('data-x', item[1]);
|
||||
@ -52,7 +67,7 @@ class Game {
|
||||
row = new Array();
|
||||
}
|
||||
})
|
||||
var that = this;
|
||||
|
||||
rows.forEach(function(item, indexRow) {
|
||||
var wrap = document.createElement('div');
|
||||
wrap.setAttribute('id', 'row-'+(indexRow+1));
|
||||
@ -126,7 +141,7 @@ class Game {
|
||||
|
||||
|
||||
showPossibleMoves() {
|
||||
console.log('show possible moves')
|
||||
//console.log('show possible moves')
|
||||
var whitePlayer = this.whitePlayer;
|
||||
var blackPlayer = this.blackPlayer;
|
||||
var busyFields = document.querySelectorAll('.farmer, .shogun');
|
||||
@ -164,117 +179,157 @@ class Game {
|
||||
return;
|
||||
}
|
||||
var possibleMoves = parseInt(item.getAttribute('data-moves'));
|
||||
var possibleTargets = new Object();
|
||||
var possibleTargets = new Set();
|
||||
var x = parseInt(item.getAttribute('data-x'));
|
||||
var y = parseInt(item.getAttribute('data-y'));
|
||||
|
||||
const isInField = function(target) {
|
||||
const [x,y] = target;
|
||||
if(x < 1 || x > 8 || y < 1 || y > 8) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
possibleTargets.add([x+possibleMoves, y]);
|
||||
possibleTargets.add(new Array(x, y+possibleMoves));
|
||||
possibleTargets.add(new Array(x-possibleMoves, y));
|
||||
possibleTargets.add(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.add(new Array(x+possibleMoves, y));
|
||||
possibleTargets.add(new Array(x, y+possibleMoves));
|
||||
possibleTargets.add(new Array(x-possibleMoves, y));
|
||||
possibleTargets.add(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);
|
||||
possibleTargets.add(new Array(x+1, y+1));
|
||||
possibleTargets.add(new Array(x-1,y-1));
|
||||
possibleTargets.add(new Array(x+1,y-1));
|
||||
possibleTargets.add(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.add(new Array(x+possibleMoves, y));
|
||||
possibleTargets.add(new Array(x, y+possibleMoves));
|
||||
possibleTargets.add(new Array(x-possibleMoves, y));
|
||||
possibleTargets.add(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);
|
||||
possibleTargets.add(new Array(x-1, y-2));
|
||||
possibleTargets.add(new Array(x+1, y-2));
|
||||
possibleTargets.add(new Array(x+1, y+2));
|
||||
possibleTargets.add(new Array(x-1, y+2));
|
||||
possibleTargets.add(new Array(x-2, y+1));
|
||||
possibleTargets.add(new Array(x-2, y-1));
|
||||
possibleTargets.add(new Array(x+2, y-1));
|
||||
possibleTargets.add(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.add(new Array(x-possibleMoves, y));
|
||||
possibleTargets.add(new Array(x+possibleMoves, y));
|
||||
possibleTargets.add(new Array(x, y+possibleMoves));
|
||||
possibleTargets.add(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.add(new Array(x+1, y-3));
|
||||
possibleTargets.add(new Array(x-1, y-3));
|
||||
possibleTargets.add(new Array(x+3, y+1));
|
||||
possibleTargets.add(new Array(x+3, y-1));
|
||||
possibleTargets.add(new Array(x+1, y+3));
|
||||
possibleTargets.add(new Array(x-1, y+3));
|
||||
possibleTargets.add(new Array(x-3, y-1));
|
||||
possibleTargets.add(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);
|
||||
possibleTargets.add(new Array(x+2, y-2));
|
||||
possibleTargets.add(new Array(x+2, y+2));
|
||||
possibleTargets.add(new Array(x-2, y+2));
|
||||
possibleTargets.add(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];
|
||||
// remove out of bounds
|
||||
for(var possibleTarget of possibleTargets) {
|
||||
if(!isInField(possibleTarget)) {
|
||||
possibleTargets.delete(possibleTarget)
|
||||
}
|
||||
}
|
||||
var allFields = document.querySelectorAll('.field');
|
||||
allFields.forEach(function(item, index) {
|
||||
item.classList.remove('possibleMove');
|
||||
item.classList.remove('active');
|
||||
})
|
||||
|
||||
// get possible ways
|
||||
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
|
||||
for(var possibleTarget of possibleTargets) {
|
||||
possibleTarget["ways"] = this.getPossibleWays(possibleTarget);
|
||||
}
|
||||
for(var possibleTarget of possibleTargets) {
|
||||
for(var way of possibleTarget["ways"]) {
|
||||
for(var field of way) {
|
||||
var chosenField = document.querySelector('[data-x="'+that.chosenFigure.getX()+'"][data-y="'+that.chosenFigure.getY()+'"]');
|
||||
var currentField = document.querySelector('[data-x="'+field.x+'"][data-y="'+field.y+'"]');
|
||||
var oppositeColor = chosenField.classList.contains('white') ? 'black' : 'white';
|
||||
var sameColor = chosenField.classList.contains('white') ? 'white' : 'black';
|
||||
var targetField = document.querySelector('[data-x="'+possibleTarget[0]+'"][data-y="'+possibleTarget[1]+'"]');
|
||||
var targetX = parseInt(targetField.getAttribute('data-x'));
|
||||
var targetY = parseInt(targetField.getAttribute('data-y'));
|
||||
//Startfeld überspringen
|
||||
if( (( field.x === that.chosenFigure.getX() ) && (field.y === that.chosenFigure.getY() ))) {
|
||||
continue;
|
||||
}
|
||||
});
|
||||
}
|
||||
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;
|
||||
// Zielfeld prüfen
|
||||
if( (( field.x === targetX ) && (field.y === targetY ))) {
|
||||
if(currentField.classList.contains(sameColor)) {
|
||||
const ways = possibleTarget["ways"].filter(w => w !== way);
|
||||
possibleTarget["ways"] = ways;
|
||||
if(possibleTarget["ways"].length == 0) {
|
||||
possibleTargets.delete(possibleTarget);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(currentField.classList.contains('shogun') || currentField.classList.contains('farmer')) {
|
||||
const ways = possibleTarget["ways"].filter(w => w !== way);
|
||||
possibleTarget["ways"] = ways;
|
||||
if(possibleTarget["ways"].length == 0) {
|
||||
possibleTargets.delete(possibleTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} 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')
|
||||
for(var possibleTarget of possibleTargets) {
|
||||
document.querySelector('[data-x="'+possibleTarget[0]+'"][data-y="'+possibleTarget[1]+'"]').classList.add('possibleMove');
|
||||
}
|
||||
}
|
||||
getPossibleWays(to) {
|
||||
const x1 = this.chosenFigure.getX();
|
||||
const y1 = this.chosenFigure.getY();
|
||||
const [x2,y2] = to;
|
||||
|
||||
const directionX = x1 < x2 ? 1 : -1;
|
||||
const directionY = y1 < y2 ? 1 : -1;
|
||||
|
||||
const way1 = new Set();
|
||||
for (let x = x1; directionX == 1 ? x <= x2 : x >= x2; x = x + directionX) {
|
||||
way1.add(this.getField(x, y1));
|
||||
}
|
||||
for (let y = y1; directionY == 1 ? y <= y2 : y >= y2; y = y + directionY) {
|
||||
way1.add(this.getField(x2, y));
|
||||
}
|
||||
|
||||
const way2 = new Set();
|
||||
for (let y = y1; directionY == 1 ? y <= y2 : y >= y2; y = y + directionY) {
|
||||
way2.add(this.getField(x1, y));
|
||||
}
|
||||
for (let x = x1; directionX == 1 ? x <= x2 : x >= x2; x = x + directionX) {
|
||||
way2.add(this.getField(x, y2));
|
||||
}
|
||||
|
||||
const setsEqual = (a,b) => a.size === b.size && [...a].every(value => b.has(value));
|
||||
|
||||
if(setsEqual(way1, way2)) {
|
||||
return [way1];
|
||||
}
|
||||
|
||||
return [way1, way2];
|
||||
}
|
||||
|
||||
getField(x,y) {
|
||||
return this.fields[x][y];
|
||||
}
|
||||
isFree(field) {
|
||||
if(field.classList.contains('farmer') || field.classList.contains('shogun')) {
|
||||
return false;
|
||||
@ -282,386 +337,10 @@ class Game {
|
||||
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
|
||||
releaseFigure(targetField) {
|
||||
var source = document.querySelector('[data-x="'+this.chosenFigure.getX()+'"][data-y="'+this.chosenFigure.getY()+'"]');
|
||||
var colorClass = source.classList.contains('white') ? 'white' : 'black';
|
||||
var oppositeColorClass = source.classList.contains('white') ? 'black' : 'white';
|
||||
var figureClass = source.classList.contains('farmer') ? 'farmer' : 'shogun';
|
||||
var figureData = source.getAttribute('data-figure');
|
||||
source.removeChild(source.childNodes[0]);
|
||||
@ -672,9 +351,8 @@ class Game {
|
||||
targetField.setAttribute('data-figure', figureData);
|
||||
this.removeIndicator();
|
||||
this.showPossibleMoves();
|
||||
this.chosenFigure.setX(0);
|
||||
this.chosenFigure.setY(0);
|
||||
|
||||
this.chosenFigure.reset();
|
||||
game.updateLists();
|
||||
}
|
||||
|
||||
removeIndicator() {
|
||||
@ -683,6 +361,12 @@ class Game {
|
||||
item.classList.remove('possibleMove')
|
||||
})
|
||||
}
|
||||
updateLists() {
|
||||
var whiteList = document.querySelector('.whitePlayer');
|
||||
var blackList = document.querySelector('.blackPlayer');
|
||||
console.log(whiteList)
|
||||
console.log(blackList)
|
||||
}
|
||||
}
|
||||
|
||||
class Player {
|
||||
|
Loading…
x
Reference in New Issue
Block a user