-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (62 loc) · 2.03 KB
/
Copy pathscript.js
File metadata and controls
71 lines (62 loc) · 2.03 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
const state = {
points: 0,
clickValue: 1,
upgrades: {},
autoClickInterval: null,
instantClickInterval: null,
};
const UPGRADES = [
{ id: 'doublePoints', name: 'Double Points', cost: 30, effect: s => { s.clickValue *= 2; } },
{ id: 'autoClicker', name: 'Auto-Clicker', cost: 80, effect: s => { startAutoClicker(s); } },
{ id: 'triplePoints', name: 'Triple Points', cost: 100, effect: s => { s.clickValue *= 3; } },
{ id: 'bonusMultiplier', name: 'Bonus Multiplier', cost: 200, effect: s => { s.clickValue *= 3; } },
{ id: 'instantClick', name: 'Instant Click', cost: 400, effect: s => { startInstantClick(s); } },
];
const counterEl = document.getElementById('counter');
const clickBtn = document.getElementById('clickButton');
const upgradesEl = document.getElementById('upgrades');
function render() {
counterEl.textContent = `Points: ${state.points}`;
for (const def of UPGRADES) {
const btn = document.getElementById(`${def.id}Button`);
if (!btn) continue;
const up = state.upgrades[def.id];
const affordable = !up && state.points >= def.cost;
btn.className = affordable ? 'enabled' : 'disabled';
}
}
function purchase(def) {
const up = state.upgrades[def.id];
if (up || state.points < def.cost) return;
state.points -= def.cost;
state.upgrades[def.id] = true;
def.effect(state);
render();
}
clickBtn.addEventListener('click', () => {
state.points += state.clickValue;
render();
});
for (const def of UPGRADES) {
const btn = document.createElement('button');
btn.id = `${def.id}Button`;
btn.className = 'disabled';
btn.textContent = `${def.name} (${def.cost})`;
btn.addEventListener('click', () => purchase(def));
upgradesEl.appendChild(btn);
}
function startAutoClicker(s) {
if (s.autoClickInterval) return;
s.autoClickInterval = setInterval(() => {
s.points += s.clickValue;
render();
}, 1000);
}
function startInstantClick(s) {
if (s.instantClickInterval) return;
s.instantClickInterval = setInterval(() => {
s.points += s.clickValue;
render();
}, 200);
}
render();