Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
147 lines (134 loc) · 3.8 KB
/
Copy pathmain.js
File metadata and controls
147 lines (134 loc) · 3.8 KB
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
//Please use a display with 1920x1080p resolution for best results
audio = new Audio('Ping Sound Effect - Discord.mp3')
audio.loop = false;
snakeaudio = new Audio('Among Us (Role Reveal) - Sound Effect (HD).mp3')
snakeaudio.loop = false
ladderaud = new Audio('Mario Jump Sound Effect.mp3')
ladderaud.loop = false
const snakes = [25,34,47,65,87,91,99]
const snakeTail = [5,1,19,52,57,61,69]
const ladders = [3,6,20,36,63,68]
const ladderDest = [51,27,70,55,95,98]
function OKOK(x) {
const a = document.getElementById(x);
var ok = a.style.left
console.log(ok)
/*currp = a.style.left
console.log(currp)
np = Number(currp.substring(0,currp.length-2))
console.log(np);
np+= 60
a.style.top = '690px'
a.style.left = np+'px'*/
}
function init(x)
{
const a = document.getElementById(x);
console.log(a.style.top);
currp = a.style.left
console.log(currp)
}
function bd()
{
const a = document.getElementById('blob')
const b = document.getElementById('blob2')
a.style.top = '750px'
b.style.top = '750px'
a.style.left = '420px'
b.style.left = '420px'
//init('blob');
}
function MOVE(x)
{
const a = document.getElementById(x);
var moves = RollDice()
if (x=="blob") {
alert("Dice Roll by Player 1: "+moves)
}
else
{
alert("Dice Roll by Player 2: "+moves)
}
isvalid = 100-xytoint(a.style.left,a.style.top)-moves
if (isvalid<0) {
return;
}
var ok = a.style.top
console.log(ok)
//alert(currt)
while(moves--){
currp = a.style.left
currt = a.style.top
if (currp=="1050px") {
tmp = Number(currt.substring(0,currt.length-2))
tmp-=70
a.style.top = tmp+'px'
a.style.left = '420px'
}
else
{
console.log(currp)
np = Number(currp.substring(0,currp.length-2))
console.log(np);
np+= 70
//a.style.top = '750px'
a.style.left = np+'px'
}
}
audio.play()
}
function RollDice()
{
return Math.ceil(Math.random()*(6));
}
function unlockB(x,y)
{
const a = document.getElementById(x)
const b = document.getElementById(y)
a.disabled = false
b.disabled = true
}
function getCor(x)
{
return [420+70*((x-1)%10)+"px",750-70*(Math.floor((x-1)/10))+"px"]
}
function checkSL(player)
{
const a = document.getElementById(player)
if (xytoint(a.style.left,a.style.top)===100) {
document.getElementById('blob').disabled = true
document.getElementById('blob2').disabled = true
alert("Game over!")
window.location.href = "gameover.html";
}
tmp = [a.style.left,a.style.top]
for (let i = 0; i < snakes.length; i++) {
if (tmp[0]===getCor(snakes[i])[0] && tmp[1]===getCor(snakes[i])[1]) {
alert("You were bitten by a snake")
snakeaudio.play()
dest = getCor(snakeTail[i])
a.style.left = dest[0]
a.style.top = dest[1]
return;
}
}
for (let i = 0; i < ladders.length; i++) {
if (tmp[0]===getCor(ladders[i])[0] && tmp[1]===getCor(ladders[i])[1]) {
alert("A Ladder!")
ladderaud.play()
dest = getCor(ladderDest[i])
a.style.left = dest[0]
a.style.top = dest[1]
return;
}
}
}
//everything is 80px wide
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function xytoint(x,y) {
tmp = Number(x.substring(0,x.length-2))
tmp2 = Number(y.substring(0,y.length-2))
return Math.floor((tmp-420)/70)+1 + Math.floor((750-tmp2)/7)
}