GameController: Position * 改为 Position &

This commit is contained in:
Calcitem 2020-09-06 12:37:35 +08:00
parent 31d9bd8294
commit a021eb9da7
2 changed files with 22 additions and 22 deletions

View File

@ -294,18 +294,18 @@ void GameController::setInvert(bool arg)
isInverted = arg; isInverted = arg;
// 遍历所有棋子 // 遍历所有棋子
for (PieceItem *p : pieceList) { for (PieceItem *pieceItem : pieceList) {
if (p) { if (pieceItem) {
// 黑子变白 // 黑子变白
if (p->getModel() == PieceItem::blackPiece) if (pieceItem->getModel() == PieceItem::blackPiece)
p->setModel(PieceItem::whitePiece); pieceItem->setModel(PieceItem::whitePiece);
// 白子变黑 // 白子变黑
else if (p->getModel() == PieceItem::whitePiece) else if (pieceItem->getModel() == PieceItem::whitePiece)
p->setModel(PieceItem::blackPiece); pieceItem->setModel(PieceItem::blackPiece);
// 刷新棋子显示 // 刷新棋子显示
p->update(); pieceItem->update();
} }
} }
#endif // TRAINING_MODE #endif // TRAINING_MODE
@ -953,7 +953,7 @@ bool GameController::command(const QString &cmd, bool update /* = true */)
if (update) { if (update) {
playSound(soundType, position.side_to_move()); playSound(soundType, position.side_to_move());
updateScence(&position); updateScence(position);
} }
// 发信号更新状态栏 // 发信号更新状态栏
@ -1117,7 +1117,7 @@ bool GameController::phaseChange(int row, bool forceUpdate)
position.set_start_time(static_cast<int>(position.start_timeb())); position.set_start_time(static_cast<int>(position.start_timeb()));
// 刷新棋局场景 // 刷新棋局场景
updateScence(&position); updateScence(position);
#endif // TRAINING_MODE #endif // TRAINING_MODE
return true; return true;
@ -1126,16 +1126,16 @@ bool GameController::phaseChange(int row, bool forceUpdate)
bool GameController::updateScence() bool GameController::updateScence()
{ {
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
return updateScence(&position); return updateScence(position);
#else #else
return true; return true;
#endif #endif
} }
bool GameController::updateScence(Position *p) bool GameController::updateScence(Position &p)
{ {
#ifndef TRAINING_MODE #ifndef TRAINING_MODE
const Piece *board = p->get_board(); const Piece *board = p.get_board();
QPointF pos; QPointF pos;
// game类中的棋子代码 // game类中的棋子代码
@ -1189,10 +1189,10 @@ bool GameController::updateScence(Position *p)
if (j == (RANK_NB) * (FILE_NB + 1)) { if (j == (RANK_NB) * (FILE_NB + 1)) {
// 判断是被吃掉的子,还是未安放的子 // 判断是被吃掉的子,还是未安放的子
if (key & B_STONE) { if (key & B_STONE) {
pos = (key - 0x11 < nTotalPieces / 2 - p->count<IN_HAND>(BLACK)) ? pos = (key - 0x11 < nTotalPieces / 2 - p.count<IN_HAND>(BLACK)) ?
scene.pos_p2_g : scene.pos_p1; scene.pos_p2_g : scene.pos_p1;
} else { } else {
pos = (key - 0x21 < nTotalPieces / 2 - p->count<IN_HAND>(WHITE)) ? pos = (key - 0x21 < nTotalPieces / 2 - p.count<IN_HAND>(WHITE)) ?
scene.pos_p1_g : scene.pos_p2; scene.pos_p1_g : scene.pos_p2;
} }
@ -1219,7 +1219,7 @@ bool GameController::updateScence(Position *p)
} }
// 添加摆棋阶段禁子点 // 添加摆棋阶段禁子点
if (rule.hasBannedLocations && p->get_phase() == PHASE_PLACING) { if (rule.hasBannedLocations && p.get_phase() == PHASE_PLACING) {
for (int j = SQ_BEGIN; j < SQ_END; j++) { for (int j = SQ_BEGIN; j < SQ_END; j++) {
if (board[j] == BAN_STONE) { if (board[j] == BAN_STONE) {
pos = scene.polar2pos(File(j / RANK_NB), Rank(j % RANK_NB + 1)); pos = scene.polar2pos(File(j / RANK_NB), Rank(j % RANK_NB + 1));
@ -1238,7 +1238,7 @@ bool GameController::updateScence(Position *p)
} }
// 走棋阶段清除禁子点 // 走棋阶段清除禁子点
if (rule.hasBannedLocations && p->get_phase() != PHASE_PLACING) { if (rule.hasBannedLocations && p.get_phase() != PHASE_PLACING) {
while (nTotalPieces < static_cast<int>(pieceList.size())) { while (nTotalPieces < static_cast<int>(pieceList.size())) {
delete pieceList.at(pieceList.size() - 1); delete pieceList.at(pieceList.size() - 1);
pieceList.pop_back(); pieceList.pop_back();
@ -1246,9 +1246,9 @@ bool GameController::updateScence(Position *p)
} }
// 选中当前棋子 // 选中当前棋子
int ipos = p->current_square(); int ipos = p.current_square();
if (ipos) { if (ipos) {
key = board[p->current_square()]; key = board[p.current_square()];
ipos = key & B_STONE ? (key - B_STONE_1) * 2 : (key - W_STONE_1) * 2 + 1; ipos = key & B_STONE ? (key - B_STONE_1) * 2 : (key - W_STONE_1) * 2 + 1;
if (ipos >= 0 && ipos < nTotalPieces) { if (ipos >= 0 && ipos < nTotalPieces) {
currentPiece = pieceList.at(static_cast<size_t>(ipos)); currentPiece = pieceList.at(static_cast<size_t>(ipos));
@ -1264,9 +1264,9 @@ bool GameController::updateScence(Position *p)
animationGroup->start(QAbstractAnimation::DeleteWhenStopped); animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
// 更新比分 LCD 显示 // 更新比分 LCD 显示
emit score1Changed(QString::number(p->score[BLACK], 10)); emit score1Changed(QString::number(p.score[BLACK], 10));
emit score2Changed(QString::number(p->score[WHITE], 10)); emit score2Changed(QString::number(p.score[WHITE], 10));
emit scoreDrawChanged(QString::number(p->score_draw, 10)); emit scoreDrawChanged(QString::number(p.score_draw, 10));
// 更新胜率 LCD 显示 // 更新胜率 LCD 显示
position.nPlayed = position.score[BLACK] + position.score[WHITE] + position.score_draw; position.nPlayed = position.score[BLACK] + position.score[WHITE] + position.score_draw;

View File

@ -327,7 +327,7 @@ public slots:
// 更新棋局显示,每步后执行才能刷新局面 // 更新棋局显示,每步后执行才能刷新局面
bool updateScence(); bool updateScence();
bool updateScence(Position *position); bool updateScence(Position &position);
// 显示网络配置窗口 // 显示网络配置窗口
void showNetworkWindow(); void showNetworkWindow();