-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
137 lines (109 loc) · 3.16 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
<link rel="stylesheet" href="http://cdn.foundation5.zurb.com/foundation.css">
<style>
.columns, .column {
background: #ccc;
border: solid black 8px;
padding: 4rem;
font-size: 7.5rem;
text-align: center;
}
.column:first-child, .columns:first-child{
border-left: none;
}
.column:last-child, .columns:last-child{
border-right: none;
}
.row:first-child .column, .row:first-child .columns{
border-top: none;
}
.row:last-child .columns{
border-bottom: none;
}
@media screen and (max-width: 63.9375em) {
.columns{
min-height: 33vw;
}
.board{
margin-top: calc(((100vh - 100vw) / 2) - 2.75rem);
}
}
h1{
top: 0;
left: 0;
}
h2{
font-size: 4rem;
text-align: center;
display: block;
}
</style>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<h1 id="title">Tic-Tac-Toe</h1>
<h2></h2>
<div class="board">
<div class="row">
<div class="small-4 columns square" data-id="0">-</div>
<div class="small-4 columns square" data-id="1">-</div>
<div class="small-4 columns square" data-id="2">-</div>
</div>
<div class="row">
<div class="small-4 columns square" data-id="3">-</div>
<div class="small-4 columns square" data-id="4">-</div>
<div class="small-4 columns square" data-id="5">-</div>
</div>
<div class="row">
<div class="small-4 columns square" data-id="6">-</div>
<div class="small-4 columns square" data-id="7">-</div>
<div class="small-4 columns square" data-id="8">-</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
var socket = io();
socket.on('position', function(msg){
// update ui with position
});
socket.on('start_game', function(msg){
// show game board and init everything (listeners)
console.log("Got start game msg");
console.log(msg);
});
socket.on('you_win', function(){ console.log('you win!'); });
socket.emit('client_hello', function(){
});
var $boxes = $('.square');
function set(index, contents){
$($boxes[index]).text(contents);
}
$boxes.click(function(e){
var id = $(e.target).data('id');
socket.emit('play', { squareId: id });
});
socket.on('game_board', function(msg){
$('h2').text(msg);
});
socket.on('move_made', function(msg){
set(msg.squareId, msg.symbol);
console.log('MOVE PLAYED');
});
socket.on('you_win', function(){
$('body').css('background', 'green');
});
socket.on('you_lose', function(){
$('body').css('background', 'red');
});
</script>
</body>
</html>