-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
86 lines (74 loc) · 1.76 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
<!doctype html>
<html>
<head>
<title>Domotic Panel</title>
<style>
* {
border: 0;
margin: 0;
padding: 0;
font-family: helvetica, monospace;
color: #FF794D;
font-size: 0;
}
body {
background: #FFFF9D;
}
.part{
display: inline-block;
width: 50vw;
}
.graph {
height: 100vh;
width: 100%;
background: #79BD8F;
}
#good{
background: url('img/sc1.jpg');
}
#bad{
background: #000;
height: 100vh;
}
</style>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<div id="good" class="part">
<div class="graph"></div>
</div>
<div id="bad" class="part"></div>
<script>
var socket = io(); // Creamos la conexion con el servidor
// Selecciona los elementos del DOM
var $graph = document.querySelector('.graph');
// var $button = document.querySelector('.button');
var height = 90;
var level = 0;
function game() {
height = height + level;
height = height > 100 ? 100 : height;
$graph.style.height= height + "vh";
console.log("height: " + height);
if (height <= 0) {
alert("Ganaste :)");
location.reload();
}
if(height >= 100){
alert("Perdiste :(");
location.reload();
}
}
var timer = setInterval(game, 500);
// Evento onSensor: Crea el eventListener y nos indica cuando un
socket.on('sensor', function onSensorCallback(newLevel) {
// var width = (value * 100) / 1023;
// $graph.style.height= width + "%";
level = newLevel;
});
// $button.addEventListener("click", function (){
// socket.emit('buttonpress', 'bu!');
// });
</script>
</body>
</html>