UI: 界面上增加胜率显示 (万分之几)

This commit is contained in:
Calcitem 2019-12-08 19:39:53 +08:00
parent ce6d9c2f2f
commit 0b4366b289
4 changed files with 110 additions and 1 deletions

View File

@ -635,6 +635,67 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="labelWinningRate">
<property name="font">
<font>
<family>黑体</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>胜率:</string>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="winningRateLcdNumber_1">
<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>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="winningRateLcdNumber_2">
<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>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLCDNumber" name="winningRateLcdNumber_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>5</number>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>

View File

@ -254,6 +254,19 @@ void GameController::gameReset()
emit score2Changed(QString::number(game.score[WHITE], 10)); emit score2Changed(QString::number(game.score[WHITE], 10));
emit scoreDrawChanged(QString::number(game.score_draw, 10)); emit scoreDrawChanged(QString::number(game.score_draw, 10));
// 更新胜率 LCD 显示
int scoreSum = game.score[BLACK] + game.score[WHITE] + game.score_draw;
int winningRate_1 = 0, winningRate_2 = 0, winningRate_draw = 0;
if (scoreSum != 0) {
winningRate_1 = game.score[BLACK] * 10000 / scoreSum;
winningRate_2 = game.score[WHITE] * 10000 / scoreSum;
winningRate_draw = game.score_draw * 10000 / scoreSum;
}
emit winningRate1Changed(QString::number(winningRate_1, 10));
emit winningRate2Changed(QString::number(winningRate_2, 10));
emit winningRateDrawChanged(QString::number(winningRate_draw, 10));
// 播放音效 // 播放音效
//playSound(":/sound/resources/sound/newgame.wav"); //playSound(":/sound/resources/sound/newgame.wav");
#endif // TRAINING_MODE #endif // TRAINING_MODE
@ -1123,6 +1136,20 @@ bool GameController::updateScence(Game &g)
emit score1Changed(QString::number(g.score[BLACK], 10)); emit score1Changed(QString::number(g.score[BLACK], 10));
emit score2Changed(QString::number(g.score[WHITE], 10)); emit score2Changed(QString::number(g.score[WHITE], 10));
emit scoreDrawChanged(QString::number(g.score_draw, 10)); emit scoreDrawChanged(QString::number(g.score_draw, 10));
// 更新胜率 LCD 显示
int scoreSum = game.score[BLACK] + game.score[WHITE] + game.score_draw;
int winningRate_1 = 0, winningRate_2 = 0, winningRate_draw = 0;
if (scoreSum != 0) {
winningRate_1 = game.score[BLACK] * 10000 / scoreSum;
winningRate_2 = game.score[WHITE] * 10000 / scoreSum;
winningRate_draw = game.score_draw * 10000 / scoreSum;
}
emit winningRate1Changed(QString::number(winningRate_1, 10));
emit winningRate2Changed(QString::number(winningRate_2, 10));
emit winningRateDrawChanged(QString::number(winningRate_draw, 10));
#endif TRAINING_MODE #endif TRAINING_MODE
return true; return true;
} }

View File

@ -105,12 +105,21 @@ signals:
// 玩家1(先手)赢盘数改变的信号 // 玩家1(先手)赢盘数改变的信号
void score1Changed(const QString &score); void score1Changed(const QString &score);
// 玩家2(后手)赢盘 数改变的信号 // 玩家2(后手)赢盘数改变的信号
void score2Changed(const QString &score); void score2Changed(const QString &score);
// 和棋数改变的信号 // 和棋数改变的信号
void scoreDrawChanged(const QString &score); void scoreDrawChanged(const QString &score);
// 玩家1(先手)胜率改变的信号
void winningRate1Changed(const QString &score);
// 玩家2(后手)胜率改变的信号
void winningRate2Changed(const QString &score);
// 和棋率改变的信号
void winningRateDrawChanged(const QString &score);
// 玩家1(先手)用时改变的信号 // 玩家1(先手)用时改变的信号
void time1Changed(const QString &time); void time1Changed(const QString &time);

View File

@ -253,6 +253,18 @@ void MillGameWindow::initialize()
connect(gameController, SIGNAL(scoreDrawChanged(QString)), connect(gameController, SIGNAL(scoreDrawChanged(QString)),
ui.scoreLcdNumber_draw, SLOT(display(QString))); ui.scoreLcdNumber_draw, SLOT(display(QString)));
// 更新LCD显示玩家1赢盘率
connect(gameController, SIGNAL(winningRate1Changed(QString)),
ui.winningRateLcdNumber_1, SLOT(display(QString)));
// 更新LCD显示玩家2赢盘率
connect(gameController, SIGNAL(winningRate2Changed(QString)),
ui.winningRateLcdNumber_2, SLOT(display(QString)));
// 更新LCD显示和棋率
connect(gameController, SIGNAL(winningRateDrawChanged(QString)),
ui.winningRateLcdNumber_draw, SLOT(display(QString)));
// 更新LCD1显示玩家1用时 // 更新LCD1显示玩家1用时
connect(gameController, SIGNAL(time1Changed(QString)), connect(gameController, SIGNAL(time1Changed(QString)),
ui.lcdNumber_1, SLOT(display(QString))); ui.lcdNumber_1, SLOT(display(QString)));