/
socket.js
64 lines (49 loc) · 1.77 KB
/
socket.js
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
var socket = io('http://jsfighter.tk:4200');
function launchGame(){
var player_tag = document.getElementById('tag_1').value;
if (!player_tag) {
alert('You need to enter a player name!');
}
else {
$( ".container-1" ).fadeOut( "slow", function() {
console.log("Fadeout Complete");
});
console.log('Creating new match....');
socket.emit('newMatch', player_tag);
socket.on('newMatch', function(matchID){
console.log('Match ID = ' + matchID);
$("#matchID_show").text('Your match ID is: #' + matchID);
$( ".container-2" ).fadeIn( "slow", function() {
console.log("Fadein Complete");
});
});
}
}
function connectGame() {
var player_tag = document.getElementById('tag_2').value;
var matchID = document.getElementById('matchID').value;
socket.emit('joinMatch',
{ player_tag: player_tag , matchID: matchID }
);
};
socket.on('alert', function(msg){
alert(msg);
});
socket.on('log', function(msg){
console.log(msg);
});
socket.on('initiate', function() {
$( "#loading_screens" ).fadeOut( "slow", function() {
$( ".container-3" ).fadeIn( "slow", function() { });
initGame();
});
});
socket.on('kill', function() {
$( ".container-3" ).fadeOut( "slow", function() {
$( ".container-1" ).css('display', 'none');
$("#matchID_show").text('Your opponent has disconnected!');
$("#matchMsg").text('You will want to navigate back to the home page and launch a new game.');
$( "#loading_screens" ).fadeIn( "slow", function() { });
$( ".container-2" ).fadeIn( "slow", function() { });
});
});