This repository has been archived by the owner on Dec 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opponent.h
76 lines (64 loc) · 2.06 KB
/
opponent.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef OPPONENT_H
#define OPPONENT_H
#include <QObject>
#include <QtNetwork>
#include "card.h"
#include "role.h"
#include "handcategory.h"
class Opponent : public QObject
{
Q_OBJECT
typedef DDZ::CardType Card;
public:
Opponent(QObject *parent = nullptr);
~Opponent();
bool connectTo(const QString &server_addr, const int &server_port);
QAbstractSocket::SocketState getListenState();
void setSocket(QTcpSocket *newSock);
void initServer();
void notifyServerUp(const QHostAddress &addr, const quint16 port);
void secondConnect(QJsonObject connInfo);
QJsonObject getConnInfo();
void giveDeck(const QVector<Card> &hand, const QVector<Card> &hide);
void announceReadyBW(bool black);
void announceBid(bool bid);
void confirmRoles();
void informCardsDealt(const HandCategory &hand);
HandCategory getLastDealt() const;
DDZ::Role getRole() const;
void setRole(const DDZ::Role &role);
void informGameOver();
bool nextRoundReady();
private:
QString serverAddr;
quint16 serverPort;
QTcpSocket *m_socket;
QByteArray buffer;
qint32 sz;
// game related
DDZ::Role m_role;
HandCategory lastDealtHand;
bool writeData(const QByteArray &data);
void processData(const QByteArray &rawData);
void initialHandshake(const QJsonObject &json);
void setRemoteServer(const QJsonObject &json);
void receiveDeck(const QJsonObject &json);
void receiveBid(const QJsonObject &json);
void updateLastDealt(const QJsonObject &json);
inline bool writeData(const QJsonObject &json) { return writeData(QJsonDocument(json).toJson()); }
private slots:
void receiveData();
signals:
// mainwindow related, e.g. server functions
void serverStart(quint16 port);
void addressReceived(QString serverAddr);
// game related
void blackAndWhite(bool black);
void incomingDecks(const QVector<Card> &hand, const QVector<Card> &hide);
void incomingBid(bool bid);
void rolesConfirmed();
void dealt();
void wonGame();
void canStart();
};
#endif // OPPONENT_H