Skip to content

Commit

Permalink
NetworkGame OK!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
alphagocc committed May 4, 2019
1 parent 5451e1f commit d73d7b7
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 108 deletions.
6 changes: 5 additions & 1 deletion FiveChess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ void FiveChess::loadFiveChessGame()

void FiveChess::newNetworkFiveChessGame()
{
QDialog* chooseDialog = new QDialog(this);
NetworkSettingDialog settingDialog;
settingDialog.exec();

QDialog* chooseDialog = new QDialog(this);
Ui::ChooseCorSDialog* chooseDialogUi = new Ui::ChooseCorSDialog;
chooseDialogUi->setupUi(chooseDialog);

Expand All @@ -66,6 +69,7 @@ void FiveChess::newNetworkFiveChessGame()
chooseDialog->close();
});
chooseDialog->exec();

newFiveChessGame();
}

Expand Down
6 changes: 4 additions & 2 deletions FiveChess.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ SOURCES += \
networksettingdialog.cpp \
serverthread.cpp \
clientthread.cpp \
chessboardcore.cpp
chessboardcore.cpp \
networksettings.cpp

HEADERS += \
battlegui.h \
Expand All @@ -42,7 +43,8 @@ HEADERS += \
networksettingdialog.h \
serverthread.h \
clientthread.h \
chessboardcore.h
chessboardcore.h \
networksettings.h

FORMS += \
battlegui.ui \
Expand Down
26 changes: 19 additions & 7 deletions FiveChess.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">release\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">release\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Platform)\$(Configuration)\</IntDir>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">FiveChess</TargetName>
<IgnoreImportLibrary Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</IgnoreImportLibrary>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">debug\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">debug\</IntDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Platform)\$(Configuration)\</IntDir>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">FiveChess</TargetName>
<IgnoreImportLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</IgnoreImportLibrary>
</PropertyGroup>
Expand All @@ -74,12 +74,11 @@
<DebugInformationFormat>None</DebugInformationFormat>
<DisableSpecificWarnings>4577;4467;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<ExceptionHandling>Sync</ExceptionHandling>
<ObjectFileName>release\</ObjectFileName>
<ObjectFileName>$(IntDir)</ObjectFileName>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>_WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QT_NO_DEBUG;QT_WIDGETS_LIB;QT_GUI_LIB;QT_NETWORK_LIB;QT_CORE_LIB;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessToFile>false</PreprocessToFile>
<ProgramDataBaseFileName>
</ProgramDataBaseFileName>
<ProgramDataBaseFileName>$(IntDir)vc$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<SuppressStartupBanner>true</SuppressStartupBanner>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
Expand Down Expand Up @@ -141,7 +140,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DisableSpecificWarnings>4577;4467;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<ExceptionHandling>Sync</ExceptionHandling>
<ObjectFileName>debug\</ObjectFileName>
<ObjectFileName>$(IntDir)</ObjectFileName>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QT_WIDGETS_LIB;QT_GUI_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessToFile>false</PreprocessToFile>
Expand All @@ -150,6 +149,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<WarningLevel>Level3</WarningLevel>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<ProgramDataBaseFileName>$(IntDir)vc$(PlatformToolsetVersion).pdb</ProgramDataBaseFileName>
</ClCompile>
<Link>
<AdditionalDependencies>$(QTDIR)\lib\Qt5Widgetsd.lib;$(QTDIR)\lib\Qt5Guid.lib;$(QTDIR)\lib\Qt5Networkd.lib;$(QTDIR)\lib\Qt5Cored.lib;$(QTDIR)\lib\qtmaind.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down Expand Up @@ -205,6 +205,7 @@
<ClCompile Include="main.cpp" />
<ClCompile Include="networksettingdialog.cpp" />
<ClCompile Include="serverthread.cpp" />
<ClCompile Include="networksettings.cpp" />
<ClCompile Include="waitdialog.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -218,7 +219,13 @@
</QtMoc>
<QtMoc Include="fivechess.h">
</QtMoc>
<ClInclude Include="networksettingdialog.h" />
<ClInclude Include="networksettings.h" />
<QtMoc Include="networksettingdialog.h">
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;.\debug;C:\VulkanSDK\1.0.51.0\include;$(QTDIR)\mkspecs\win32-msvc</IncludePath>
<Define Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">_WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QT_WIDGETS_LIB;QT_GUI_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions)</Define>
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;$(QTDIR)\include;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtCore;.\release;C:\VulkanSDK\1.0.51.0\include;$(QTDIR)\mkspecs\win32-msvc</IncludePath>
<Define Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">_WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QT_NO_DEBUG;QT_WIDGETS_LIB;QT_GUI_LIB;QT_NETWORK_LIB;QT_CORE_LIB;NDEBUG;%(PreprocessorDefinitions)</Define>
</QtMoc>
<QtMoc Include="serverthread.h">
</QtMoc>
<QtMoc Include="waitdialog.h">
Expand Down Expand Up @@ -294,4 +301,9 @@
<Import Project="$(QtMsBuild)\qt.targets" />
</ImportGroup>
<ImportGroup Label="ExtensionTargets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties Qt5Version_x0020_Win32="msvc2017" />
</VisualStudio>
</ProjectExtensions>
</Project>
14 changes: 10 additions & 4 deletions FiveChess.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
<ClCompile Include="networksettingdialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="networksettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="serverthread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -101,7 +104,7 @@
<QtMoc Include="fivechess.h">
<Filter>Header Files</Filter>
</QtMoc>
<ClInclude Include="networksettingdialog.h">
<ClInclude Include="networksettings.h">
<Filter>Header Files</Filter>
</ClInclude>
<QtMoc Include="serverthread.h">
Expand All @@ -110,6 +113,9 @@
<QtMoc Include="waitdialog.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="networksettingdialog.h">
<Filter>Generated Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">
Expand Down Expand Up @@ -152,13 +158,13 @@
<QtUic Include="chessboardgui.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="networksettingdialog.ui">
<QtUic Include="chooseCorS.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="waitdialog.ui">
<QtUic Include="networksettingdialog.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="chooseCorS.ui">
<QtUic Include="waitdialog.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
Expand Down
38 changes: 15 additions & 23 deletions battlegui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,31 @@
#include "ui_battlegui.h"
#include <QDebug>

