-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_demo.html
128 lines (114 loc) · 2.89 KB
/
client_demo.html
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
<!doctype html>
<html>
<head>
<title>client demo</title>
<style>
.tests {
width: 100%;
height: 400px;
font-size: 0;
}
.tests>.test {
width: 100%;
height: 40px;
display: inline-block;
font-size: 14px;
}
.tests>.test>label {
width: 100px;
line-height: 40px;
text-align: right;
display: inline-block;
}
.tests>.test>input {
width: 300px;
height: 20px;
line-height: 40px;
}
.buttons {
width: 100%;
height: 30px;
font-size: 0;
}
.buttons>.button {
width: 60px;
height: 100%;
padding-left: 10px;
font-size: 14px;
display: inline-block;
}
.buttons>.button>input {
width: 100%;
height: 100%;
cursor: pointer;
}
</style>
</head>
<body>
<ul id="messages"></ul>
<div class="tests">
<div class="test">
<label>测试1:</label>
<input id="test1" type="text">
</div>
<div class="test">
<label>测试2:</label>
<input id="test2" type="text">
</div>
</div>
<div class="buttons">
<div class="button">
<input id="btn1" type="button" value="登录">
</div>
<div class="button">
<input id="btn2" type="button" value="创建房间">
</div>
<div class="button">
<input id="btn3" type="button" value="加入房间">
</div>
<div class="button">
<input id="btn4" type="button" value="开始游戏">
</div>
<div class="button">
<input id="btn5" type="button" value="测试2">
</div>
</div>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$(function () {
var socket = io();
//登录
$('#btn1').on('click', function (e) {
let group = $('#room').val();
socket.emit('login', $('#content').val());
socket.on('login_state', function (state) {
let msg = state ? '登录成功' : '登录失败';
$('#messages').append($('<li>').text(msg));
window.scrollTo(0, document.body.scrollHeight);
});
return false;
});
//开始游戏
$('#btn4').on('click', function (e) {
let group = $('#room').val();
socket.emit('start', $('#content').val());
socket.on('sendcards', function (cards) {
if (cards) {
let cardArr = JSON.parse(cards);
cardArr.forEach(function (card) {
$('#messages').append($('<li>').text(JSON.stringify(card)));
window.scrollTo(0, document.body.scrollHeight);
}, this);
}
});
return false;
});
socket.on('chat message', function (msg) {
$('#messages').append($('<li>').text(msg));
window.scrollTo(0, document.body.scrollHeight);
});
});
</script>
</body>
</html>