-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
105 lines (93 loc) · 2.38 KB
/
index.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
93
94
95
96
97
98
99
100
101
102
103
104
105
import { getPattern, setForm, getForm, makeDigiPet } from './src/drawDigipet.js'
import { DIGI_FORM, DELAY_IN_SECONDS } from './const.js'
import { DIGI_PATTERN } from './src/patterns.js'
var index = 0
var eggLove = 0
var babyFilth = 1
const buttonPet = document.querySelector('.button-pet')
const buttonFeed = document.querySelector('.button-feed')
const buttonClean = document.querySelector('.button-clean')
const disableButtons = bool => {
if (getForm() === DIGI_FORM.EGG) {
buttonClean.disabled = true
buttonFeed.disabled = true
buttonPet.disabled = bool
} else {
buttonClean.disabled = bool
buttonFeed.disabled = bool
buttonPet.disabled = bool
}
}
buttonPet.onclick = () => {
console.log('petDigipet')
disableButtons(true)
if (getForm() === DIGI_FORM.EGG) {
setForm(DIGI_FORM.HAPPY_EGG)
eggLove++
if (eggLove >= 3) {
setTimeout(() => {
setForm(DIGI_FORM.BABY)
disableButtons(false)
}, 5 * 1000)
} else {
setTimeout(() => {
setForm(DIGI_FORM.EGG)
disableButtons(false)
}, 5 * 1000)
}
} else if (getForm() !== DIGI_FORM.DIRTY_BABY) {
setForm(DIGI_FORM.HAPPY_BABY)
setTimeout(() => {
setForm(DIGI_FORM.BABY)
disableButtons(false)
}, 5 * 1000)
} else {
disableButtons(false)
}
}
buttonClean.onclick = () => {
console.log('clean')
disableButtons(true)
if (getForm() === DIGI_FORM.DIRTY_BABY) {
setForm(DIGI_FORM.HAPPY_BABY)
setTimeout(() => {
setForm(DIGI_FORM.BABY)
disableButtons(false)
}, 5 * 1000)
} else {
disableButtons(false)
}
}
buttonFeed.onclick = () => {
console.log('feed')
disableButtons(true)
babyFilth++
setForm(DIGI_FORM.FED_BABY)
if (babyFilth > 3) {
setTimeout(() => {
setForm(DIGI_FORM.DIRTY_BABY)
disableButtons(false)
}, 5 * 1000)
} else {
setTimeout(() => {
setForm(DIGI_FORM.HAPPY_BABY)
setTimeout(() => {
setForm(DIGI_FORM.BABY)
disableButtons(false)
}, 5 * 1000)
}, 5 * 1000)
}
}
setInterval(() => {
var digiPattern = getPattern(getForm())
if (!digiPattern) {
digiPattern = eggLove >= 3 ? DIGI_PATTERN.BABY : DIGI_PATTERN.EGG
}
makeDigiPet(digiPattern[index])
index++
// index = index === totalPatterns ? 0 : index+1
if (index >= digiPattern.length) {
index = 0
}
}, DELAY_IN_SECONDS * 60)
export { disableButtons }