From 0257824b6f3f2a10fa7964588b7a3daf5610d320 Mon Sep 17 00:00:00 2001 From: CalciteM Team Date: Sun, 18 Aug 2019 23:59:03 +0800 Subject: [PATCH] =?UTF-8?q?ui:=20=E5=8F=B3=E4=BE=A7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=A0=8F=E6=98=BE=E7=A4=BA=E6=AF=94=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NineChess/ninechesswindow.ui | 77 ++++++++++++++++++++++++++++++- NineChess/src/gamecontroller.cpp | 37 ++++++--------- NineChess/src/gamecontroller.h | 17 ++++--- NineChess/src/ninechesswindow.cpp | 12 +++++ 4 files changed, 112 insertions(+), 31 deletions(-) diff --git a/NineChess/ninechesswindow.ui b/NineChess/ninechesswindow.ui index 54eaf5ea..f8f4dbf7 100644 --- a/NineChess/ninechesswindow.ui +++ b/NineChess/ninechesswindow.ui @@ -23,7 +23,7 @@ false - + @@ -57,7 +57,7 @@ 0 0 491 - 22 + 21 @@ -384,6 +384,79 @@ + + + + + 黑体 + 9 + + + + 比分: + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + false + + + 2 + + + 0.000000000000000 + + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + 2 + + + QLCDNumber::Dec + + + + + + + + 0 + 0 + + + + false + + + 2 + + + diff --git a/NineChess/src/gamecontroller.cpp b/NineChess/src/gamecontroller.cpp index 14148c9f..360ca9e3 100644 --- a/NineChess/src/gamecontroller.cpp +++ b/NineChess/src/gamecontroller.cpp @@ -53,9 +53,7 @@ GameController::GameController(GameScene & scene, QObject * parent) : timeID(0), ruleNo_(-1), timeLimit(0), - stepsLimit(50), - score1(-2), - score2(-2) + stepsLimit(50) { // 已在view的样式表中添加背景,scene中不用添加背景 // 区别在于,view中的背景不随视图变换而变换,scene中的背景随视图变换而变换 @@ -133,16 +131,9 @@ void GameController::gameReset() timeID = 0; // 棋未下完,则算对手得分 - if (score1 < 0 || score2 < 0) { - score1++; - score2++; - } - else { - if (chess_.getStage() == NineChess::GAME_MOVING && - chess_.whoWin() == NineChess::NOBODY) - { - giveUp(); - } + if (chess_.getStage() == NineChess::GAME_MOVING && + chess_.whoWin() == NineChess::NOBODY) { + giveUp(); } #ifdef LCD_SHOW_SCORE_INSTEAD_OF_TIME @@ -234,6 +225,11 @@ void GameController::gameReset() message = QString::fromStdString(chess_.getTips()); emit statusBarChanged(message); + // 更新比分 LCD 显示 + emit score1Changed(QString::number(chess_.score_1, 10)); + emit score2Changed(QString::number(chess_.score_2, 10)); + emit scoreDrawChanged(QString::number(chess_.score_draw, 10)); + // 播放音效 //playSound(":/sound/resources/sound/newgame.wav"); } @@ -561,12 +557,6 @@ void GameController::timerEvent(QTimerEvent *event) // 弹框 //QMessageBox::about(NULL, "游戏结果", message); - if (chess_.whoWin() == NineChess::PLAYER1) { - score1++; - } else if (chess_.whoWin() == NineChess::PLAYER2) { - score2++; - } - #ifdef LCD_SHOW_SCORE_INSTEAD_OF_TIME emit time1Changed(QString::number(score1, 10)); emit time2Changed(QString::number(score2, 10)); @@ -770,13 +760,11 @@ bool GameController::giveUp() if (chess_.whosTurn() == NineChess::PLAYER1) { result = chess_.giveup(NineChess::PLAYER1); - score2++; chess_.score_2++; } else if (chess_.whosTurn() == NineChess::PLAYER2) { result = chess_.giveup(NineChess::PLAYER2); - score1++; - chess_.score_2++; + chess_.score_1++; } if (result) { @@ -1083,6 +1071,11 @@ bool GameController::updateScence(NineChess &chess) animationGroup->start(QAbstractAnimation::DeleteWhenStopped); + // 更新比分 LCD 显示 + emit score1Changed(QString::number(chess.score_1, 10)); + emit score2Changed(QString::number(chess.score_2, 10)); + emit scoreDrawChanged(QString::number(chess.score_draw, 10)); + return true; } diff --git a/NineChess/src/gamecontroller.h b/NineChess/src/gamecontroller.h index 81a9f0d2..07cefd8f 100644 --- a/NineChess/src/gamecontroller.h +++ b/NineChess/src/gamecontroller.h @@ -95,7 +95,16 @@ public: signals: - // 玩家1(先手)用时改变的信号 + // 玩家1(先手)赢盘数改变的信号 + void score1Changed(const QString &score); + + // 玩家2(后手)赢盘 数改变的信号 + void score2Changed(const QString &score); + + // 和棋数改变的信号 + void scoreDrawChanged(const QString &score); + + // 玩家1(先手)用时改变的信号 void time1Changed(const QString &time); // 玩家2(后手)用时改变的信号 @@ -236,12 +245,6 @@ private: // 玩家2剩余时间(毫秒) long remainingTime2; - // 玩家1赢盘数 - int score1; - - // 玩家2赢盘数 - int score2; - // 用于主窗口状态栏显示的字符串 QString message; diff --git a/NineChess/src/ninechesswindow.cpp b/NineChess/src/ninechesswindow.cpp index 99f2b0cb..fd726e9a 100644 --- a/NineChess/src/ninechesswindow.cpp +++ b/NineChess/src/ninechesswindow.cpp @@ -216,6 +216,18 @@ void NineChessWindow::initialize() // 关联控制器的信号和主窗口控件的槽 + // 更新LCD,显示玩家1赢盘数 + connect(game, SIGNAL(score1Changed(QString)), + ui.scoreLcdNumber_1, SLOT(display(QString))); + + // 更新LCD,显示玩家2赢盘数 + connect(game, SIGNAL(score2Changed(QString)), + ui.scoreLcdNumber_2, SLOT(display(QString))); + + // 更新LCD,显示和棋数 + connect(game, SIGNAL(scoreDrawChanged(QString)), + ui.scoreLcdNumber_draw, SLOT(display(QString))); + // 更新LCD1,显示玩家1用时 connect(game, SIGNAL(time1Changed(QString)), ui.lcdNumber_1, SLOT(display(QString)));