This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/SoftwareDesign/Lab5/lab5_2_gomoku/gamewidget.cpp
2022-05-31 17:21:56 +08:00

32 lines
795 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "gamewidget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QPushButton>
GameWidget::GameWidget(QWidget *parent)
: QWidget(parent)
{
setWindowTitle("五子棋");
boardWidget = new BoardWidget(this);
connect(boardWidget, &BoardWidget::gameOver, this, &GameWidget::showWinner);
}
GameWidget::~GameWidget()
{
}
void GameWidget::showWinner(int winner)
{
if (winner != 2)
{
QString playerName = (winner == BoardWidget::WHITE_PLAYER) ? "白方" : "黑方";
QMessageBox::information(this, "游戏结束", tr("恭喜%1获胜").arg(playerName), QMessageBox::Ok);
}
else
{
QMessageBox::information(this, "游戏结束", "和棋!", QMessageBox::Ok);
}
}