-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5c83ae
commit a773f25
Showing
7 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
MarioDungeon_performance_test/MarioDungeon_performance_test.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "widget.h" | ||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
Widget w; | ||
w.show(); | ||
|
||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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;i<playerNum;++i) | ||
{ | ||
Name_arr[i]=("测试"+QString::number(i)); | ||
PassWord_arr[i]=("ceshi"+QString::number(i)); | ||
} | ||
for(int i=0;i<playerNum;++i) | ||
{ | ||
QString msg = REGISTER; | ||
msg += Name_arr[i] + '\t' + PassWord_arr[i]; | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); | ||
if(length != msg.toUtf8().length()) | ||
return; | ||
} | ||
} | ||
void Test::Login() | ||
{ | ||
for(int i=0;i<playerNum;++i) | ||
{ | ||
QString msg=LOGIN; | ||
msg += Name_arr[i] + '\t' + PassWord_arr[i]; | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); | ||
if(length != msg.toUtf8().length()) | ||
return; | ||
} | ||
} | ||
void Test::CreateRoom() | ||
{ | ||
for(int i=0;i<Room_Num;++i) | ||
RoomName_arr[i]=("测试"+QString::number(i)); | ||
for(int i=0;i<Room_Num;++i) | ||
{ | ||
QString msg = CREATEROOM; | ||
msg+=RoomName_arr[i]+'\t'+Name_arr[2*i]; | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); | ||
if(length != msg.toUtf8().length()) | ||
return; | ||
} | ||
} | ||
void Test::EnterRoom() | ||
{ | ||
for(int i=0;i<Room_Num;++i) | ||
{ | ||
QString msg = ENTERROOM; | ||
msg+=RoomName_arr[i]+'\t'+Name_arr[2*i]; | ||
msg+=ENDFLAG; | ||
msg+= ENTERROOM; | ||
msg+=RoomName_arr[i]+'\t'+Name_arr[2*i+1]; | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); | ||
if(length != msg.toUtf8().length()) | ||
return; | ||
} | ||
} | ||
void Test::ReadyToPlay() | ||
{ | ||
for(int i=0;i<Room_Num;++i) | ||
{ | ||
QString msg = READYRQ; | ||
msg+=Name_arr[2*i+1]+'\t'+RoomName_arr[i]+'\t'+"ready"; | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); | ||
if(length != msg.toUtf8().length()) | ||
return; | ||
} | ||
} | ||
void Test::GameStart() | ||
{ | ||
for(int i=0;i<Room_Num;++i) | ||
{ | ||
QString msg = STARTRQ; | ||
msg+=Name_arr[2*i]+'\t'+RoomName_arr[i]; | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); | ||
if(length != msg.toUtf8().length()) | ||
return; | ||
} | ||
} | ||
void Test::MapRequest() | ||
{ | ||
for(int i=0;i<playerNum;++i) | ||
{ | ||
QString msg = MAPRQ; | ||
msg+=Name_arr[i]; | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length()); | ||
if(length != msg.toUtf8().length()) | ||
return; | ||
} | ||
} | ||
void Test::udpkPosRequest() | ||
{ | ||
qDebug()<<"this is run"; | ||
for(int i=0;i<playerNum;++i) | ||
{ | ||
QString msg = UDPKPOSRQ; | ||
msg+=Name_arr[i]+'\t'+QString::number(5)+'#'+QString::number(5)+'\t'+QString::number(2); | ||
msg+=ENDFLAG; | ||
int length = tcpSocket->write(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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef TEST_H | ||
#define TEST_H | ||
|
||
#include <QHostAddress> | ||
#include <QTcpSocket> | ||
#include <QString> | ||
#include <QTimer> | ||
#include <QWidget> | ||
#include <QDebug> | ||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef WIDGET_H | ||
#define WIDGET_H | ||
|
||
#include <QWidget> | ||
#include <QLineEdit> | ||
#include <QPushButton> | ||
#include <QLabel> | ||
#include <QGridLayout> | ||
#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 |