Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
303 commits
Select commit Hold shift + click to select a range
86a3e7c
Update README.md
SU-Hongs Dec 4, 2020
18fc878
Update README.md
SU-Hongs Dec 4, 2020
f3c07fd
Update README.md
SU-Hongs Dec 4, 2020
c57b6cf
Update CurrentPattern.h
hzelg Dec 4, 2020
5c40826
Update README.md
SU-Hongs Dec 4, 2020
a4a3d34
Update README.md
SU-Hongs Dec 4, 2020
8b703d9
Update README.md
SU-Hongs Dec 4, 2020
a83d2ad
Update README.md
SU-Hongs Dec 4, 2020
33af405
Update README.md
SU-Hongs Dec 4, 2020
d5fa8fb
Update README.md
SU-Hongs Dec 4, 2020
4ed9016
Update README.md
SU-Hongs Dec 4, 2020
734dba1
Update README.md
SU-Hongs Dec 4, 2020
861655c
Update playwindow.cpp
hzelg Dec 4, 2020
f16cc85
Update README.md
SU-Hongs Dec 4, 2020
254116e
Update README.md
SU-Hongs Dec 4, 2020
b443f6f
Update playwindow.cpp
hzelg Dec 4, 2020
7657cc7
Update playwindow.cpp
hzelg Dec 4, 2020
044d650
Update Player.cpp
SU-Hongs Dec 4, 2020
68c078e
Update Player.h
SU-Hongs Dec 4, 2020
3dc8b1c
Update CurrentPattern.cpp
williamlus Dec 4, 2020
a5085be
Update CurrentPattern.cpp
williamlus Dec 4, 2020
2ee5b7f
Update CardsGroup.cpp
williamlus Dec 4, 2020
b5f070c
Update Player.cpp
SU-Hongs Dec 4, 2020
f4d024a
Update Player.cpp
SU-Hongs Dec 4, 2020
1fcf52d
Add files via upload
SU-Hongs Dec 4, 2020
afc26d9
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
de63068
Update playwindow.cpp
williamlus Dec 4, 2020
797ace5
Update playwindow.cpp
williamlus Dec 4, 2020
d74c90c
Update playwindow.cpp
SU-Hongs Dec 4, 2020
718ae40
Update mainwindow.ui
SU-Hongs Dec 4, 2020
fa63c4b
Update README.md
SU-Hongs Dec 4, 2020
fa2d40f
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
9beb363
Update playwindow.h
RyanZ010819 Dec 4, 2020
984f5c9
Add files via upload
SU-Hongs Dec 4, 2020
a80ec2e
Update serverwindow.cpp
williamlus Dec 4, 2020
d07a4e1
Update serverwindow.h
williamlus Dec 4, 2020
bb932ee
Update clientwindow.cpp
williamlus Dec 4, 2020
f5ceda2
Update clientwindow.ui
williamlus Dec 4, 2020
d0cf3fb
Update playwindow.h
RyanZ010819 Dec 4, 2020
d8352a7
Update serverwindow.ui
williamlus Dec 4, 2020
04e0392
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
31e9853
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
56cf7c5
Add files via upload
williamlus Dec 4, 2020
bd2bd44
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
64c743d
Update clientwindow.h
williamlus Dec 4, 2020
4851b8e
Update clientwindow.cpp
williamlus Dec 4, 2020
d12d33a
Update serverwindow.cpp
williamlus Dec 4, 2020
3b5a660
Update serverwindow.cpp
williamlus Dec 4, 2020
8d4c7af
Add files via upload
RyanZ010819 Dec 4, 2020
38b98e4
Update serverwindow.cpp
williamlus Dec 4, 2020
f4159ae
Add files via upload
RyanZ010819 Dec 4, 2020
a7a7819
Update AIPlayer.cpp
SU-Hongs Dec 4, 2020
209394b
Update CurrentPattern.cpp
SU-Hongs Dec 4, 2020
8a890e5
Update playwindow.cpp
SU-Hongs Dec 4, 2020
f2295b2
Update AIPlayer.cpp
SU-Hongs Dec 4, 2020
280d58e
Add files via upload
RyanZ010819 Dec 4, 2020
1499e87
Add files via upload
RyanZ010819 Dec 4, 2020
450029f
Add files via upload
RyanZ010819 Dec 4, 2020
ae5afcd
Add files via upload
RyanZ010819 Dec 4, 2020
903e3a8
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
3817d47
Update README.md
hzelg Dec 4, 2020
fec8cb1
Update README.md
SU-Hongs Dec 4, 2020
fa541cf
Update README.md
SU-Hongs Dec 4, 2020
21ec0e3
Update README.md
SU-Hongs Dec 4, 2020
64a071e
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
d668fdf
Update playwindow.h
RyanZ010819 Dec 4, 2020
050582f
Update README.md
SU-Hongs Dec 4, 2020
0a74a7f
Update README.md
SU-Hongs Dec 4, 2020
fdf110d
Update README.md
SU-Hongs Dec 4, 2020
8ef600d
Update README.md
SU-Hongs Dec 4, 2020
3a7a44c
Update README.md
SU-Hongs Dec 4, 2020
de34eb7
Update README.md
SU-Hongs Dec 4, 2020
7831a2c
Update README.md
SU-Hongs Dec 4, 2020
1a40ad4
Update README.md
SU-Hongs Dec 4, 2020
79c2459
Update playwindow.cpp
hzelg Dec 4, 2020
4e4f5bb
Update Player.cpp
SU-Hongs Dec 4, 2020
85db204
Update AIPlayer.cpp
SU-Hongs Dec 4, 2020
032a716
Update AIPlayer.cpp
SU-Hongs Dec 4, 2020
b5b5fe0
Add files via upload
RyanZ010819 Dec 4, 2020
ad3ab48
Update serverwindow.cpp
williamlus Dec 4, 2020
e28b9d7
Update playwindow.cpp
hzelg Dec 4, 2020
6f2986f
Update playwindow.cpp
SU-Hongs Dec 4, 2020
ae970f2
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
0ceec5a
Update README.md
hzelg Dec 4, 2020
68922a4
Update playwindow.cpp
williamlus Dec 4, 2020
3532d4f
Update README.md
SU-Hongs Dec 4, 2020
23c330e
Update README.md
SU-Hongs Dec 4, 2020
febcf8c
Update README.md
SU-Hongs Dec 4, 2020
84fc7c3
Update README.md
SU-Hongs Dec 4, 2020
a424146
Update README.md
SU-Hongs Dec 4, 2020
de1dd9e
Update playwindow.cpp
hzelg Dec 4, 2020
2e0266b
Update playwindow.cpp
hzelg Dec 4, 2020
ddb19f5
Update clientwindow.h
williamlus Dec 4, 2020
1cfada0
Add files via upload
SU-Hongs Dec 4, 2020
af7fbca
Update serverwindow.h
williamlus Dec 4, 2020
f3db53d
Update playwindow.cpp
RyanZ010819 Dec 4, 2020
aa7c5c9
Update playwindow.cpp
williamlus Dec 5, 2020
fd1e66e
Add files via upload
williamlus Dec 5, 2020
911c6a1
Update playwindow.cpp
hzelg Dec 5, 2020
7644867
Add files via upload
williamlus Dec 5, 2020
781ba83
Delete C10.png
williamlus Dec 5, 2020
3f70d1e
Delete C11.png
williamlus Dec 5, 2020
3a2f11e
Delete C12.png
williamlus Dec 5, 2020
ac1b5ae
Delete C13.png
williamlus Dec 5, 2020
c1b3b90
Delete C14.png
williamlus Dec 5, 2020
500d0d9
Delete C15.png
williamlus Dec 5, 2020
fb1b00d
Delete C3.png
williamlus Dec 5, 2020
ea30321
Delete C4.png
williamlus Dec 5, 2020
06c9e04
Delete C5.png
williamlus Dec 5, 2020
3d32e09
Delete C6.png
williamlus Dec 5, 2020
6474f04
Delete C7.png
williamlus Dec 5, 2020
b9d1eab
Delete C8.png
williamlus Dec 5, 2020
5300784
Delete C9.png
williamlus Dec 5, 2020
ae214c2
Delete D10.png
williamlus Dec 5, 2020
526aa53
Delete D11.png
williamlus Dec 5, 2020
51de192
Delete D12.png
williamlus Dec 5, 2020
e72147f
Delete D13.png
williamlus Dec 5, 2020
391f3b2
Delete D14.png
williamlus Dec 5, 2020
e11d571
Delete D15.png
williamlus Dec 5, 2020
2ab744b
Delete D3.png
williamlus Dec 5, 2020
71387de
Delete D4.png
williamlus Dec 5, 2020
15808bb
Delete D5.png
williamlus Dec 5, 2020
f1d9ebd
Delete D6.png
williamlus Dec 5, 2020
5385f82
Delete D7.png
williamlus Dec 5, 2020
02fc3af
Delete D8.png
williamlus Dec 5, 2020
c88c276
Delete D9.png
williamlus Dec 5, 2020
ccbcbff
Delete H10.png
williamlus Dec 5, 2020
786a055
Delete H11.png
williamlus Dec 5, 2020
7cd7fe7
Delete H12.png
williamlus Dec 5, 2020
55ef611
Delete H13.png
williamlus Dec 5, 2020
fc0c4ea
Delete H14.png
williamlus Dec 5, 2020
55146d3
Delete H15.png
williamlus Dec 5, 2020
b685ea1
Delete H3.png
williamlus Dec 5, 2020
54c39f9
Delete S9.png
williamlus Dec 5, 2020
54aa4a9
Delete H4.png
williamlus Dec 5, 2020
9d1523d
Delete H5.png
williamlus Dec 5, 2020
81a108c
Delete H6.png
williamlus Dec 5, 2020
edfdd19
Add files via upload
williamlus Dec 5, 2020
b45f711
Delete H7.png
williamlus Dec 5, 2020
d1f298e
Delete H8.png
williamlus Dec 5, 2020
82a065c
Delete H9.png
williamlus Dec 5, 2020
976e70f
Delete K16.png
williamlus Dec 5, 2020
a60e35d
Delete K17.png
williamlus Dec 5, 2020
6325f22
Delete S10.png
williamlus Dec 5, 2020
f12e75a
Delete S11.png
williamlus Dec 5, 2020
de18161
Delete S12.png
williamlus Dec 5, 2020
6da6ea4
Delete S13.png
williamlus Dec 5, 2020
fbb9dce
Delete S14.png
williamlus Dec 5, 2020
a021855
Delete S15.png
williamlus Dec 5, 2020
e648413
Delete S3.png
williamlus Dec 5, 2020
0bae16d
Delete S4.png
williamlus Dec 5, 2020
9782717
Delete S5.png
williamlus Dec 5, 2020
921e5d5
Delete S6.png
williamlus Dec 5, 2020
f9e4b5b
Delete S7.png
williamlus Dec 5, 2020
b5e17fa
Delete S8.png
williamlus Dec 5, 2020
5e254ea
Delete electronic.mp3
williamlus Dec 5, 2020
ab9705d
Delete normal.mp3
williamlus Dec 5, 2020
e8aaa8d
Delete bg.png
williamlus Dec 5, 2020
879e58c
Delete no.png
williamlus Dec 5, 2020
b014893
Delete yes.png
williamlus Dec 5, 2020
5faa74b
Delete C10.png
williamlus Dec 5, 2020
fe4b705
Delete C11.png
williamlus Dec 5, 2020
2cc33b8
Delete C12.png
williamlus Dec 5, 2020
b3e25ca
Delete C13.png
williamlus Dec 5, 2020
3bb32bd
Delete C14.png
williamlus Dec 5, 2020
bed4c64
Delete C15.png
williamlus Dec 5, 2020
433497b
Delete C3.png
williamlus Dec 5, 2020
5541d89
Delete C4.png
williamlus Dec 5, 2020
b04dbc4
Delete C5.png
williamlus Dec 5, 2020
c58f2a6
Delete C6.png
williamlus Dec 5, 2020
88e4921
Delete C7.png
williamlus Dec 5, 2020
2463d8a
Delete C8.png
williamlus Dec 5, 2020
ffb734e
Delete C9.png
williamlus Dec 5, 2020
014e08f
Delete D10.png
williamlus Dec 5, 2020
7b08764
Delete D11.png
williamlus Dec 5, 2020
728af40
Delete D12.png
williamlus Dec 5, 2020
de776fd
Delete D13.png
williamlus Dec 5, 2020
2d3c2ca
Delete D14.png
williamlus Dec 5, 2020
da25bd8
Delete D15.png
williamlus Dec 5, 2020
5bb5390
Delete D3.png
williamlus Dec 5, 2020
5be65e0
Delete D4.png
williamlus Dec 5, 2020
0744d65
Delete D5.png
williamlus Dec 5, 2020
d8f3f33
Delete D6.png
williamlus Dec 5, 2020
b4640ef
Delete D7.png
williamlus Dec 5, 2020
dc46a9d
Delete D8.png
williamlus Dec 5, 2020
ebb7ac4
Delete D9.png
williamlus Dec 5, 2020
3c65b0e
Delete H13.png
williamlus Dec 5, 2020
db439ad
Delete H10.png
williamlus Dec 5, 2020
9350e38
Delete H11.png
williamlus Dec 5, 2020
4bc7984
Delete H12.png
williamlus Dec 5, 2020
5f9bf93
Delete H14.png
williamlus Dec 5, 2020
6c954cb
Delete H15.png
williamlus Dec 5, 2020
b1dc33a
Delete H3.png
williamlus Dec 5, 2020
3bae13f
Delete H4.png
williamlus Dec 5, 2020
e2bafb7
Delete H5.png
williamlus Dec 5, 2020
0496d42
Delete H6.png
williamlus Dec 5, 2020
41ece91
Delete H7.png
williamlus Dec 5, 2020
8c6a174
Delete H8.png
williamlus Dec 5, 2020
ff75631
Delete H9.png
williamlus Dec 5, 2020
1f1e37f
Delete K16.png
williamlus Dec 5, 2020
f539263
Delete K17.png
williamlus Dec 5, 2020
ff08ebf
Delete S10.png
williamlus Dec 5, 2020
fd439ec
Delete S11.png
williamlus Dec 5, 2020
0d687e0
Delete S12.png
williamlus Dec 5, 2020
27e1ffc
Delete S13.png
williamlus Dec 5, 2020
e217a9f
Delete S14.png
williamlus Dec 5, 2020
9af9e42
Delete S15.png
williamlus Dec 5, 2020
72bde76
Delete S3.png
williamlus Dec 5, 2020
ed550fb
Delete S4.png
williamlus Dec 5, 2020
b43ca64
Delete S5.png
williamlus Dec 5, 2020
b36df6f
Delete S6.png
williamlus Dec 5, 2020
12b2820
Delete S7.png
williamlus Dec 5, 2020
ea4b9fd
Delete S8.png
williamlus Dec 5, 2020
a88321b
Delete S9.png
williamlus Dec 5, 2020
80b6829
Delete hello.txt
williamlus Dec 5, 2020
363ed90
Delete 开始游戏.bat
williamlus Dec 5, 2020
fd7a212
Add files via upload
williamlus Dec 5, 2020
a3faf60
Update playwindow.cpp
williamlus Dec 5, 2020
8efb58c
Update datapackage.cpp
williamlus Dec 5, 2020
029ecb5
Update datapackage.cpp
williamlus Dec 5, 2020
4e74c80
Update datapackage.cpp
williamlus Dec 5, 2020
ddb487d
Update serverwindow.cpp
williamlus Dec 5, 2020
db945dd
Update serverwindow.cpp
williamlus Dec 5, 2020
4ab01dd
Update serverwindow.cpp
williamlus Dec 5, 2020
38e6527
Update serverwindow.cpp
williamlus Dec 5, 2020
a14c09b
Update clientwindow.cpp
williamlus Dec 5, 2020
f9776f7
Update clientwindow.h
williamlus Dec 5, 2020
9f7880e
Update clientwindow.ui
williamlus Dec 5, 2020
6a0c6bd
Update serverwindow.cpp
williamlus Dec 5, 2020
8155937
Add files via upload
williamlus Dec 5, 2020
42bb5ee
Update playwindow.cpp
williamlus Dec 5, 2020
a0daa50
Update playwindow.h
williamlus Dec 5, 2020
47c0557
Update clientwindow.cpp
williamlus Dec 5, 2020
15ed2aa
Update clientwindow.cpp
williamlus Dec 5, 2020
b55044d
Update serverwindow.cpp
williamlus Dec 5, 2020
a0074ba
Update serverwindow.cpp
williamlus Dec 5, 2020
b341a78
Update serverwindow.cpp
williamlus Dec 5, 2020
0234108
Update playwindow.cpp
williamlus Dec 5, 2020
486d965
Add files via upload
williamlus Dec 5, 2020
31a09da
Update playwindow.cpp
williamlus Dec 5, 2020
c196dc0
Update clientwindow.cpp
williamlus Dec 5, 2020
af872a7
Update clientwindow.cpp
williamlus Dec 5, 2020
bb496a9
Add files via upload
williamlus Dec 5, 2020
8decb7c
Update README.md
williamlus Nov 5, 2022
70ca32b
Update README.md
williamlus Nov 5, 2022
5ed6b77
Update README.md
williamlus Nov 5, 2022
6e2cc72
Move Windows release to another repository
williamlus Nov 5, 2022
cd75975
Update README.md
williamlus Nov 5, 2022
7b6c2ca
Update README.md
williamlus Nov 5, 2022
0485193
Update README.md
williamlus Nov 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 206 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,206 @@
# COMP2012H_Project
UST Landlord Game
# USTlandlord Game

