forked from jimgeisler/LifeIsMagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
153 lines (141 loc) · 4.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link href='http://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css'>
<link href='/css/style.css' rel='stylesheet' type='text/css'>
<title>
</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
</head>
<body>
<div id="get_name" class="page" style="display:none">
<div>
<h1>LIFEIS<strong>MAGIC</strong></h1>
<div class="name_enter">
<label for="nameInput">enter your name</label>
<p>
<input id="nameInput" value="" type="text" />
</p>
<button id="save">SAVE</button>
</div>
</div>
</div>
<div id="play" style="display:none" class="page">
<h1>LIFEIS<strong>MAGIC</strong></h1>
<div id="name"></div>
<div class="player_stats">
<div class="stat">
<div class="icon">
<img src="/images/heart.png" />
</div>
<div class="counter">
<div id="life_minus" class="button">-</div><div id="life" class="value">20</div><div id="life_plus" class="button">+</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<div class="stat">
<div class="icon">
<img src="/images/skull.png" />
</div>
<div class="counter">
<div id="poison_minus" class="button">-</div><div id="poison" class="value">0</div><div id="poison_plus" class="button">+</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
<div id="others"></div>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
function update() {
socket.emit('update',{name : name, life : life, poison : poison});
}
var name = "";
var life = 20;
var poison = 0;
var socket;
$("#save").bind("click", function (event){
if ($("#nameInput").val() != "") {
if (name != "") {
socket.emit('remove',name);
}
name = $("#nameInput").val();
localStorage.setItem("name", name);
socket.emit('join',{name:name});
$("#name").text(name);
}
$("#get_name").hide();
$("#play").show();
});
$("#life_plus").bind("touchstart click", function(event) {
if (event.type === "touchstart") { $(this).unbind("click"); }
life = life + 1;
$("#life").text(life);
update();
})
$("#life_minus").bind("touchstart click", function(event) {
if (event.type === "touchstart") { $(this).unbind("click"); }
life = life - 1;
$("#life").text(parseInt($("#life").text()) - 1);
update();
})
$("#poison_plus").bind("touchstart click", function(event) {
if (event.type === "touchstart") { $(this).unbind("click"); }
poison = poison + 1;
$("#poison").text(poison);
update();
})
$("#poison_minus").bind("touchstart click", function(event) {
if (event.type === "touchstart") { $(this).unbind("click"); }
poison = poison - 1;
$("#poison").text(poison);
update();
})
$("#name").bind("click", function(event) {
$("#play").hide()
$("#get_name").show()
})
</script>
<script>
socket = io.connect('http://' + window.location.hostname);
var name = localStorage.getItem("name");
if (name == "null" || name == null) {
$("#get_name").show();
} else {
$("#name").text(name);
console.log('emitting, right?')
socket.emit('join',{name:name});
$("#play").show();
}
socket.on('new', function(data) {
console.log(data)
$("#others").empty();
for (eIdx in data.players) {
var player = data.players[eIdx];
if (player.name != name) {
$("#others").append($("<div>").attr("id",player.name.replace(" ","")).attr("class", "other").
append("<div class='other_name'>" + player.name + "</div><div class='other_stats'><img src='/images/heart.png' /><span class='other_life'>" + player.life + "</span><img src='/images/skull.png' /><span class='other_poison'>" + player.poison + "</span></div>"));
}
}
})
socket.on('update', function(data) {
player = data.player
var player_element = $('#' + player.name.replace(" ", ""));
player_element.find('.other_life').empty().append(player.life);
player_element.find('.other_poison').empty().append(player.poison);
if (player.life >= 10 && player.poison <= 6) {
player_element.removeClass("warn").removeClass("dead");
} else if (player.life > 0 && player.poison < 10) {
player_element.addClass("warn").removeClass("dead");
} else {
player_element.addClass("dead");
}
})
</script>
</body>
</html>