-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerWhite.java
More file actions
182 lines (160 loc) · 5.79 KB
/
Copy pathPlayerWhite.java
File metadata and controls
182 lines (160 loc) · 5.79 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package Objects;
import java.awt.*;
import Data.Data;
import Util.Util;
public class PlayerWhite extends Player {
int[][] chessPositionArray = new int[15][15];
public PlayerWhite() {
this.name = "白方";
this.color = Color.white;
}
@Override
public void repentanceChess() {
if (Data.chessArray.size() > 2) {
Data.chessArray.remove(Data.chessArray.size() - 1);
if (Data.pattern == 0) {
Data.gameState = 0;
} else if (Data.pattern == 1) {
Data.gameState = 2;
}
}
}
@Override
public void writeChess() {
if (Data.gameEnd == 0) {
// 当前鼠标坐标
int x = Data.mousePointer.x;
int y = Data.mousePointer.y;
// 转换成棋盘坐标
row = (Util.round(x)) / 40;
column = (Util.round(y)) / 40;
// 检查当前位置是否已有棋子
for (Chess chess : Data.chessArray) {
if (chess.equal(new Chess(row, column, color))) {
return;
}
}
// 向棋盘数组添加棋子
Data.chessArray.add(new Chess(row, column, color));
chessPositionArray[row][column] = -1;
// 根据当前模式交换下棋方
if (Data.pattern == 0) {
Data.gameState = 0;
}
ifWin();
}
}
@Override
public void ifWin() {
// 游戏结束不判断
if (Data.gameEnd == 0) {
// 当棋子总数大于等于9时才判断
if (Data.chessArray.size() >= 1) {
// 初始化变量
chessPositionArray = Util.getChessPositionArray(Data.chessArray);
int positionX = row;
int positionY = column;
// 检查同一行右方向是否有相同颜色棋子
if (!(positionX == 14)) {
while (chessPositionArray[row][column] == chessPositionArray[positionX + 1][positionY]) {
count++;
positionX++;
if (positionX == 14) {
break;
}
}
}
// 检查同一行左方向
positionX = row;
if (!(positionX == 0)) {
while (chessPositionArray[row][column] == chessPositionArray[positionX - 1][positionY]) {
count++;
positionX--;
if (positionX == 0) {
break;
}
}
}
winOrLose();
count = 0;
// 检查同一列下方向
if (!(positionY == 14)) {
while (chessPositionArray[row][column] == chessPositionArray[positionX][positionY + 1]) {
count++;
positionY++;
if (positionY == 14) {
break;
}
}
}
// 检查同一列上方向
positionY = column;
if (!(positionY == 0)) {
while (chessPositionArray[row][column] == chessPositionArray[row][positionY - 1]) {
count++;
positionY--;
if (positionY == 0) {
break;
}
}
}
winOrLose();
count = 0;
// 检查右下方向
positionX = row;
positionY = column;
if (!(positionX == 14 || positionY == 14))
while (chessPositionArray[row][column] == chessPositionArray[positionX + 1][positionY + 1]) {
count++;
positionX++;
positionY++;
if (positionX == 14 || positionY == 14) {
break;
}
}
// 检查方左上方向
positionX = row;
positionY = column;
if (!(positionX == 0 || positionY == 0)) {
while (chessPositionArray[row][column] == chessPositionArray[positionX - 1][positionY - 1]) {
count++;
positionX--;
positionY--;
if (positionX == 0 || positionY == 0) {
break;
}
}
}
winOrLose();
count = 0;
// 检查右上方向
positionX = row;
positionY = column;
if (!(positionX == 14 || positionY == 0)) {
while (chessPositionArray[row][column] == chessPositionArray[positionX + 1][positionY - 1]) {
count++;
positionX++;
positionY--;
if (positionX == 14 || positionY == 0) {
break;
}
}
}
// 检查左下方向
positionX = row;
positionY = column;
if (!(positionX == 0 || positionY == 14)) {
while (chessPositionArray[row][column] == chessPositionArray[positionX - 1][positionY + 1]) {
count++;
positionX--;
positionY++;
if (positionX == 0 || positionY == 14) {
break;
}
}
}
winOrLose();
}
}
}
}