By COMP2012H 2020FALL Group21, ZHENG Hantao, SU Hong, LU Weiqi, GUO Bingcan

### 0. Installation
Windows version of this game is in [COMP-2012H repository](https://github.com/williamlus/COMP-2012H). Download that repository and double click [start.exe](https://github.com/williamlus/COMP-2012H/blob/main/start.exe) to start the game.

![USTlord 2022_11_5 19_42_51](https://user-images.githubusercontent.com/67042315/200118232-d7e20a93-01f5-4643-b3e9-708ccf1ea124.png)

### 1. Introduction

Dou dizhu is described as easy to learn but hard to master, requiring mathematical and strategic thinking as well as carefully planned execution. Suits are irrelevant in playing doudizhu. Players can easily play the game with a set of dou dizhu playing cards, without the suits printed on the cards. Less popular variations of the game do exist in China, such as four-player and five-player dou dizhu played with two packs of cards.

Making a Qt GUIbased game has moderate difficulty and can be expanded with many other features such as multi-player, background music and even a chat box for players to communicate with their teammates and opponents, while the project is relatively s itable to apply beginner’slevel OOP to achieve.

### 2. Overview

Apply OOP to develop a landlord game with GUI based on QT with followingfeatures:

1. A computer “AI” player written based on simple game logic as human

2. Multip-player mode, which is the most important part of the game.

3. Background music and fancy GUI.



**Basic Rules and Strateges**

1.**A player can deal with an unrelated or useless card by making it the kicker card.**

2.**Rocket and bomb are the ultimate weapons in the game.**

If they either is in one's hand, one should make full use of it when time comes. If players do not possess high confidence in winning, they may think twice about dealing a rocket or bomb, because once the dealt, the risk stake of the round will be doubled (players will either win or lose double) with each rocket or bomb dealt.

3.**Peasants must co-operate to fight against the landlord.**

For example, since the two peasants come after one another, the first peasant might play a low single card if the second peasant has a sole card left.
(Reference: https://en.wikipedia.org/wiki/Dou_dizhu#Rules)




### 3. Design

* **Class Design**

Console Game:

* Board
* Cards
* CardsGroup
* CardsType
* CurrentPattern
* Deck
* Player

Networking:

* Datapackage
* ServerWindow

GUI:

* playerwindow
* mainwindow
* serverwindow
* clientwindow



* **AI Player Design**

AI Logic:

`const CardsGroup choose_hint(const CurrentPattern& cp);`

* AI player with some common sense strategies:

* if the AI player is the first one to play or the CurrentPattern is played by himself
he will play cards with the following logic:

First find the smallest card in hand,
if it is inside a bomb, then DO NOT play it, and find the second smallest one unless he only has one card left
if not, then if this card is inside any other cards_combination, then just play this combination
otherwise just play this SINGLE card

* if the AI player is landlord, then try to beat everyone

* if the AI player is farmer, then beat landlord all the time

* if the CurrentPattern is played by another farmer
Only give cards in these cases:

* the AI player can directly win the game
* the partner played a small SINGLE or PAIR



`bool want_landlord() override;//choose to be landlord or not automatically`


* the probability of choosing lord is determined by how good the cards in hand are

The evaluation is basically determined by the number of cards_combination

The cards_combination considered here are:

TRIO,BOMB, ROCKET


* **UI Design**

1. Distribute cards effect.
2. Show buttons according to game process.
3. Info bar displays game process to players.
4. Play cards effect and view other players' cards.
5. Serverwindow and Clientwindow design.



* **Networking Design**

**Transfer principle:**
Using Transmission Control Protocol (TCP)\
The one created room will simultaneously be SERVER and CLIENT, the rest two are just CLIENT\
Before sending and after receiving the raw_data, the information is stored in user_defined object: **Datapackage**\
For more details of the usages of DataPackage, please refer to `DataPackage.h`


class DataPackage
{
public:
enum Action{
NONE=-1,
GIVE_ID,
CONFIRM_READY,
DEAL_CARDS,
CHOOSE_LANDLORD,
LANDLORD_BONUS,
PLAY_CARDS,
ANNOUNCE,
CHAT,
EXCEPTION
};

struct Content{
static const QString REQUEST;
static const QString ACCEPT;
static const QString REJECT;
static const QString BE_LANDLORD;
static const QString DO_NOT_PLAY;
static const QString WIN_GAME;
static const QString LOSE_GAME;
static const QString END_GAME;
static const QString QUIT;
};

public:

int sender;
int actioner;
Action action;
QString content;

};


**DataPackage** is equivalent to a formatted QString: "sender:`(int) sender_id`;actioner:`(int) actioner_id`;Action;Content"

Before sending **DataPackage**, we will first convert it to the formatted QString, then serialize it to QByteArray

After receiving **raw_data(QByteArray)**, we will first convert it to QString, then convert it to DataPackage



### 4. UI Display

Main window

Single Player game:

* Choose landlord:
* Player cards:
* View hints:
* Game over:

Multiplayer Player game:



### 5. Summary

**This project design is a comprehensive OOP program design. The development of USTlord game involves object-oriented programming, data structure, TCP networking and GUI design. We encounted and overcame quite a lot problems due to lack of knowledge and communication problems of multi-person collaboration. The experience we gain are as follows:**

- Deenpen the understanding of object-oriented programming

Different from process-oriented program,object-oriented programming involves class, object, inheritance, polymorphism etc., which greatly enhance the resuability of the codes, and also provide convinience for deleveloping projects in team.

- Modern development concept

In a program involving multiple modules, the more modern development method is encapsulation. After determining the structure of the program, encapsulate the different modules. On the one hand, it is easy to combine and use the modules. On the other hand, the clear interfaces are also the cornerstone of efficient cooperation.

- Development tools and multi-person collaboration

Modern program development is not alone. Multi-person remote collaboration and project management are very important parts of program specification development. The use of Git for version control and project management in this program design has brought great convenience to the development of the program, and also allowed us to deepen our understanding of the actual software engineering process.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += core gui network
QT += core gui network multimedia

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

Expand All @@ -22,7 +22,8 @@ SOURCES += \
source/CurrentPattern.cpp \
source/Deck.cpp \
source/Player.cpp \
source/DataPackage.cpp
source/datapackage.cpp\
source/CardPicture.cpp

HEADERS += \
clientwindow.h \
Expand All @@ -37,7 +38,8 @@ HEADERS += \
source/CurrentPattern.h \
source/Deck.h \
source/Player.h \
source/DataPackage.h
source/datapackage.h\
source/CardPicture.h

FORMS += \
clientwindow.ui \
Expand All @@ -49,3 +51,7 @@ FORMS += \
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
img.qrc \
music.qrc
78 changes: 72 additions & 6 deletions USTlord_final/clientwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "clientwindow.h"
#include "ui_clientwindow.h"
#include <QMessageBox>

ClientWindow::ClientWindow(QWidget *parent) :
QMainWindow(parent),
Expand All @@ -8,36 +9,101 @@ ClientWindow::ClientWindow(QWidget *parent) :
ui->setupUi(this);
}

void ClientWindow::closeEvent(QCloseEvent *event){
if(socket){
socket->close();
socket->deleteLater();
qDebug() << "Closing socket";
}
this->parentWidget()->show();
emit close_window();
event->accept();
}

ClientWindow::~ClientWindow()
{
delete ui;
}

void ClientWindow::handleStateChanged(QAbstractSocket::SocketState state)
{

if(state==QAbstractSocket::SocketState::UnconnectedState){
if(play_window){
play_window->close();
}
socket->close();
ui->listWidget_dialogs->addItem("Disconnected from server");
ui->listWidget_dialogs->addItem("Closing the socket");
}
}

void ClientWindow::handle_server_message()
{
ui->listWidget_dialogs->addItem("Handle server msg");
if(socket){
QByteArray arr=socket->readAll();
ui->listWidget_dialogs->addItem(QString::fromStdString(arr.toStdString()));
DataPackage data=DataPackage::parse(arr);
ui->listWidget_dialogs->addItem("Received from server:"+data.to_string());
// qDebug()<< "data.action==DataPackage::Action::GIVE_ID?";/////
// qDebug() << (data.action==DataPackage::Action::GIVE_ID);//////////
if(data.action==DataPackage::Action::GIVE_ID){
QMessageBox::information(this,"Start","Let's start!",QMessageBox::Ok,QMessageBox::Ok);
id=data.content.toInt();
}
if(play_window){
play_window->receive_from_client(DataPackage::parse(arr));
ui->listWidget_dialogs->addItem("data.conent="+data.content);///////
DataPackage data_to_send(id,id,DataPackage::GIVE_ID,ui->lineEdit_name->text()+"#"+QString::number(id));
send_to_server(data_to_send);
}////////
else if(data.action==DataPackage::Action::CONFIRM_READY){
QStringList names=data.content.split(QLatin1Char(','),Qt::SkipEmptyParts);
QVector<QString> names_vec{};
for(int i=0;i<names.size();i++){
names_vec.push_back(names[i]);
qDebug() << names_vec[i];
}
play_window=new PlayWindow(id,names_vec,this);
connect(play_window,&PlayWindow::send_to_client,this,&ClientWindow::received_from_playwindow);
connect(play_window,&PlayWindow::close_window,[=](){
play_window=nullptr;
send_to_server(DataPackage(id,id,DataPackage::EXCEPTION,DataPackage::Content::QUIT));
ui->listWidget_dialogs->addItem("You exit the room");
disconnect(play_window,&PlayWindow::send_to_client,this,&ClientWindow::received_from_playwindow);
qDebug() << "exit the room";
});
play_window->show();/////////
// this->hide();
DataPackage data_to_send(id,-1,DataPackage::Action::CONFIRM_READY,DataPackage::Content::ACCEPT);
send_to_server(data_to_send);
}/////////
else if(play_window){
ui->listWidget_dialogs->addItem("send msg to playwindow"+data.to_string());/////////////
play_window->receive_from_client(data);
}
}
}

void ClientWindow::send_to_server(DataPackage data){

ui->listWidget_dialogs->addItem("Send to server"+data.to_string());//////
qDebug() << "Send to server"+data.to_string();
if(socket){
QByteArray arr=data.serialize();
socket->write(arr);
}
}
void ClientWindow::received_from_playwindow(DataPackage data){
if(socket){
this->send_to_server(data);
}
}

void ClientWindow::set_port(QString port)
{
ui->lineEdit_server_port->setText(port);
}

void ClientWindow::set_serverIP(QString ip)
{
ui->lineEdit_serverIP->setText(ip);
}

void ClientWindow::on_pushButton_join_server_clicked()
Expand All @@ -62,5 +128,5 @@ void ClientWindow::on_pushButton_stop_joining_clicked()

void ClientWindow::on_pushButton_quit_clicked()
{

this->close();
}
Loading