Skip to content

Commit

Permalink
[fix]修复了一些BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
Realself-Ma authored Nov 3, 2020
1 parent 6b92750 commit e8adf30
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 15 deletions.
24 changes: 12 additions & 12 deletions chatroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,6 @@ void ChatRoom::GameOverRequest()
if(length != msg.toUtf8().length())
return;
}
void ChatRoom::initialPlayerRequest()
{
if(playerName!=owner_)
{
QString msg = INITPLAYERRQ;
msg+=playerName;
msg+=ENDFLAG;
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length());
if(length != msg.toUtf8().length())
return;
}
}
void ChatRoom::dataReceived()
{
QByteArray datagram;
Expand Down Expand Up @@ -250,3 +238,15 @@ void ChatRoom::showEvent(QShowEvent *)
if(playerName!=""&&owner_!=""&&playerName!=owner_)
initialReadyRquest();
}
void ChatRoom::closeEvent(QCloseEvent*)
{
//qDebug()<<"------------closeEvent------------";
//initialPlayerRequest();
//doOfflineRequest();
}
void ChatRoom::hideEvent(QHideEvent*)
{
//qDebug()<<"------------hideEvent------------";
//initialPlayerRequest();
//doOfflineRequest();
}
3 changes: 2 additions & 1 deletion chatroom.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class ChatRoom : public QWidget
void udpkStatusRequest(int hp, int atk, int def);
void FightRequest();
void GameOverRequest();
void initialPlayerRequest();
QString competitoName;
int cur_x;
int cur_y;
Expand All @@ -46,6 +45,8 @@ class ChatRoom : public QWidget
bool pkStartGet;
private:
void showEvent(QShowEvent *);
void closeEvent(QCloseEvent*);
void hideEvent(QHideEvent*);
void initialChatRoomWidget();
void mapRequest();
void initialReadyRquest();
Expand Down
7 changes: 6 additions & 1 deletion interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ void interface::Quit()
message.setButtonText(QMessageBox::No, QString("返 回"));
if(message.exec()==QMessageBox::Yes)
{
sign->roomWidget->chatRoom->initialPlayerRequest();
if(sign->roomWidget->isVisible())
{
//qDebug()<<"------------isVisible------------";
sign->roomWidget->initialPlayerRequest();
sign->roomWidget->doOfflineRequest();
}
QuitTimer->start(100);
}
else
Expand Down
2 changes: 1 addition & 1 deletion request.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
#define GAMEOVERRQ "GRQ"
#define INITREQDYRQ "IRQ"
#define INITPLAYERRQ "YRQ"

#define OFFLINERQ "ORQ"
#endif // REQUEST_H
32 changes: 32 additions & 0 deletions rooms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ void rooms::GameStart()
else
beReady();
}
void rooms::initialPlayerRequest()
{
if(playerName!=owner_)
{
QString msg = INITPLAYERRQ;
msg+=playerName;
msg+=ENDFLAG;
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length());
if(length != msg.toUtf8().length())
return;
}
}
void rooms::doOfflineRequest()
{
QString msg = OFFLINERQ;
msg+=playerName;
msg+=ENDFLAG;
int length = tcpSocket->write(msg.toUtf8(), msg.toUtf8().length());
if(length != msg.toUtf8().length())
return;
}
void rooms::dataReceived()
{
QByteArray datagram;
Expand Down Expand Up @@ -353,6 +374,11 @@ void rooms::dataReceived()
QMessageBox::information(this, "进入房间失败", "房主不能进入他人房间,可以删除自己的房间后进入");
return;
}
else if(msg=="room is full")
{
QMessageBox::information(this, "房间已满员", "房间已满员");
return;
}
else if(msg.mid(0,9)=="EnterRoom")
{
doEnterRoom();
Expand Down Expand Up @@ -416,3 +442,9 @@ void rooms::showEvent(QShowEvent *)
//qDebug()<<"flushRooms";
flushRoomList();
}
void rooms::closeEvent(QCloseEvent*)
{
//qDebug()<<"------------closeEvent------------";
initialPlayerRequest();
doOfflineRequest();
}
3 changes: 3 additions & 0 deletions rooms.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ class rooms: public QMainWindow
QString owner_;
ChatRoom* chatRoom;
QPushButton* startGameBtn;
void initialPlayerRequest();
void doOfflineRequest();
private:
void initialmainWidget();
void intialRoomPlayersWidget();
void initialRoomsListBtn();
void initialCreateroomDialog();
void showEvent(QShowEvent *);
void closeEvent(QCloseEvent*);
void flushRoomList();
void doEnterRoom();
void startRq();
Expand Down
4 changes: 4 additions & 0 deletions sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ void Sign::dataReceived()
{
QMessageBox::information(this, "The name has been registered", "The name has been registered");
}
else if(msg=="another client have Login this acount")
{
QMessageBox::information(this, "another client have Login this acount", "another client have Login this acount");
}
else
return;

Expand Down

0 comments on commit e8adf30

Please sign in to comment.