103 lines
2.1 KiB
C++
103 lines
2.1 KiB
C++
#include "gameclient.h"
|
|
|
|
GameClient::GameClient() : TcpClientEquipment()
|
|
{
|
|
|
|
}
|
|
|
|
bool GameClient::setValue(int iValue)
|
|
{
|
|
QByteArray buffer;
|
|
buffer.resize(0);
|
|
buffer[0]=static_cast<u_int8_t>(iValue%0xff);
|
|
buffer[1]=static_cast<u_int8_t>(iValue>>8);
|
|
return this->sendMsg(buffer);
|
|
}
|
|
|
|
bool GameClient::IsReady()
|
|
{
|
|
return IsReady();
|
|
}
|
|
|
|
void GameClient::sendReady()
|
|
{
|
|
sendMsg(readyCheckString);
|
|
}
|
|
|
|
void GameClient::sendStart()
|
|
{
|
|
sendMsg(gameStartString);
|
|
}
|
|
|
|
void GameClient::sendStop()
|
|
{
|
|
sendMsg(gameStopString);
|
|
}
|
|
|
|
void GameClient::sendLevelHard()
|
|
{
|
|
sendMsg(gameLevelHard);
|
|
}
|
|
|
|
void GameClient::sendLevelMiddle()
|
|
{
|
|
sendMsg(gameLevelMiddle);
|
|
}
|
|
|
|
void GameClient::sendLevelEasy()
|
|
{
|
|
sendMsg(gameLevelEasy);
|
|
}
|
|
|
|
void GameClient::sendScore(int iValue)
|
|
{
|
|
sendMsg(gameScore+"|"+QString::number(iValue));
|
|
}
|
|
|
|
void GameClient::onDataReceived()
|
|
{
|
|
QByteArray revBuffer=this->mClient->readAll();
|
|
|
|
QString strTempBuffer=QString(revBuffer);
|
|
if(strTempBuffer.contains("|"))
|
|
{
|
|
QStringList list=strTempBuffer.split('|');
|
|
for (int i=0;i<list.count();i++) {
|
|
emit valueReceived(list.at(i).toInt());
|
|
}
|
|
}
|
|
if(strTempBuffer.contains(readyCheckString))
|
|
{
|
|
emit allReady();
|
|
}
|
|
if(strTempBuffer.contains(gameLevelEasy))
|
|
{
|
|
emit gameLevel(GAME_LEVEL_EASY);
|
|
}
|
|
if(strTempBuffer.contains(gameLevelMiddle))
|
|
{
|
|
emit gameLevel(GAME_LEVEL_NORMAL);
|
|
}
|
|
if(strTempBuffer.contains(gameLevelHard))
|
|
{
|
|
emit gameLevel(GAME_LEVEL_HARD);
|
|
}
|
|
if(strTempBuffer.contains(gameStartString))
|
|
{
|
|
emit gameStatus(GAME_STATUS_START);
|
|
}
|
|
if(strTempBuffer.contains(gameStopString))
|
|
{
|
|
emit gameStatus(GAME_STATUS_STOP);
|
|
}
|
|
if(strTempBuffer.contains(gamePauseString))
|
|
{
|
|
emit gameStatus(GAME_STATUS_PAUSE);
|
|
}
|
|
if(strTempBuffer.contains(gameContinueString))
|
|
{
|
|
emit gameStatus(GAME_STATUS_RESUME);
|
|
}
|
|
|
|
}
|