-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
148 lines (141 loc) · 4.33 KB
/
main.qml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import QtQuick 2.1
import QtQuick.Window 2.11
import FlatUI 2.0
import "./gameComponent"
Window {
id: rootWindow
width: gameWindow.width
height: gameWindow.height
visible: true
property var selfInfo
function recvJsonObj(jsonObj) {
switch (jsonObj["messageType"]) {
case 0:
gameHall.addPlayer(jsonObj["deskID"], jsonObj["seatID"], jsonObj["account"])
// account=="" mean leave seat
if(jsonObj["account"]!=="")
gameWindow.addTheOtherSide(jsonObj["deskID"], jsonObj["seatID"], jsonObj["playerInfo"])
else
gameWindow.removeTheOtherSide(jsonObj["deskID"], jsonObj["seatID"])
break;
case 1:
gameHall.setReady(jsonObj["deskID"], jsonObj["seatID"], jsonObj["isReady"])
gameWindow.setOtherSideReady(jsonObj["deskID"], jsonObj["seatID"], jsonObj["isReady"])
break;
case 2:
gameWindow.putChess(jsonObj["row"], jsonObj["column"], jsonObj["result"])
break;
case 3:
//接受到请求悔棋消息
gameWindow.reqestTackBack()
break;
case 4:
// 执行悔棋操作
gameWindow.takeBack(jsonObj["resp"], jsonObj["whoReq"], jsonObj["whoResp"], jsonObj["lastSteps"])
break
case 5:
// 收到对方认输消息
gameWindow.recvLoseReq()
break
case 6:
// 收到对方和棋请求
gameWindow.recvDrawReq()
break
case 7:
// 收到请求和棋的回复
gameWindow.recvDrawRespond(jsonObj["resp"])
break;
case 8:
//收到聊天消息
gameWindow.addChatTextMessage(jsonObj["text"])
}
}
function netWorkError(err) {
console.log("call netWorkError")
console.log(err)
}
ManagerWindow {
id: managerWindow
anchors.fill: parent
visible: false
}
GameWindow {
id: gameWindow
visible: false
}
GameHall {
id: gameHall
visible: false
anchors.fill: parent
}
LoginWindow {
id: loginWindow
visible: false
anchors.centerIn: parent
onLogined: {
detailPlayerInfo.addPlayerInfo(playerInfo["account"], playerInfo["nickname"]
, playerInfo["score"], playerInfo["winRound"]
, playerInfo["loseRound"], playerInfo["drawRound"]
, playerInfo["escapeRound"])
detailPlayerInfo.display(playerInfo["account"])
selfInfo = playerInfo
//detailPlayerInfo.visible = true
gameHallBtn.type = FlatGlobal.typePrimary
}
}
RegisterWindow {
id: registerWindow
visible: false
anchors.centerIn: parent
}
DetailPlayerInfo {
width: 130
anchors.right: parent.right
anchors.top: parent.top
id: detailPlayerInfo
visible: false
}
Item {
id: rootRect
anchors.fill: parent
Column {
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.leftMargin: 15
anchors.rightMargin: 15
anchors.bottomMargin: 25
spacing: 25
FlatButton {
text: "登录"
onClicked: {
rootRect.visible = false
loginWindow.visible = true
}
}
FlatButton {
text: "注册"
onClicked: {
rootRect.visible = false
registerWindow.visible = true
}
}
FlatButton {
text: "人机对弈"
onClicked: {
rootRect.visible = false
gameWindow.visible = true
gameWindow.resetGameWindow()
}
}
FlatButton {
id: gameHallBtn
text: "网络对弈"
type: FlatGlobal.typeDisabled
onClicked: {
rootRect.visible = false
gameHall.visible = true
}
}
}
}
}