From a773f25c78c1d2a01d41ac4b8f9e5cdba385aa6f Mon Sep 17 00:00:00 2001 From: Realself-Ma <52282764+Realself-Ma@users.noreply.github.com> Date: Fri, 6 Nov 2020 19:02:26 +0800 Subject: [PATCH] =?UTF-8?q?[add]=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MarioDungeon_performance_test.pro | 24 +++ MarioDungeon_performance_test/main.cpp | 11 ++ MarioDungeon_performance_test/request.h | 27 ++++ MarioDungeon_performance_test/test.cpp | 150 ++++++++++++++++++ MarioDungeon_performance_test/test.h | 39 +++++ MarioDungeon_performance_test/widget.cpp | 50 ++++++ MarioDungeon_performance_test/widget.h | 33 ++++ 7 files changed, 334 insertions(+) create mode 100644 MarioDungeon_performance_test/MarioDungeon_performance_test.pro create mode 100644 MarioDungeon_performance_test/main.cpp create mode 100644 MarioDungeon_performance_test/request.h create mode 100644 MarioDungeon_performance_test/test.cpp create mode 100644 MarioDungeon_performance_test/test.h create mode 100644 MarioDungeon_performance_test/widget.cpp create mode 100644 MarioDungeon_performance_test/widget.h diff --git a/MarioDungeon_performance_test/MarioDungeon_performance_test.pro b/MarioDungeon_performance_test/MarioDungeon_performance_test.pro new file mode 100644 index 0000000..dddcb8e --- /dev/null +++ b/MarioDungeon_performance_test/MarioDungeon_performance_test.pro @@ -0,0 +1,24 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2020-11-03T19:56:26 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = MarioDungeon_performance_test +TEMPLATE = app + + +SOURCES += main.cpp\ + widget.cpp \ + test.cpp + +HEADERS += widget.h \ + test.h \ + request.h + +FORMS += +QT += network diff --git a/MarioDungeon_performance_test/main.cpp b/MarioDungeon_performance_test/main.cpp new file mode 100644 index 0000000..4d6c97b --- /dev/null +++ b/MarioDungeon_performance_test/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + + return a.exec(); +} diff --git a/MarioDungeon_performance_test/request.h b/MarioDungeon_performance_test/request.h new file mode 100644 index 0000000..c77cdb6 --- /dev/null +++ b/MarioDungeon_performance_test/request.h @@ -0,0 +1,27 @@ +#ifndef REQUEST_H +#define REQUEST_H + +#define SERVER_IP "121.36.20.9" +#define SERVER_PORT 2021 +#define ENDFLAG '-' +#define REGISTER "REG" +#define LOGIN "LOG" +#define FLUSHROOMLIST "FRL" +#define CREATEROOM "CRO" +#define DELETEROOM "DRO" +#define ENTERROOM "ERO" +#define LEAVEROOM "LRO" +#define MESSAGE "MES" +#define STARTRQ "SRQ" +#define READYRQ "RRQ" +#define MAPRQ "MRQ" +#define PKRQ "PRQ" +#define UDPKPOSRQ "URQ" +#define UDPKSTATUSRQ "USQ" +#define FIGHTRQ "FRQ" +#define GAMEOVERRQ "GRQ" +#define INITREQDYRQ "IRQ" +#define INITPLAYERRQ "YRQ" +#define OFFLINERQ "ORQ" +#define TRUNCATETABLERQ "TRQ" +#endif // REQUEST_H diff --git a/MarioDungeon_performance_test/test.cpp b/MarioDungeon_performance_test/test.cpp new file mode 100644 index 0000000..1e1b1fd --- /dev/null +++ b/MarioDungeon_performance_test/test.cpp @@ -0,0 +1,150 @@ +#include "test.h" + +Test::Test(QWidget *parent):QWidget(parent) +{ + tcpSocket=new QTcpSocket(); + updatePosTimer=new QTimer(); + ConnectToHost(SERVER_IP,SERVER_PORT); + connect(updatePosTimer,SIGNAL(timeout()),this,SLOT(udpkPosRequest())); +} +void Test::Run_Test() +{ + GenStringArray(); + Register(); + Login(); + CreateRoom(); + EnterRoom(); + ReadyToPlay(); + GameStart(); + MapRequest(); + //udpkPosRequest(); +} +void Test::ConnectToHost(QString ServerIp,int ServerPort) +{ + QHostAddress* serverIP = new QHostAddress(); + QString ip = ServerIp; + serverIP->setAddress(ip); + tcpSocket->connectToHost(*serverIP, ServerPort); +} +void Test::GenStringArray() +{ + playerNum=Room_Num*2; + Name_arr=new QString[playerNum]; + PassWord_arr=new QString[playerNum]; + RoomName_arr=new QString[Room_Num]; +} +void Test::Register() +{ + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::Login() +{ + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::CreateRoom() +{ + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::EnterRoom() +{ + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::ReadyToPlay() +{ + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::GameStart() +{ + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::MapRequest() +{ + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::udpkPosRequest() +{ + qDebug()<<"this is run"; + for(int i=0;iwrite(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; + } +} +void Test::TruncateTable() +{ + QString msg = TRUNCATETABLERQ; + msg+=ENDFLAG; + int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); + if(length != msg.toUtf8().length()) + return; +} diff --git a/MarioDungeon_performance_test/test.h b/MarioDungeon_performance_test/test.h new file mode 100644 index 0000000..f311323 --- /dev/null +++ b/MarioDungeon_performance_test/test.h @@ -0,0 +1,39 @@ +#ifndef TEST_H +#define TEST_H + +#include +#include +#include +#include +#include +#include +#include "request.h" +extern int Room_Num; +class Test: public QWidget +{ + Q_OBJECT +public: + Test(QWidget *parent = 0); + void Run_Test(); + void TruncateTable(); + QTimer* updatePosTimer; +private: + QTcpSocket* tcpSocket; + QString *Name_arr; + QString *PassWord_arr; + QString *RoomName_arr; + int playerNum; + void ConnectToHost(QString ServerIp,int ServerPort); + void GenStringArray(); + void Register(); + void Login(); + void CreateRoom(); + void EnterRoom(); + void ReadyToPlay(); + void GameStart(); + void MapRequest(); +private slots: + void udpkPosRequest(); +}; + +#endif // TEST_H diff --git a/MarioDungeon_performance_test/widget.cpp b/MarioDungeon_performance_test/widget.cpp new file mode 100644 index 0000000..db855e0 --- /dev/null +++ b/MarioDungeon_performance_test/widget.cpp @@ -0,0 +1,50 @@ +#include "widget.h" +#include "ui_widget.h" + +int Room_Num=0; +Widget::Widget(QWidget *parent) : + QWidget(parent) +{ + this->resize(400,200); + m_gLayout=new QGridLayout(this); + m_label=new QLabel("房间数:"); + Go_Test=new QPushButton("开始测试"); + End_Test=new QPushButton("结束测试"); + Go_Pk=new QPushButton("开始PK"); + End_Pk=new QPushButton("结束PK"); + m_edit=new QLineEdit(this); + m_gLayout->addWidget(m_label,0,0); + m_gLayout->addWidget(m_edit,0,1,1,3); + m_gLayout->addWidget(Go_Test,1,0); + m_gLayout->addWidget(Go_Pk,1,1); + m_gLayout->addWidget(End_Pk,1,2); + m_gLayout->addWidget(End_Test,1,3); + this->setLayout(m_gLayout); + connect(Go_Test,SIGNAL(clicked(bool)),this,SLOT(go_test())); + connect(End_Test,SIGNAL(clicked(bool)),this,SLOT(end_test())); + connect(Go_Pk,SIGNAL(clicked(bool)),this,SLOT(go_pk())); + connect(End_Pk,SIGNAL(clicked(bool)),this,SLOT(end_pk())); + test=new Test(); +} + +Widget::~Widget() +{ + +} +void Widget::go_test() +{ + Room_Num=m_edit->text().toInt(); + test->Run_Test(); +} +void Widget::go_pk() +{ + test->updatePosTimer->start(1000); +} +void Widget::end_pk() +{ + test->updatePosTimer->stop(); +} +void Widget::end_test() +{ + test->TruncateTable(); +} diff --git a/MarioDungeon_performance_test/widget.h b/MarioDungeon_performance_test/widget.h new file mode 100644 index 0000000..fd2291a --- /dev/null +++ b/MarioDungeon_performance_test/widget.h @@ -0,0 +1,33 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include +#include +#include +#include "test.h" +class Widget : public QWidget +{ + Q_OBJECT + +public: + explicit Widget(QWidget *parent = 0); + ~Widget(); +private: + QLabel* m_label; + QPushButton* Go_Test; + QPushButton* Go_Pk; + QPushButton* End_Pk; + QPushButton* End_Test; + QLineEdit* m_edit; + QGridLayout* m_gLayout; + Test* test; +private slots: + void go_test(); + void end_test(); + void go_pk(); + void end_pk(); +}; + +#endif // WIDGET_H