-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnonVRFirebase.js
94 lines (80 loc) · 2.44 KB
/
nonVRFirebase.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
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
var lastCurrTile = null;
var currTile = null;
const firebaseConfig = {
apiKey: "AIzaSyBrAnW65FVKNAcNns3zVfa0z1MT_I0___c",
authDomain: "hacksc-538d5.firebaseapp.com",
databaseURL: "https://hacksc-538d5.firebaseio.com",
projectId: "hacksc-538d5",
storageBucket: "hacksc-538d5.appspot.com",
messagingSenderId: "548745669097"
};
// var database = firebase.database();
const init = () => {
firebase.initializeApp(firebaseConfig);
newCurrTile();
onWin();
onDead();
};
window.onload = function() {
initGrid("mine-field", row, column);
init();
initCounter("title-bar");
}
const onWin = () => {
firebase.database().ref('/grids/won').on('value', (snapshot) => {
// console.log("onwin");
if (snapshot.val()) {
// console.log(snapshot.val());
displayWin("end-game-pop-up");
firebase.database().ref('/grids/currentPosition').off();
firebase.database().ref('/grids/isDead').off();
firebase.database().ref('/grids/won').off();
}
})
}
const onDead = () => {
firebase.database().ref('/grids/isDead').on('value', (snapshot) => {
if (snapshot.val()) {
displayDead("end-game-pop-up");
firebase.database().ref('/grids/currentPosition').off();
firebase.database().ref('/grids/isDead').off();
firebase.database().ref('/grids/won').off();
}
})
}
const flagBomb = (x,y) => {
firebase.database().ref('/grids/points/' + x + '/' + y).update({flagged: true});
};
const unflagBomb = (x, y) => {
firebase.database().ref('/grids/points/' + x + '/' + y).update({flagged: false});
}
const newCurrTile = () => {
firebase.database().ref('/grids/currentPosition').on('value', (snapshot) => {
var currGrid = snapshot.val();
if (currTile) {
// console.log(currTile);
lastCurrTile = currTile;
// console.log(lastCurrTile);
deHighlightTile(lastCurrTile);
}
currTile = document.getElementById("tile-" + currGrid.x + "-" + currGrid.y);
revealNewTile(currTile, currGrid);
highlightTile(currTile);
});
}
const revealNewTile = (tile, currGrid) => {
firebase.database().ref('/grids/points/' + currGrid.x + '/' + currGrid.y).once('value', (snapshot) => {
var grid = snapshot.val();
if (tile && tile.getAttribute("revealed") == "false") {
revealTile(tile, grid.number);
}
});
}
const getBombCount = (counterId) => {
firebase.database().ref('/grids/numBombs').once('value', (snapshot) => {
// console.log(snapshot.val());
bombCount = snapshot.val();
// console.log(bombCount);
drawCounter(counterId);
});
}