battleGui::battleGui(QWidget *parent) :
QWidget(parent),
ui(new Ui::battleGui),
timer(new QTimer)
battleGui::battleGui(QWidget* parent)
: QWidget(parent), ui(new Ui::battleGui), timer(new QTimer)
{
qDebug()<<"OK2"<<endl;
qDebug() << "OK2" << endl;
ui->setupUi(this);
ui->labelTime->setText(tr("Time:%1 Second").arg(0));
ui->labelTime->setText(tr("Time:%1 Second").arg(0));
timer->start(1000);

connect(ui->pushButtonSave,&QPushButton::clicked,this,[]{
chessBoard.saveBoard();
});
connect(timer,&QTimer::timeout,this,[&]{
connect(ui->pushButtonSave, &QPushButton::clicked, this,
[] { chessBoard.saveBoard(); });
connect(timer, &QTimer::timeout, this, [&] {
chessBoard.addUsedTime();
ui->labelTime->setText(tr("Time:%1 Second").arg(chessBoard.getUsedTime()));
});
connect(&chessBoard, &ChessBoardCore::dataChanged, this, [&](int x, int y, ChessBoardCore::DataType d) {
ui->labelColor->setText(tr("Waiting:%1").arg(d == ChessBoardCore::DataType::black ? "White" : "Black"));
});
connect(&chessBoard, &ChessBoardCore::dataChanged, this,
[&](int x, int y, ChessBoardCore::DataType d) {
ui->labelColor->setText(tr("Waiting:%1").arg(d == ChessBoardCore::DataType::black ? tr("White") : tr("Black")));
});
}

battleGui::~battleGui()
{
delete ui;
}
battleGui::~battleGui() { delete ui; }

bool battleGui::close()
{
QWidget *p = parentWidget();
p->show();
return true;
QWidget* p = parentWidget();
p->show();
return true;
}



46 changes: 30 additions & 16 deletions chessBoardCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,28 @@ bool ChessBoardCore::searchWin(ChessBoardCore::DataType chess)
FOR(i, 0, 11)
FOR(j, 0, 15)
if (m_data[i][j] == chess && m_data[i + 1][j] == chess && m_data[i + 2][j] == chess &&
m_data[i + 3][j] == chess && m_data[i + 4][j] == chess) return true;
m_data[i + 3][j] == chess && m_data[i + 4][j] == chess)
return true;

FOR(i, 0, 15)
FOR(j, 0, 11)
if (m_data[i][j] == chess && m_data[i][j + 1] == chess && m_data[i][j + 2] == chess &&
m_data[i][j + 3] == chess && m_data[i][j + 4] == chess) return true;
m_data[i][j + 3] == chess && m_data[i][j + 4] == chess)
return true;

