-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathField
124 lines (110 loc) · 4.42 KB
/
Field
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package schach;
public abstract class Figure extends ChessRun {
ChessGame chessGame = new ChessGame();
public int xStart, yStart;
static ColorFigure colorFigure;
public ChessRun.Type type;
public String value;
public Figure(int xStart, int yStart, ColorFigure colorFigure) {
this.xStart = xStart;
this.yStart = yStart;
this.colorFigure = colorFigure;
}
public abstract boolean moveIsPossible(int move, int figure);
public abstract void makeMove(int posStart, int posEnd);
public boolean pathForMoveIsFree(int posStart, int posEnd) {
//überprüfen, dass die Figuren nicht durch andere Figuren gehen
boolean free = true;
int xStart = posStart % 10 - 1;
int yStart = posStart / 10 - 1;
int xEnd = posEnd % 10 - 1;
int yEnd = posEnd / 10 - 1;
int delta_x = xEnd - xStart;
int delta_y = yEnd - yStart;
ColorFigure presentColorFigure = chessGame.askColor(posStart);
System.out.println("Present Color is " + presentColorFigure);
ColorFigure oppositeColorFigure;
if (presentColorFigure == ColorFigure.Black)
oppositeColorFigure = ColorFigure.White;
else oppositeColorFigure = ColorFigure.Black;
System.out.println("Opposite Color is " + oppositeColorFigure);
if (delta_x >= 0 && delta_y >= 0) {
System.out.println("Case 1 [+ +]");
if (delta_x == 0) {//horizontal
for (int i = 1; i <= delta_y; i++) {
if ((ChessGame.field[xStart][yStart + i].type != Type.Null)
&& ChessGame.field[xEnd][yEnd].colorFigure != oppositeColorFigure) {
free = false;
break;
}
}
} else if (delta_y == 0) {//vertikal
for (int i = 1; i <= delta_x; i++) {
if (ChessGame.field[xStart + i][yStart].type != Type.Null) {
free = false;
break;
}
}
} else {//sonst - diagonal
for (int i = 1; i <= delta_x; i++) {
if (ChessGame.field[xStart + i][yStart + i].type != Type.Null) {
free = false;
break;
}
}
}
} else if (delta_x >= 0) {
System.out.println("Case 2 [+ -]");
if (delta_x == 0) {//horizontal
for (int i = delta_y; i >= -1; i--) {
if (ChessGame.field[xStart][yStart + i].type != Type.Null) {
free = false;
break;
}
}
} else {//sonst - diagonal
for (int i = 1; i <= delta_x; i++) {
if (ChessGame.field[xStart + i][yStart - i].type != Type.Null) {
free = false;
break;
}
}
}
} else if (delta_y >= 0) {
System.out.println("Case 3 [- +]");
if (delta_y == 0) {//vertikal
for (int i = delta_x; i >= -1; i--) {
if (ChessGame.field[xStart + i][yStart].type != Type.Null) {
free = false;
break;
}
}
} else {//sonst - diagonal
for (int i = 1; i <= delta_y; i++) {
if (ChessGame.field[xStart - i][yStart + i].type != Type.Null) {
free = false;
break;
}
}
}
} else {
System.out.println("Case 4 [- -]");
//nur diagonal
for (int i = 1; i <= -delta_x; i++) {
if (ChessGame.field[xStart - i][yStart - i].type != Type.Null) {
free = false;
break;
}
}
}
System.out.println(xStart + " - " + yStart + " - Start");
System.out.println(xEnd + " - " + yEnd + " - End");
System.out.println(ChessGame.field[xStart][yStart].type + " - Start");
System.out.println(ChessGame.field[xEnd][yEnd].type + " - End");
if (!free)
System.out.println("Move is not possible because of a barrier");
return free;
}
public void pathFor1Case(){
}
}