-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
136 lines (99 loc) · 3.25 KB
/
Copy pathwidget.cpp
File metadata and controls
136 lines (99 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setWindowTitle("五子棋v1.12.0");
ChessAI::beforeStart();
board = new Board;
connect(board, &Board::goBackStart, this, [=](){
this->show();
board->hide();
});
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_pve_clicked()
{
/// TODO
Widget::openGame("", true);
}
void Widget::on_pvp_clicked()
{
/// Widget::openGameBoard();
Widget::openGame("", false);
}
void Widget::receiveStringSlot(const QString &receivedString)
{
// 在这里对接收到的字符串进行处理
qDebug() << "接收到的文件名:" << receivedString;
Widget::openGame(receivedString.toStdString().append(".data"), false);
}
/// 准备载入残局
/// TODO
void Widget::on_load_clicked()
{
std::vector<std::string> filelist = fileutils::readFileList(".", ".data");
if (filelist.empty()) {
/// 找不到可行的棋局
/// 提示
QString dialtitle = "prompt";
QString strInfo = "没有找到可选择的对局文件,是否新建一个对局";
QMessageBox::StandardButton result=QMessageBox::question(this, dialtitle, strInfo,
QMessageBox::Yes|QMessageBox::No );
if (result == QMessageBox::Yes) {
/// TODO AI对局打开后按AI走
Widget::openGame("", false);
} else {
/// TODO
}
} else {
// 创建并显示新窗口
fileopenboard = new fileOpenUI(filelist);
fileopenboard->show();
connect(fileopenboard, &fileOpenUI::sendStringSignal, this, &Widget::receiveStringSlot);
}
}
void Widget::openGame(std::string oldfiles, bool isPVE){
if (oldfiles.size() > 0) {
board->openGameFile(oldfiles);
} else {
delete board;
board = new Board();
connect(board, &Board::goBackStart, this, [=](){
this->show();
board->hide();
});
if (isPVE) {
/// 提示
// QString dialtitle = "prompt";
// QString strInfo = "请选择谁执黑";
// qDebug() << "试图让玩家选择谁;来执黑";
// // 显示消息框并获取用户点击的结果
// QMessageBox::StandardButton result=QMessageBox::question(this, dialtitle, strInfo,
// QMessageBox::Yes|QMessageBox::No );
// // 根据用户点击的结果进行后续处理,这里简单示例,可按需扩展
// if (result == QMessageBox::Yes)
// {
// board->useAIMode(Board::Mode::ComputerWhite);
// qDebug() << "玩家选择自己黑";
// }
// else
// {
// board->useAIMode(Board::Mode::ComputerBlack);
// qDebug() << "玩家选择AI 黑";
// }
qDebug() << "玩家选择 AI白色";
board->useAIMode(Board::Mode::ComputerWhite);
}
}
Widget::openGameBoard();
}
void Widget::openGameBoard() {
this->hide();
board->show();
}