diff --git a/FiveChess.cpp b/FiveChess.cpp index 89380eb..371c211 100644 --- a/FiveChess.cpp +++ b/FiveChess.cpp @@ -2,6 +2,7 @@ #include "ui_FiveChess.h" #include "battlegui.h" #include "waitdialog.h" +#include FiveChess::FiveChess(QWidget *parent) : QMainWindow(parent), @@ -27,9 +28,19 @@ void FiveChess::newFiveChessGame() void FiveChess::loadFiveChessGame() { - //chessBoardData.loadBoard(); - //newFiveChessGame(); - waitDialog *waitDialogWindow=new waitDialog(nullptr); - waitDialogWindow->setModal(true); - waitDialogWindow->show(); + if(chessBoardData->loadBoard()) + { + chessBoardData->opt=chessBoardData_Process::chess; + qDebug()<<"OK!"<setModal(true); + waitDialogWindow->show();*/ + } +} + +void FiveChess::setData(chessBoardData_Process *data) +{ + this->chessBoardData=data; + qDebug()<<"SetData0!"<chessBoardData=data;} + chessBoardData_Process *chessBoardData; + void setData(chessBoardData_Process*data); }; #endif // FIVECHESS_H diff --git a/battlegui.cpp b/battlegui.cpp index 4818d1f..c95e74d 100644 --- a/battlegui.cpp +++ b/battlegui.cpp @@ -1,22 +1,24 @@ #include "battlegui.h" #include "ui_battlegui.h" +#include battleGui::battleGui(QWidget *parent) : QWidget(parent), ui(new Ui::battleGui), timer(new QTimer) { + qDebug()<<"OK2"<setupUi(this); time=0; - ui->frame->setData(chessBoardData); timer->start(1000); + connect(ui->pushButtonSave,ui->pushButtonSave->clicked,this,[&]{ - ui->frame->chessBoardData.saveBoard(); + ui->frame->chessBoardData->saveBoard(); }); connect(timer,timer->timeout,this,[&]{ time++; ui->labelTime->setText(tr("时间:%1秒").arg(time)); - }); + });qDebug()<<"OK3"<chessBoardData=data; + qDebug()<<"SetData!1"<frame->setData(chessBoardData); +} + diff --git a/battlegui.h b/battlegui.h index 9bd8be0..832fa84 100644 --- a/battlegui.h +++ b/battlegui.h @@ -23,8 +23,8 @@ class battleGui : public QWidget QTimer *timer; int time; public : - chessBoardData_Process chessBoardData; - void setData(chessBoardData_Process&data){this->chessBoardData=data;} + chessBoardData_Process *chessBoardData; + void setData(chessBoardData_Process*data); }; #endif // BATTLEGUI_H diff --git a/chessboarddata_process.cpp b/chessboarddata_process.cpp index 458c883..07651e0 100644 --- a/chessboarddata_process.cpp +++ b/chessboarddata_process.cpp @@ -8,7 +8,9 @@ chessBoardData_Process::chessBoardData_Process() { - clear(); + clearData(); + opt=chessBoardData_Process::onlyChessBoard; + flg=0; qDebug()<<"none:"<setupUi(this); - flg=0; } chessBoardGui::~chessBoardGui() @@ -22,31 +20,32 @@ chessBoardGui::~chessBoardGui() void chessBoardGui::paintEvent(QPaintEvent *) { - chessBoardData.dataPrint(); + chessBoardData_Process::optType& opt=(chessBoardData->opt); + chessBoardData->dataPrint(); auto f=[&]{parentWidget()->close();}; qDebug()<<"OK1"<data[i][j]==chessBoardData_Process::black) painter.drawImage(QRect(i*35+7,j*35+7,30,30),QImage(":/img/Resources/black.png")); - if (chessBoardData.data[i][j]==chessBoardData_Process::white) + if (chessBoardData->data[i][j]==chessBoardData_Process::white) painter.drawImage(QRect(i*35+7,j*35+7,30,30),QImage(":/img/Resources/white.png")); } } @@ -55,22 +54,24 @@ void chessBoardGui::paintEvent(QPaintEvent *) void chessBoardGui::mousePressEvent(QMouseEvent *event) { + chessBoardData_Process::optType& opt=chessBoardData->opt; + int& flg=chessBoardData->flg; if (event->button() == Qt::LeftButton){ mouseOffset=event->globalPos() - pos()-parentWidget()->pos()-QPoint(30,54); } qDebug()<<(mouseOffset.x())<<" "<<(mouseOffset.y())<data[tx][ty]==chessBoardData_Process::none){ + chessBoardData->data[tx][ty]=flg?chessBoardData_Process::white:chessBoardData_Process::black; + opt=chessBoardData_Process::chess; + if (chessBoardData->searchWin(flg?chessBoardData_Process::white:chessBoardData_Process::black)) { - if (flg){opt=whiteWin;} - else {opt=blackWin;} + if (flg){opt=chessBoardData_Process::whiteWin;} + else {opt=chessBoardData_Process::blackWin;} } repaint(); + flg^=1; } } @@ -78,3 +79,9 @@ void chessBoardGui::mouseReleaseEvent(QMouseEvent *event) { Q_UNUSED(event); } + +void chessBoardGui::setData(chessBoardData_Process *data) +{ + this->chessBoardData=data; + qDebug()<<"SetData!2"<chessBoardData=data;} + chessBoardData_Process *chessBoardData; + void setData(chessBoardData_Process *data); }; #endif // CHESSBOARDGUI_H diff --git a/main.cpp b/main.cpp index 56f31d8..be86179 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); FiveChess w; chessBoardData_Process data=chessBoardData_Process(); - w.setData(data); + w.setData(&data); w.show(); return a.exec();