-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.html
239 lines (217 loc) · 9.58 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html>
<head>
<title>Seven Wonders</title>
<link href="styles/mediakit.css" rel="stylesheet" type="text/css" />
<link href="styles/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/jquery-1.6.2.js"></script>
<script type="text/javascript" src="scripts/jquery-rotate.js"></script>
<script type="text/javascript" src="scripts/jquery.flip.min.js"></script>
<script type="text/javascript" src="scripts/jquery.easing.js"></script>
<script type="text/javascript" src="scripts/html5slider.js"></script>
<script type="text/javascript" src="scripts/wonder.js"></script>
<script type="text/javascript" src="scripts/game.js"></script>
<script type="text/javascript">
(function() {
function createSocket(host){
if(window.WebSocket) return new WebSocket(host);
else if(window.MozWebSocket) return new MozWebSocket(host);
}
function send(opts, type){
opts.messageType = type;
socket.send(JSON.stringify(opts));
}
function onopen(msg) {
console.log("WebSocket OPEN!");
send({id: my_id}, 'myid');
}
function onmessage(msg) {
var args = JSON.parse(msg.data);
switch(args.messageType){
case 'myname':
localStorage.sevenwonders_id = args.id;
$('input[name=name]').attr('value', args.name);
my_name = args.name;
changeName({name:{value: my_name}});
$('input[name=name]').attr('value', my_name);
// doing this so we don't have that awkward flashing screen on refresh
if(!args.ingame && !$('#pregame').is(':visible'))
$('#pregame').fadeIn(100);
break;
case 'newgame':
if(status == "lobby"){
$('#opengames').append('<li class="light" id="game'+
args.id + '"><a href="#" onclick="return ' +
"joinGame('" + args.id + "')\">" + args.name +
' - ' + args.creator + '</a></li>');
}
break;
case 'newplayer':
$('#waiting ul').append('<li>' + args.name + '</li>');
break;
case 'startinfo':
status = "game";
$('#pregame, #game, body').css('overflow', 'hidden');
if(args.rejoin == true){
$('#pregame').css('display', 'none');
$('#game').css('display', 'block');
$('#pregame, #game, body').css('overflow', 'auto');
} else {
$('#pregame').fadeOut(500, function(){
$('#game').fadeIn(500, function(){ $('#pregame, #game, body').css('overflow', 'auto'); });
});
}
game = new SevenWonders(socket, args);
break;
case 'started':
$("#game" + args.id).css('display', 'none');
break;
case 'joingame':
waitScreen();
for (var i = 0; i < args.players.length; i++)
$('#waiting ul').append(
'<li>' + args.players[i] + '</li>');
break;
default:
if(game != undefined)
game.onMessage(args, msg.data);
else
console.log(msg.data);
break;
}
}
var socket;
var my_id = localStorage.sevenwonders_id || '';
var my_name = "Guest";
var status = "lobby";
var game = undefined;
$(document).ready(function(){
var host = "ws://" + window.location.hostname + ":12345";
try {
socket = createSocket(host);
socket.onopen = onopen;
socket.onmessage = onmessage;
socket.onclose = function(msg){
console.log("WebSocket CLOSED...");
$('body *').remove();
$('body').append('<h1 class="disconnect"><span>ERROR</span>: The game server is down or your connection was severed. Try refreshing.</h1>')
}
} catch(ex) {
console.log(ex);
}
$('input[name=players]').change(function(){
$('#numplayers').html($(this).attr('value'));
});
});
window.newGame = function(form){
if(form.game_name.value == ''){
alert('Please enter a name for your game.');
return false;
}
var opts = { name: form.game_name.value,
players: form.players.value };
send(opts, "newgame");
waitScreen();
return false;
};
function waitScreen(){
$('#lobby').fadeOut(500, function(){
$('#pregame').css('display', 'block');
$('#lobby').css('display', 'none');
$('#waiting').fadeIn(1000);
$('#pregame').animate({ height: $('#waiting').outerHeight() }, 500, function(){
$(this).css('height', 'auto');
});
});
$('#waiting ul').append('<li>' + my_name + ' (you)</li>');
$('#pregame').css('height', $('#lobby').outerHeight());
status = "waiting";
}
window.joinGame = function(id){
var opts = { id: id };
send(opts, "joingame");
waitScreen();
return false;
};
window.changeName = function(form){
var opts = { name: form.name.value };
send(opts, "changename");
my_name = opts.name;
return false;
};
})();
</script>
</head>
<body>
<div id="pregame">
<div id="lobby">
<h1>Seven Wonders<br /><span>Created by Antoine Bauza, published by Repos Productions</span></h1>
<form id="nickname" method="post" onsubmit="return changeName(this)">
Name: <input type="text" name="name" value="" />
<input type="submit" value="Change Name" />
</form>
<div class="column left">
<h2>Start a Game</h2>
<form method="post" onsubmit="return newGame(this)">
<table>
<tr>
<td>Game Name:</td>
<td><input type="text" name="game_name" /></td>
</tr>
<tr>
<td># Players:</td>
<td>
<input type='range' name='players' min='3'
max='7' value='3' />
<span id='numplayers'>3</span>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Start" /></td>
</tr>
</table>
</form>
</div>
<div class="column right">
<h2>Open Games</h2>
<ul id="opengames" class="menu light"></ul>
</div>
</div>
<div id="waiting">
<h1>Waiting for Players...</h1>
<ul></ul>
</div>
</div>
<div id="game">
<div id="setup-container">
<div id="setup">
<h1>SETUP</h1>
<p>You were given <strong></strong>. Pick a side of the board to play:</p>
</div>
</div>
<div class="neighbor left">
<h1></h1>
<div class="info">
<img class="resource" />
<div class="stage"></div>
</div>
</div>
<div class="neighbor right">
<h1></h1>
<div class="info">
<img class="resource" />
<div class="stage"></div>
</div>
</div>
<div id="cardselect">
<div id="cardwindow">
<h1></h1>
</div>
<div id="hovercardwindow"></div>
</div>
</div>
<!-- co.nr link for niceness -->
<a href="http://www.freedomain.co.nr/" title="Free Domain Name"><img src="http://rnrnoza.imdrv.net/animg7.gif" alt="Free Domain Name" style="width:88px;height:31px;border:0;" /></a>
</body>
</html>