-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinigame.html
131 lines (130 loc) · 4.34 KB
/
inigame.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tartam</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vuefire/dist/vuefire.js"></script>
</head>
<body>
<div id="app">
<span style="">Player 1 = {{playerSatu['user']}}</span>
<span style="margin-left: 50%;">Player 2 = {{playerDua['user']}}</span>
<div class="container">
<h2>Basic Progress Bar</h2>
<div class="progress">
<div class="progress-bar" role="progressbar" :aria-valuenow="progressive" aria-valuemin="0" aria-valuemax="100" :style="progressive">
<span class="sr-only">70% Complete</span>
</div>
</div>
</div>
<div :style="progressMerah">
</div>
</div>
<script>
var config = {
apiKey: "AIzaSyCUHvjhSMX2NeDTKbny453Wcj2-bzW2C44",
authDomain: "tartam-dev.firebaseapp.com",
databaseURL: "https://tartam-dev.firebaseio.com",
projectId: "tartam-dev",
storageBucket: "",
messagingSenderId: "1026006366586"
};
var firebaseApp = firebase.initializeApp(config);
var db = firebaseApp.database()
Vue.use(VueFire)
var app = new Vue({
el: "#app",
data: {
progressive: "",
progressMerah: ``,
leftnya: 48
},
firebase: function() {
return {
room: db.ref('/room'),
onlineUser: db.ref('onlineUser/')
}
},
computed: {
playerSatu: function() {
return this.room[0]
},
playerDua: function() {
return this.room[1]
},
progress: function() {
return this.room[2]
},
progressnya () {
db.ref('/room/progress/nilai').set(this.progress.nilai)
this.progressive = `width: ${this.progress.nilai}%`
this.progressMerah = `background: red; height: 50px; width: 50px; position: relative; left: ${this.leftnya}%`
return
}
},
methods: {
tambahin () {
console.log("tambah");
if (this.progress.nilai < 100) {
this.progress.nilai += 10
this.leftnya += 8
} else {
if (this.playerSatu.user == localStorage.currUser) {
let nilaiBaru = this.playerDua.score += 10
db.ref('onlineUser/'+localStorage.getItem('key')+'/score').set(nilaiBaru)
db.ref('room/'+this.playerSatu['.key']).remove()
db.ref('room/'+this.playerDua['.key']).remove()
db.ref('room/progress').set({
nilai: 50
})
alert(`${this.playerSatu.user} menang!!`)
window.location.href = '/'
} else {
let nilaiBaru = this.playerDua.score += 10
db.ref('onlineUser/'+localStorage.getItem('key')+'/score').set(nilaiBaru)
db.ref('room/progress').set({
nilai: 50
})
alert(`${this.playerDua.user} menang!!`)
window.location.href = '/'
}
}
this.progressnya
},
kurangin () {
if (this.progress.nilai > 0) {
this.progress.nilai -= 10
this.leftnya -= 8
} else {
let nilaiBaru = this.playerDua.score += 10
console.log(this.playerSatu);
db.ref('onlineUser/'+this.playerSatu['.key']+'/score').set(nilaiBaru)
db.ref('room/'+this.playerSatu['.key']).remove()
alert(`${this.playerSatu.user} menang!!`)
window.location.href = '/'
}
this.progressnya
}
},
created: function() {
this.progressnya
}
})
$(document).keydown(function(e) {
if (e.which == 37) {
app.kurangin()
return false;
} else if (e.which == 39) {
app.tambahin()
return false;
}
})
</script>
</body>
</html>