Skip to content

Commit

Permalink
Merge branch 'release/v1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
alphagocc committed Jan 24, 2018
2 parents 2e5c4c9 + afd5539 commit 921a317
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 40 deletions.
21 changes: 16 additions & 5 deletions FiveChess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_FiveChess.h"
#include "battlegui.h"
#include "waitdialog.h"
#include <QDebug>

FiveChess::FiveChess(QWidget *parent) :
QMainWindow(parent),
Expand All @@ -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!"<<endl;
newFiveChessGame();
/*waitDialog *waitDialogWindow=new waitDialog(nullptr);
waitDialogWindow->setModal(true);
waitDialogWindow->show();*/
}
}

void FiveChess::setData(chessBoardData_Process *data)
{
this->chessBoardData=data;
qDebug()<<"SetData0!"<<data<<endl;
}
4 changes: 2 additions & 2 deletions FiveChess.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public slots:
void newFiveChessGame();
void loadFiveChessGame();
public :
chessBoardData_Process chessBoardData;
void setData(chessBoardData_Process&data){this->chessBoardData=data;}
chessBoardData_Process *chessBoardData;
void setData(chessBoardData_Process*data);
};

#endif // FIVECHESS_H
15 changes: 12 additions & 3 deletions battlegui.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#include "battlegui.h"
#include "ui_battlegui.h"
#include <QDebug>

battleGui::battleGui(QWidget *parent) :
QWidget(parent),
ui(new Ui::battleGui),
timer(new QTimer)
{
qDebug()<<"OK2"<<endl;
ui->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"<<endl;
}

battleGui::~battleGui()
Expand All @@ -31,5 +33,12 @@ bool battleGui::close()
return true;
}

void battleGui::setData(chessBoardData_Process *data)
{
this->chessBoardData=data;
qDebug()<<"SetData!1"<<data<<endl;
ui->frame->setData(chessBoardData);
}



4 changes: 2 additions & 2 deletions battlegui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions chessboarddata_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

chessBoardData_Process::chessBoardData_Process()
{
clear();
clearData();
opt=chessBoardData_Process::onlyChessBoard;
flg=0;
qDebug()<<"none:"<<none<<"black:"<<black<<"white:"<<white<<endl;
}

Expand All @@ -23,7 +25,7 @@ void chessBoardData_Process::dataPrint()
}
}

void chessBoardData_Process::clear()
void chessBoardData_Process::clearData()
{
FOR(i,0,15)
FOR(j,0,15)
Expand Down
9 changes: 8 additions & 1 deletion chessboarddata_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ class chessBoardData_Process
white = 0x00000001,
black = 0x00000002
};
int flg;
enum optType{
onlyChessBoard = 0x00000000,
chess = 0x00000001,
blackWin = 0x00000002,
whiteWin = 0x00000004
}opt;
dataType data[15][15];
void dataPrint();
void clear();
void clearData();
bool searchWin(dataType chess);
bool saveBoard();
bool loadBoard();
Expand Down
37 changes: 22 additions & 15 deletions chessboardgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ chessBoardGui::chessBoardGui(QWidget *parent) :
QFrame(parent),
ui(new Ui::chessBoardGui)
{
opt=onlyChessBoard;
ui->setupUi(this);
flg=0;
}

chessBoardGui::~chessBoardGui()
Expand All @@ -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"<<endl;
QPainter painter;
painter.begin(this);
painter.drawImage(QPoint(0,0),QImage(":/img/Resources/chessboard.jpg"));
if (opt==blackWin)
if (opt==chessBoardData_Process::blackWin)
{
painter.drawImage(QRect(535/2-200,535/2-60,400,120),QImage(":/img/Resources/blackwin.JPG"));
QTimer::singleShot(2000,this,f);
}
if (opt==whiteWin)
if (opt==chessBoardData_Process::whiteWin)
{
painter.drawImage(QRect(535/2-200,535/2-60,400,120),QImage(":/img/Resources/whitewin.JPG"));
QTimer::singleShot(2000,this,f);
}
qDebug()<<"OK2"<<endl;
if (opt==chess){
if (opt==chessBoardData_Process::chess){
for (int i=0;i<15;i++)
for (int j=0;j<15;j++)
{
//qDebug()<<"i:"<<i<<"j:"<<j<<"data:"<<chessBoardData.data[i][j]<<endl;
if (chessBoardData.data[i][j]==chessBoardData_Process::black)
if (chessBoardData->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"));
}
}
Expand All @@ -55,26 +54,34 @@ 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())<<endl;
int tx=(mouseOffset.x()+17)/35,ty=(mouseOffset.y()+17)/35;
qDebug()<<tx<<" "<<ty<<endl;
if (chessBoardData.data[tx][ty]==chessBoardData_Process::none){
chessBoardData.data[tx][ty]=flg?chessBoardData_Process::white:chessBoardData_Process::black;
flg^=1;
opt=chess;
if (chessBoardData.searchWin(flg?chessBoardData_Process::white:chessBoardData_Process::black))
if (chessBoardData->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;
}
}

void chessBoardGui::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
}

void chessBoardGui::setData(chessBoardData_Process *data)
{
this->chessBoardData=data;
qDebug()<<"SetData!2"<<data<<endl;
}
11 changes: 2 additions & 9 deletions chessboardgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,14 @@ class chessBoardGui : public QFrame
private:
Ui::chessBoardGui *ui;
QPoint mouseOffset;
int flg;
enum optType{
onlyChessBoard = 0x00000000,
chess = 0x00000001,
blackWin = 0x00000002,
whiteWin = 0x00000004
}opt;

protected :
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
public :
chessBoardData_Process chessBoardData;
void setData(chessBoardData_Process&data){this->chessBoardData=data;}
chessBoardData_Process *chessBoardData;
void setData(chessBoardData_Process *data);
};

#endif // CHESSBOARDGUI_H
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 921a317

Please sign in to comment.