-
Notifications
You must be signed in to change notification settings - Fork 0
/
deckSnapTest.html
163 lines (130 loc) · 3.83 KB
/
deckSnapTest.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!doctype html>
<html>
<head>
<title>decksnap test</title>
<link rel="stylesheet" href="public/styles.css">
</head>
<body>
<H1>Decksnap Web Test Beta</H1>
<div id= "turn"></div>
<div id= "handwinner"></div>
<div id="name">
<ul id="player"></ul>
<p></p>
<form action="" id="p"> user id
<input id="n" autocomplete="off" />
<button>Sim log in </button>
</form>
</div>
<div id="game">
<ul id="moves"></ul>
<form action="" id="a"> move
<input id="jk" autocomplete="off" />
<button>Send move </button>
</form>
</div>
<div id="challange">
<form action="" id="c"> user id
<input id="ch" autocomplete="off" />
<button>challanger id </button>
</form>
</div>
<div id="allusers"></div>
<ul id="cardid"></ul>
<ul id="win"></ul>
</body>
<script src="public/cards.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
//console.log(cards);
//sets room
var x;
var challenger;
var iamP1 = false;
var turn = document.getElementById("turn");
var hw = document.getElementById("handwinner");
var username;
$('#p').submit(function () {
username = $('#n').val();
socket.emit('connectPlayer', $('#n').val());
// $('#n').val('');
return false;
});
//var room;
var socket = io();
$('#c').submit(function () {
socket.emit('challange',username, $('#ch').val());
challenger = $('#ch').val();
iamP1 = true;
//$('#m').val('');
return false;
});
$('#move').submit(function () {
socket.emit('playcat1', $('#n').val());
//$('#m').val('');
return false;
});
//move, playerId, roomId
$('#a').submit(function () {
socket.emit('playermove', $('#jk').val(), $('#n').val(), x);
$('#jk').val('');
return false;
});
socket.on('playerTurn', function (msg) {
turn.innerHTML = "user ids turn is " + msg;
// console.log(x);
});
socket.on('roomname', function (msg) {
x = msg;
console.log(x);
});
socket.on(username, function (msg) {
console.log("myre" + msg);
});
socket.on('gameStarted', function (msg) {
socket.emit('mycard', name, x);
});
socket.on('incomingchallange', function (msg, msg2) {
console.log(msg, msg2);
challenger = msg;
x = msg2;
challengeAlert();
});
///handWonBy
socket.on('handWonBy', function (msg) {
hw.innerHTML = "hand won by user id:" + msg;
// console.log(x);
});
socket.on('start', function (msg) {
$('#name').append($('<p>').text(msg));
});
socket.on('movement', function (msg) {
$('#messages').append($('<li>').text(msg));
});
socket.on('connectToRoom', function (msg) {
$('#messages').append($('<li>').text(msg));
});
socket.on('player', function (msg) {
$('#player').append($('<li>').text(msg));
});
socket.on('card', function (msg) {
$('#cardid').append($('<li>').text(msg));
});
socket.on('winner', function (msg) {
$('#win').append($('<li>').text(msg));
//playerId, roomId
socket.emit('finishgame', $('#n').val(), x);
});
function challengeAlert() {
console.log("test");
if (confirm("Do You accept a challenge from " + challenger) == true) {
socket.emit('acceptchallenge', challenger, username, x);
iamP1 = false;
} else {
socket.emit('delinechallenge', challenger, username, x);
}
}
</script>
</body>
</html>