diff --git a/.gitignore b/.gitignore index 827be054..c0a5a30a 100644 --- a/.gitignore +++ b/.gitignore @@ -261,7 +261,9 @@ __pycache__/ *.pyc - +# exe and dll +*.exe +*.dll diff --git a/NineChess/ninechesswindow.ui b/NineChess/ninechesswindow.ui index 7c89041c..4253e5cc 100644 --- a/NineChess/ninechesswindow.ui +++ b/NineChess/ninechesswindow.ui @@ -72,8 +72,6 @@ - - @@ -493,15 +491,6 @@ 另存为(&A)... - - - - :/icon/Resources/icon/EditInformationHS.png:/icon/Resources/icon/EditInformationHS.png - - - 查看文本棋谱(&V) - - 退出(&X) diff --git a/NineChess/src/boarditem.cpp b/NineChess/src/boarditem.cpp index 9e5d3865..fb4a6f7d 100644 --- a/NineChess/src/boarditem.cpp +++ b/NineChess/src/boarditem.cpp @@ -5,7 +5,7 @@ BoardItem::BoardItem(QGraphicsItem *parent ) : QGraphicsItem(parent), size(BOARD_SIZE), sizeShadow(5.0), - hasObliqueLine(false) + hasObliqueLine(false) { Q_UNUSED(parent) // 棋盘中心放在场景中心 diff --git a/NineChess/src/boarditem.h b/NineChess/src/boarditem.h index f5063e70..6f341609 100644 --- a/NineChess/src/boarditem.h +++ b/NineChess/src/boarditem.h @@ -29,6 +29,7 @@ public: static const int RING = 3; // 8位,禁止修改! static const int SEAT = 8; + private: // 棋盘尺寸 qreal size; diff --git a/NineChess/src/gamecontroller.cpp b/NineChess/src/gamecontroller.cpp index 39741a60..2c69da17 100644 --- a/NineChess/src/gamecontroller.cpp +++ b/NineChess/src/gamecontroller.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "gamecontroller.h" #include "graphicsconst.h" #include "boarditem.h" @@ -42,6 +43,10 @@ stepsLimit(0) GameController::~GameController() { + // 清除棋子 + qDeleteAll(pieceList); + pieceList.clear(); + piece = NULL; } const QMap GameController::getActions() @@ -89,6 +94,35 @@ void GameController::gameReset() // 重新绘制棋盘 scene.setDiagonal(chess.getRule()->hasObliqueLine); + // 绘制所有棋子,放在起始位置,分成2组写,后面好区分 + for (int i = 0; i < chess.getRule()->numOfChess; i++) + { + PieceItem::Models md = isInverted ? PieceItem::whitePiece : PieceItem::blackPiece; + PieceItem *newP = new PieceItem; + newP->setModel(md); + newP->setPos(scene.pos_p1); + newP->setNum(i + 1); + // 如果重复三连不可用,则显示棋子序号,九连棋专用玩法 + if (!(chess.getRule()->canRepeated)) + newP->setShowNum(true); + pieceList.append(newP); + scene.addItem(newP); + } + for (int i = 0; i < chess.getRule()->numOfChess; i++) + { + PieceItem::Models md = isInverted ? PieceItem::blackPiece : PieceItem::whitePiece; + PieceItem *newP = new PieceItem; + newP->setModel(md); + newP->setPos(scene.pos_p2); + newP->setNum(i + 1); + // 如果重复三连不可用,则显示棋子序号,九连棋专用玩法 + if (!(chess.getRule()->canRepeated)) + newP->setShowNum(true); + pieceList.append(newP); + scene.addItem(newP); + } + + // 读取规则限时要求 timeLimit = chess.getRule()->maxTime; // 如果规则不要求计时,则time1和time2表示已用时间 @@ -511,43 +545,67 @@ bool GameController::giveUp() bool GameController::updateScence(NineChess &chess) { - // 清除棋子 - qDeleteAll(pieceList); - pieceList.clear(); - piece = NULL; + const char *board = chess.getBoard(); + QPointF pos; + int key; + int n = chess.getRule()->numOfChess * 2; - const char *board = chess.getBoard(); - QPointF pos; + // 棋子就位 + for (int i = 0; i < n; i++) + { + key = (i >= n/2) ? (i + 0x21 -n/2) : (i + 0x11); + int j; + for (j = NineChess::SEAT; j < (NineChess::SEAT)*(NineChess::RING + 1); j++) + { + if (board[j] == key) + { + pos = scene.cp2pos(j / NineChess::SEAT, j % NineChess::SEAT + 1); + pieceList.at(i)->setPos(pos); + break; + } + } + if (j == (NineChess::SEAT)*(NineChess::RING + 1)) + { + pieceList.at(i)->setPos((i % 2) ? scene.pos_p2 : scene.pos_p1); + } + } - for (int i = NineChess::SEAT; i < (NineChess::SEAT)*(NineChess::RING + 1); i++) { - pos = scene.cp2pos(i / NineChess::SEAT, i % NineChess::SEAT + 1); - if (board[i] & 0x30) { - PieceItem *newP = NULL; - PieceItem::Models md; - if (isInverted) - md = (board[i] & 0x10) ? PieceItem::whitePiece : PieceItem::blackPiece; - else - md = (board[i] & 0x10) ? PieceItem::blackPiece : PieceItem::whitePiece; - newP = new PieceItem; - newP->setModel(md); - newP->setPos(pos); - newP->setNum(chess.getPieceNum(i / NineChess::SEAT, i % NineChess::SEAT + 1)); - // 如果重复三连不可用,则显示棋子序号 - if (!(chess.getRule()->canRepeated)) - newP->setShowNum(true); - pieceList.append(newP); - scene.addItem(newP); - } - else if (board[i] & 0x0F) { - PieceItem *newP = NULL; - newP = new PieceItem; - newP->setDeleted(); - newP->setPos(pos); - pieceList.append(newP); - scene.addItem(newP); - } - } + // 添加开局禁子点 + if (chess.getRule()->hasForbidden && chess.getPhase() == NineChess::GAME_OPENING) + { + for (int j = NineChess::SEAT; j < (NineChess::SEAT)*(NineChess::RING + 1); j++) + { + if (board[j] == 0x0F) + { + pos = scene.cp2pos(j / NineChess::SEAT, j % NineChess::SEAT + 1); + if (n < pieceList.size()) + { + pieceList.at(n++)->setPos(pos); + } + else + { + PieceItem *newP = new PieceItem; + newP->setDeleted(); + newP->setPos(pos); + pieceList.append(newP); + n++; + scene.addItem(newP); + } + } + } + } + // 中局清除禁子点 + if (chess.getRule()->hasForbidden && chess.getPhase() != NineChess::GAME_OPENING) + { + while (n < pieceList.size()) + { + delete pieceList.at(n); + pieceList.removeAt(n); + } + } + + // 选中当前棋子 int ipos = chess.getCurrentPos(); if (ipos) { pos = scene.cp2pos(ipos / NineChess::SEAT, ipos % NineChess::SEAT + 1); diff --git a/NineChess/src/gamescene.cpp b/NineChess/src/gamescene.cpp index 2811e322..602702e6 100644 --- a/NineChess/src/gamescene.cpp +++ b/NineChess/src/gamescene.cpp @@ -1,13 +1,19 @@ #include "gamescene.h" #include "pieceitem.h" #include "boarditem.h" +#include "graphicsconst.h" #include #include #include #include #include -GameScene::GameScene(QObject *parent) : QGraphicsScene(parent), board(NULL) +GameScene::GameScene(QObject *parent) : QGraphicsScene(parent), + board(NULL), + pos_p1(LINE_INTERVAL * 6, LINE_INTERVAL * 3), + pos_p1_g(LINE_INTERVAL* (-6), LINE_INTERVAL * 3), + pos_p2(LINE_INTERVAL * (-6), LINE_INTERVAL * (-3)), + pos_p2_g(LINE_INTERVAL * 6, LINE_INTERVAL * (-3)) { // 添加棋盘 board = new BoardItem; diff --git a/NineChess/src/gamescene.h b/NineChess/src/gamescene.h index 308c91b4..fb6884e9 100644 --- a/NineChess/src/gamescene.h +++ b/NineChess/src/gamescene.h @@ -17,6 +17,10 @@ public: bool pos2cp(QPointF pos, int &c, int &p); // 设置棋盘斜线 void setDiagonal(bool arg = true); + // 玩家1的己方棋盒及对方棋盒位置 + const QPointF pos_p1, pos_p1_g; + // 玩家2的己方棋盒及对方棋盒位置 + const QPointF pos_p2, pos_p2_g; protected: void keyPressEvent(QKeyEvent *keyEvent); diff --git a/NineChess/src/ninechesswindow.cpp b/NineChess/src/ninechesswindow.cpp index 1ea34472..10653d41 100644 --- a/NineChess/src/ninechesswindow.cpp +++ b/NineChess/src/ninechesswindow.cpp @@ -51,14 +51,11 @@ NineChessWindow::NineChessWindow(QWidget *parent) ui.gameView->setRenderHint(QPainter::Antialiasing); // 因功能限制,使部分功能不可用 - ui.actionViewText_V->setDisabled(true); - ui.actionAutoRun_A->setDisabled(true); ui.actionEngine_E->setDisabled(true); ui.actionInternet_I->setDisabled(true); ui.actionEngine1_T->setDisabled(true); ui.actionEngine2_R->setDisabled(true); ui.actionSetting_O->setDisabled(true); - ui.actionAnimation_A->setDisabled(true); // 关联既有动作信号和主窗口槽 // 视图上下翻转 @@ -328,11 +325,6 @@ void NineChessWindow::on_actionSaveAs_A_triggered() } -void NineChessWindow::on_actionViewText_V_triggered() -{ - -} - void NineChessWindow::on_actionEdit_E_toggled(bool arg1) { @@ -395,6 +387,7 @@ void NineChessWindow::on_actionRowChange() ui.actionPrevious_B->setEnabled(false); ui.actionNext_F->setEnabled(false); ui.actionEnd_E->setEnabled(false); + ui.actionAutoRun_A->setEnabled(false); } else { if (currentRow <= 0) { @@ -402,23 +395,74 @@ void NineChessWindow::on_actionRowChange() ui.actionPrevious_B->setEnabled(false); ui.actionNext_F->setEnabled(true); ui.actionEnd_E->setEnabled(true); - } - if (currentRow >= rows - 1) + ui.actionAutoRun_A->setEnabled(true); + } + else if (currentRow >= rows - 1) { ui.actionBegin_S->setEnabled(true); ui.actionPrevious_B->setEnabled(true); ui.actionNext_F->setEnabled(false); ui.actionEnd_E->setEnabled(false); - } + ui.actionAutoRun_A->setEnabled(false); + } + else + { + ui.actionBegin_S->setEnabled(true); + ui.actionPrevious_B->setEnabled(true); + ui.actionNext_F->setEnabled(true); + ui.actionEnd_E->setEnabled(true); + ui.actionAutoRun_A->setEnabled(true); + } } // 更新局面 game->phaseChange(currentRow); } +// 自动运行 void NineChessWindow::on_actionAutoRun_A_toggled(bool arg1) { + int rows = ui.listView->model()->rowCount(); + int currentRow = ui.listView->currentIndex().row(); + if (rows <= 1) + return; + + // 反复执行“下一招” + while (currentRow < rows - 1) + { + if (currentRow < rows - 1) + { + ui.listView->setCurrentIndex(ui.listView->model()->index(currentRow + 1, 0)); + } + currentRow = ui.listView->currentIndex().row(); + // 更新动作状态 + if (currentRow <= 0) { + ui.actionBegin_S->setEnabled(false); + ui.actionPrevious_B->setEnabled(false); + ui.actionNext_F->setEnabled(true); + ui.actionEnd_E->setEnabled(true); + ui.actionAutoRun_A->setEnabled(true); + } + else if (currentRow >= rows - 1) + { + ui.actionBegin_S->setEnabled(true); + ui.actionPrevious_B->setEnabled(true); + ui.actionNext_F->setEnabled(false); + ui.actionEnd_E->setEnabled(false); + ui.actionAutoRun_A->setEnabled(false); + } + else + { + ui.actionBegin_S->setEnabled(true); + ui.actionPrevious_B->setEnabled(true); + ui.actionNext_F->setEnabled(true); + ui.actionEnd_E->setEnabled(true); + ui.actionAutoRun_A->setEnabled(true); + } + // 更新局面 + game->phaseChange(currentRow); + } } diff --git a/NineChess/src/ninechesswindow.h b/NineChess/src/ninechesswindow.h index 2ba8c4ee..4ade631d 100644 --- a/NineChess/src/ninechesswindow.h +++ b/NineChess/src/ninechesswindow.h @@ -48,7 +48,6 @@ private slots: void on_actionOpen_O_triggered(); void on_actionSave_S_triggered(); void on_actionSaveAs_A_triggered(); - void on_actionViewText_V_triggered(); //void on_actionExit_X_triggered(); void on_actionEdit_E_toggled(bool arg1); //void on_actionFlip_F_triggered();