ui: 右侧信息栏显示比分

This commit is contained in:
CalciteM Team 2019-08-18 23:59:03 +08:00
parent 79effc7ec0
commit 0257824b6f
4 changed files with 112 additions and 31 deletions

View File

@ -23,7 +23,7 @@
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="GameView" name="gameView"> <widget class="GameView" name="gameView">
<property name="sizePolicy"> <property name="sizePolicy">
@ -57,7 +57,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>491</width> <width>491</width>
<height>22</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu_F"> <widget class="QMenu" name="menu_F">
@ -384,6 +384,79 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="labelScore">
<property name="font">
<font>
<family>黑体</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>比分:</string>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="scoreLcdNumber_1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="smallDecimalPoint">
<bool>false</bool>
</property>
<property name="digitCount">
<number>2</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="scoreLcdNumber_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="digitCount">
<number>2</number>
</property>
<property name="mode">
<enum>QLCDNumber::Dec</enum>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="scoreLcdNumber_draw">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="smallDecimalPoint">
<bool>false</bool>
</property>
<property name="digitCount">
<number>2</number>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>

View File

@ -53,9 +53,7 @@ GameController::GameController(GameScene & scene, QObject * parent) :
timeID(0), timeID(0),
ruleNo_(-1), ruleNo_(-1),
timeLimit(0), timeLimit(0),
stepsLimit(50), stepsLimit(50)
score1(-2),
score2(-2)
{ {
// 已在view的样式表中添加背景scene中不用添加背景 // 已在view的样式表中添加背景scene中不用添加背景
// 区别在于view中的背景不随视图变换而变换scene中的背景随视图变换而变换 // 区别在于view中的背景不随视图变换而变换scene中的背景随视图变换而变换
@ -133,16 +131,9 @@ void GameController::gameReset()
timeID = 0; timeID = 0;
// 棋未下完,则算对手得分 // 棋未下完,则算对手得分
if (score1 < 0 || score2 < 0) { if (chess_.getStage() == NineChess::GAME_MOVING &&
score1++; chess_.whoWin() == NineChess::NOBODY) {
score2++; giveUp();
}
else {
if (chess_.getStage() == NineChess::GAME_MOVING &&
chess_.whoWin() == NineChess::NOBODY)
{
giveUp();
}
} }
#ifdef LCD_SHOW_SCORE_INSTEAD_OF_TIME #ifdef LCD_SHOW_SCORE_INSTEAD_OF_TIME
@ -234,6 +225,11 @@ void GameController::gameReset()
message = QString::fromStdString(chess_.getTips()); message = QString::fromStdString(chess_.getTips());
emit statusBarChanged(message); 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"); //playSound(":/sound/resources/sound/newgame.wav");
} }
@ -561,12 +557,6 @@ void GameController::timerEvent(QTimerEvent *event)
// 弹框 // 弹框
//QMessageBox::about(NULL, "游戏结果", message); //QMessageBox::about(NULL, "游戏结果", message);
if (chess_.whoWin() == NineChess::PLAYER1) {
score1++;
} else if (chess_.whoWin() == NineChess::PLAYER2) {
score2++;
}
#ifdef LCD_SHOW_SCORE_INSTEAD_OF_TIME #ifdef LCD_SHOW_SCORE_INSTEAD_OF_TIME
emit time1Changed(QString::number(score1, 10)); emit time1Changed(QString::number(score1, 10));
emit time2Changed(QString::number(score2, 10)); emit time2Changed(QString::number(score2, 10));
@ -770,13 +760,11 @@ bool GameController::giveUp()
if (chess_.whosTurn() == NineChess::PLAYER1) { if (chess_.whosTurn() == NineChess::PLAYER1) {
result = chess_.giveup(NineChess::PLAYER1); result = chess_.giveup(NineChess::PLAYER1);
score2++;
chess_.score_2++; chess_.score_2++;
} }
else if (chess_.whosTurn() == NineChess::PLAYER2) { else if (chess_.whosTurn() == NineChess::PLAYER2) {
result = chess_.giveup(NineChess::PLAYER2); result = chess_.giveup(NineChess::PLAYER2);
score1++; chess_.score_1++;
chess_.score_2++;
} }
if (result) { if (result) {
@ -1083,6 +1071,11 @@ bool GameController::updateScence(NineChess &chess)
animationGroup->start(QAbstractAnimation::DeleteWhenStopped); 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; return true;
} }

View File

@ -95,7 +95,16 @@ public:
signals: 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); void time1Changed(const QString &time);
// 玩家2(后手)用时改变的信号 // 玩家2(后手)用时改变的信号
@ -236,12 +245,6 @@ private:
// 玩家2剩余时间毫秒 // 玩家2剩余时间毫秒
long remainingTime2; long remainingTime2;
// 玩家1赢盘数
int score1;
// 玩家2赢盘数
int score2;
// 用于主窗口状态栏显示的字符串 // 用于主窗口状态栏显示的字符串
QString message; QString message;

View File

@ -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用时 // 更新LCD1显示玩家1用时
connect(game, SIGNAL(time1Changed(QString)), connect(game, SIGNAL(time1Changed(QString)),
ui.lcdNumber_1, SLOT(display(QString))); ui.lcdNumber_1, SLOT(display(QString)));