-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchessdispatch.cpp
More file actions
58 lines (51 loc) · 1.51 KB
/
chessdispatch.cpp
File metadata and controls
58 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "chessdispatch.h"
#include "chessreplay.h"
#include "chessserver.h"
#include "chessclient.h"
#include "chessaicontrol.h"
#include "chessinformation.h"
#include "chesslog.h"
#include "chessprotocol.h"
ChessDispatch * ChessDispatch::INSTANCE = 0;
ChessDispatch *ChessDispatch::instance()
{
if(!INSTANCE)
{
INSTANCE = new ChessDispatch;
}
return INSTANCE;
}
ChessDispatch::ChessDispatch(QObject *parent) :
QObject(parent), chessOpposition(0)
{
switch(ChessInformation::instance()->getChessType())
{
case(ReplayType): chessOpposition = ChessReplay::instance(); break;
case(ServerType): chessOpposition = ChessServer::instance(); break;
case(ClientType): chessOpposition = ChessClient::instance(); break;
case(AIType): chessOpposition = ChessAIControl::instance(); break;
default: Chess_Fatal(tr("chess type error!")); break;
}
Chess_Trace(tr("new ChessDispatch"));
}
ChessDispatch::~ChessDispatch()
{
delete chessOpposition;
chessOpposition = 0;
Chess_Trace(tr("delete ChessDispatch"));
}
bool ChessDispatch::isValid()
{
if(chessOpposition) return chessOpposition->isValid();
else return false;
}
void ChessDispatch::send(const QString &message)
{
Chess_Info("send: "+message);
if(chessOpposition) chessOpposition->send(message);
}
void ChessDispatch::receive(const QString &message)
{
Chess_Info("receive: "+message);
ChessProtocol::instance()->receiveMessage(message);
}