FOR(i, 0, 11)
FOR(j, 0, 11)
if (m_data[i][j] == chess && m_data[i + 1][j + 1] == chess &&
m_data[i + 2][j + 2] == chess && m_data[i + 3][j + 3] == chess &&
m_data[i + 4][j + 4] == chess) return true;
m_data[i + 4][j + 4] == chess)
return true;

FOR(i, 0, 11)
FOR(j, 4, 15)
if (m_data[i][j] == chess && m_data[i + 1][j - 1] == chess &&
m_data[i + 2][j - 2] == chess && m_data[i + 3][j - 3] == chess &&
m_data[i + 4][j - 4] == chess) return true;
m_data[i + 4][j - 4] == chess)
return true;

return false;
}
Expand All @@ -68,15 +72,19 @@ bool ChessBoardCore::saveBoard()
qDebug() << file.errorString() << endl;
return false;
}
file.write(QString("%1\n").arg(m_usedTime).toUtf8());
file.write(QString("%1\n").arg(m_flag).toUtf8());
QJsonObject jsonObj;
jsonObj.insert("usedTime", m_usedTime);
jsonObj.insert("flag", m_flag);
QString tempString;
FOR(i, 0, 15)
{
FOR(j, 0, 15)
{
file.write(QString("%1").arg(static_cast<int>(m_data[i][j])).toUtf8());
}
FOR(j, 0, 15) { tempString.append(static_cast<int>(m_data[i][j]) + 48); }
}
jsonObj.insert("chessBoard", tempString);
QJsonDocument jsonDoc;
jsonDoc.setObject(jsonObj);
qDebug() << jsonDoc.toJson();
file.write(jsonDoc.toJson());
file.close();
}
qDebug() << fileName << endl;
Expand All @@ -96,17 +104,23 @@ bool ChessBoardCore::loadBoard()
qDebug() << file.errorString() << endl;
return false;
}
m_usedTime = file.readLine().toInt();
m_flag = file.readLine().toInt();
QByteArray ba = file.readAll();
// qDebug() << ba;
QJsonDocument jsonDoc;
jsonDoc = QJsonDocument::fromJson(ba);
QJsonObject jsonObj = jsonDoc.object();
qDebug() << jsonDoc.toJson();
m_usedTime = jsonObj["usedTime"].toInt();
m_flag = jsonDoc["flag"].toInt();
qDebug() << m_usedTime;
qDebug() << m_flag;
QString tempStr;
tempStr = file.readLine();
QString tempStr = jsonObj["chessBoard"].toString();
FOR(i, 0, 15)
{
FOR(j, 0, 15)
{
int tempData = tempStr[j].toLatin1();
int tempData = tempStr[i * 15 + j].toLatin1();
qDebug() << tempData;
if (!std::isdigit(tempData))
{
file.close();
Expand All @@ -116,7 +130,7 @@ bool ChessBoardCore::loadBoard()
m_data[i][j] = static_cast<DataType>(tempData - 48);
}
}
dataPrint();
// dataPrint();
file.close();
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion clientthread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "clientthread.h"
#include "chessboardcore.h"
#include "networksettings.h"
#include <QDebug>

ClientThread* clientThread;
Expand All @@ -10,7 +11,10 @@ void ClientThread::run()
{
m_tcpSocket = new QTcpSocket();
m_tcpSocket->abort();
m_tcpSocket->connectToHost("127.0.0.1", 23333);
m_tcpSocket->connectToHost(networkSettings["host"].toString(),
networkSettings["port"].toInt());
qDebug() << networkSettings["host"].toString()
<< networkSettings["port"].toInt();
tcpSocketInit();
}

Expand Down
Loading

0 comments on commit d73d7b7

Please sign in to comment.