-
Notifications
You must be signed in to change notification settings - Fork 1
/
Qml_Connection.cpp
316 lines (268 loc) · 14.9 KB
/
Qml_Connection.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include "Qml_Connection.h"
/*****************************************************************
* File: Qml_Connection.cpp
* Author: Haodong LI
* Usage: TheUsageOfFile
* Time: 2021-05-31 -> 20:29:48
*****************************************************************/
Qml_Connection::Qml_Connection()
{
isEndGameMode = false;
}
void Qml_Connection::moveChessAnimationBegin(int start_X, int start_Y, int end_X, int end_Y) {
object->setProperty(QString("isAnimation").toLatin1(), true);
object->setProperty(QString("animation_start_X").toLatin1(), start_X);
object->setProperty(QString("animation_start_Y").toLatin1(), start_Y);
object->setProperty(QString("animation_end_X").toLatin1(), end_X);
object->setProperty(QString("animation_end_Y").toLatin1(), end_Y);
}
void Qml_Connection::moveChessAnimationEnd() {
object->setProperty(QString("isAnimation").toLatin1(), false);
}
void Qml_Connection::changeChessPos(int chessName, int number, bool camp, SGeoPoint *Pos) {
// number already contain the infomation of camp, chessName also contains
QString name = GlobalEnvirIn::Instance()->__int2QStrName(chessName) + QString::number(number);
if(name.isEmpty()) {
qDebug() << "ERROR! Qml_Connection.cpp changeChessPos() line: 17";
return;
}
moveChessAnimationBegin(GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosX(),
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosY(),
Pos->getPosX(),
Pos->getPosY());
int cur_x = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosX();
int cur_y = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosY();
double current_x = coordinateIn::Instance()->tranRealPosX(cur_x);
double current_y = coordinateIn::Instance()->tranRealPosY(cur_y);
double target_x = coordinateIn::Instance()->tranRealPosX(Pos->getPosX());
double target_y = coordinateIn::Instance()->tranRealPosY(Pos->getPosY());
double length = sqrt((Pos->getPosX() - cur_x) * (Pos->getPosX() - cur_x) + (Pos->getPosY() - cur_y) * (Pos->getPosY() - cur_y));
int num_pieces = 10;
int num_pieces_d = 10.0;
if(length >= 4.0) {
num_pieces += int((length - 4.0)/2.0);
num_pieces_d = double(num_pieces);
}
double delta_x = (target_x - current_x)/num_pieces_d;
double delta_y = (target_y - current_y)/num_pieces_d;
for(int i = 0; i < num_pieces; i++) {
object->setProperty((name + QString("_posX")).toLatin1(), current_x + delta_x * (double)i);
object->setProperty((name + QString("_posY")).toLatin1(), current_y + delta_y * (double)i);
GlobalEnvirIn::Instance()->__delayMsec(20);
}
object->setProperty((name + QString("_posX")).toLatin1(), coordinateIn::Instance()->tranRealPosX(Pos->getPosX()));
object->setProperty((name + QString("_posY")).toLatin1(), coordinateIn::Instance()->tranRealPosY(Pos->getPosY()));
if(GlobalEnvirIn::Instance()->__isThereHasChess(Pos)) {
killThisChess(Pos);
}
moveChessAnimationEnd();
GlobalEnvirIn::Instance()->__delayMsec(5);
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosX(Pos->getPosX());
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosY(Pos->getPosY());
if(chessName == PARAM::globalEnvironment::CHESS_TABLE::BLACK_GENERAL || chessName == PARAM::globalEnvironment::CHESS_TABLE::RED_GENERAL) {
GlobalEnvirIn::Instance()->__refershPosValueUnit();
}
}
void Qml_Connection::changeChessPos(QString chessName, int number, bool camp, SGeoPoint *Pos) {
int chessNameInt = GlobalEnvirIn::Instance()->__QStr2intName(chessName);
if(chessNameInt == -1) {
qDebug() << "ERROR! Qml_Connection.cpp changeChessPos() line: 27";
return;
}
changeChessPos(chessNameInt, number, camp, Pos); // call other function
}
void Qml_Connection::changeChessPos(int chessName, int number, bool camp, int deltaX, int deltaY) {
// chessName like b_gen_, r_adv_
QString name = GlobalEnvirIn::Instance()->__int2QStrName(chessName) + QString::number(number);
if(name.isEmpty()) {
qDebug() << "ERROR! Qml_Connection.cpp changeChessPos() line: 36";
return;
}
int posX = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosX() + deltaX; // first call
int posY = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosY() + deltaY; // second call
moveChessAnimationBegin(GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosX(),
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosY(),
posX,
posY);
int cur_x = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosX();
int cur_y = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosY();
double current_x = coordinateIn::Instance()->tranRealPosX(cur_x);
double current_y = coordinateIn::Instance()->tranRealPosY(cur_y);
double target_x = coordinateIn::Instance()->tranRealPosX(posX);
double target_y = coordinateIn::Instance()->tranRealPosY(posY);
double length = sqrt((posX - cur_x) * (posX - cur_x) + (posY - cur_y) * (posY - cur_y));
int num_pieces = 10;
int num_pieces_d = 10.0;
if(length >= 4.0) {
num_pieces += int((length - 4.0)/2.0);
num_pieces_d = double(num_pieces);
}
double delta_x = (target_x - current_x)/num_pieces_d;
double delta_y = (target_y - current_y)/num_pieces_d;
for(int i = 0; i < num_pieces; i++) {
object->setProperty((name + QString("_posX")).toLatin1(), current_x + delta_x * (double)i);
object->setProperty((name + QString("_posY")).toLatin1(), current_y + delta_y * (double)i);
GlobalEnvirIn::Instance()->__delayMsec(20);
}
object->setProperty((name + QString("_posX")).toLatin1(), coordinateIn::Instance()->tranRealPosX(posX));
object->setProperty((name + QString("_posY")).toLatin1(), coordinateIn::Instance()->tranRealPosY(posY));
if(GlobalEnvirIn::Instance()->__isThereHasChess(posX, posY)) {
killThisChess(posX, posY);
}
moveChessAnimationEnd();
GlobalEnvirIn::Instance()->__delayMsec(5);
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosX(posX);
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosY(posY);
if(chessName == PARAM::globalEnvironment::CHESS_TABLE::BLACK_GENERAL || chessName == PARAM::globalEnvironment::CHESS_TABLE::RED_GENERAL) {
GlobalEnvirIn::Instance()->__refershPosValueUnit();
}
}
void Qml_Connection::changeChessPos(QString chessName, int number, bool camp, int deltaX, int deltaY) {
int chessNameInt = GlobalEnvirIn::Instance()->__QStr2intName(chessName);
if(chessNameInt == -1) {
qDebug() << "ERROR! Qml_Connection.cpp changeChessPos() line: 44";
return;
}
changeChessPos(chessNameInt, number, camp, deltaX ,deltaY); // call other function
}
void Qml_Connection::killThisChess(SGeoPoint *Pos) {
QString killName = GlobalEnvirIn::Instance()->__QString2SimpleName(GlobalEnvirIn::Instance()->__whichChessOnThere(Pos)->chessName());
int killNum = GlobalEnvirIn::Instance()->__QStr2intName(killName);
int killNumber = GlobalEnvirIn::Instance()->__whichChessOnThere(Pos)->chessNumber();
GlobalEnvirIn::Instance()->__whichChessOnThere(Pos)->setAlive(false);
object->setProperty(
(GlobalEnvirIn::Instance()->__int2QStrName(killNum) +
QString::number(killNumber) +
QString("_alive")).toLatin1(), false);
// std::cout << "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH" << std::endl;
// QString camp_killed = GlobalEnvirIn::Instance()->__whichChessOnThere(Pos)->chessCamp() ? "red_" : "black_";
// QString name_killed = GlobalEnvirIn::Instance()->__whichChessOnThere(Pos)->chessName().remove(0, 1);
// QString image_killed = QString("../chess/") + camp_killed + name_killed + QString(".svg");
// object->setProperty(QString("killedChessDisplay").toLatin1(), true);
// object->setProperty(QString("killed").toLatin1(), image_killed.toLatin1());
// std::cout << image_killed.toStdString() << std::endl;
}
void Qml_Connection::killThisChess(int PosX, int PosY) {
SGeoPoint* Pos = new SGeoPoint(PosX, PosY);
killThisChess(Pos);
delete Pos;
}
void Qml_Connection::fakeChangeChessPos(int chessName, int number, bool camp, SGeoPoint *Pos) {
// number already contain the infomation of camp, chessName also contains
QString name = GlobalEnvirIn::Instance()->__int2QStrName(chessName) + QString::number(number);
if(name.isEmpty()) {
qDebug() << "ERROR! Qml_Connection.cpp fakeChangeChessPos() line: 87";
return;
}
if(GlobalEnvirIn::Instance()->__isThereHasChess(Pos)) {
fakeKillThisChess(Pos);
}
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosX(Pos->getPosX());
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosY(Pos->getPosY());
if(chessName == PARAM::globalEnvironment::CHESS_TABLE::BLACK_GENERAL || chessName == PARAM::globalEnvironment::CHESS_TABLE::RED_GENERAL) {
GlobalEnvirIn::Instance()->__refershPosValueUnit();
}
}
void Qml_Connection::fakeChangeChessPos(QString chessName, int number, bool camp, SGeoPoint *Pos) {
int chessNameInt = GlobalEnvirIn::Instance()->__QStr2intName(chessName);
if(chessNameInt == -1) {
qDebug() << "ERROR! Qml_Connection.cpp fakeChangeChessPos() line: 104";
return;
}
fakeChangeChessPos(chessNameInt, number, camp, Pos); // call other function
}
void Qml_Connection::fakeChangeChessPos(int chessName, int number, bool camp, int deltaX, int deltaY) {
// chessName like b_gen_, r_adv_
QString name = GlobalEnvirIn::Instance()->__int2QStrName(chessName) + QString::number(number);
if(name.isEmpty()) {
qDebug() << "ERROR! Qml_Connection.cpp fakeChangeChessPos() line: 113";
return;
}
int posX = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosX() + deltaX; // first call
int posY = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosY() + deltaY; // second call
if(GlobalEnvirIn::Instance()->__isThereHasChess(posX, posY)) {
fakeKillThisChess(posX, posY);
}
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosX(posX);
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosY(posY);
if(chessName == PARAM::globalEnvironment::CHESS_TABLE::BLACK_GENERAL || chessName == PARAM::globalEnvironment::CHESS_TABLE::RED_GENERAL) {
GlobalEnvirIn::Instance()->__refershPosValueUnit();
}
}
void Qml_Connection::fakeChangeChessPos(QString chessName, int number, bool camp, int deltaX, int deltaY) {
int chessNameInt = GlobalEnvirIn::Instance()->__QStr2intName(chessName);
if(chessNameInt == -1) {
qDebug() << "ERROR! Qml_Connection.cpp fakeChangeChessPos() line: 44";
return;
}
fakeChangeChessPos(chessNameInt, number, camp, deltaX ,deltaY); // call other function
}
void Qml_Connection::fakeKillThisChess(SGeoPoint *Pos) {
GlobalEnvirIn::Instance()->__whichChessOnThere(Pos)->setAlive(false);
}
void Qml_Connection::fakeKillThisChess(int PosX, int PosY) {
SGeoPoint* Pos = new SGeoPoint(PosX, PosY);
fakeKillThisChess(Pos);
delete Pos;
}
void Qml_Connection::fakeBackChangeChessPos(int chessName, int number, bool camp, int deltaX, int deltaY) {
// chessName like b_gen_, r_adv_
QString name = GlobalEnvirIn::Instance()->__int2QStrName(chessName) + QString::number(number);
if(name.isEmpty()) {
qDebug() << "ERROR! Qml_Connection.cpp fakeBackChangeChessPos() line: 177";
return;
}
int posX = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosX() + deltaX; // first call
int posY = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->getPosY() + deltaY; // second call
if(GlobalEnvirIn::Instance()->__isThereHasChess(posX, posY)) {
qDebug() << "ERROR! Qml_Connection.cpp fakeBackChangeChessPos() line: 185 Back Pos Has Chess! " << posX << "," << posY << " " << chessName << number;
return;
}
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosX(posX);
GlobalEnvirIn::Instance()->__QStrOrInt2Chess(chessName, number)->setPosY(posY);
if(chessName == PARAM::globalEnvironment::CHESS_TABLE::BLACK_GENERAL || chessName == PARAM::globalEnvironment::CHESS_TABLE::RED_GENERAL) {
GlobalEnvirIn::Instance()->__refershPosValueUnit();
}
}
void Qml_Connection::fakeBackChangeChessPos(QString chessName, int number, bool camp, int deltaX, int deltaY) {
int chessNameInt = GlobalEnvirIn::Instance()->__QStr2intName(chessName);
if(chessNameInt == -1) {
qDebug() << "ERROR! Qml_Connection.cpp fakeBackChangeChessPos() line: 195";
return;
}
fakeBackChangeChessPos(chessNameInt, number, camp, deltaX ,deltaY); // call other function
}
void Qml_Connection::setWinnerWhenOnlyGeneralsInRow(bool redOrBlack) {
if(redOrBlack) object->setProperty("onlyTwoGeneralsInRow_redWin", true);
else object->setProperty("onlyTwoGeneralsInRow_blackWin", true);
}
void Qml_Connection::setEndGameMode(bool isInEndGameMode) {
isEndGameMode = isInEndGameMode;
object->setProperty("is_endgame_mode", isInEndGameMode);
}
void Qml_Connection::setWhetherVisionDone(bool isVisionDone) {
if(isEndGameMode == false) {
qDebug() << "Qml_Connection.cpp function:setWhetherVisionDone() line:210 EngGameMode = false!!!!!";
}
else object->setProperty("is_vision_board_done", isVisionDone);
}
void Qml_Connection::eraseChessOnCanvas(int num, int number) {
object->setProperty((GlobalEnvirIn::Instance()->__int2QStrName(num) +
QString::number(number) + QString("_alive")).toLatin1(), false);
}
void Qml_Connection::moveChessOnCanvas(int num, int number) {
QString chessName = GlobalEnvirIn::Instance()->__int2QStrName(num) + QString::number(number);
int PosX = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(num, number)->getPosX();
int PosY = GlobalEnvirIn::Instance()->__QStrOrInt2Chess(num, number)->getPosY();
object->setProperty((chessName + QString("_posX")).toLatin1(), coordinateIn::Instance()->tranRealPosX(PosX));
object->setProperty((chessName + QString("_posY")).toLatin1(), coordinateIn::Instance()->tranRealPosY(PosY));
if(num == PARAM::globalEnvironment::CHESS_TABLE::BLACK_GENERAL || num == PARAM::globalEnvironment::CHESS_TABLE::RED_GENERAL) {
GlobalEnvirIn::Instance()->__refershPosValueUnit();
}
}
void Qml_Connection::whetherStrategyMode(bool curStrategyMode) {
object->setProperty("is_strategy_mode", curStrategyMode);
}
void Qml_Connection::setStrategyMode(int curStrategyMode) {
object->setProperty("strategy_mode", curStrategyMode);
}