forked from hellenicdev/clicker-game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClicker Game.html
More file actions
172 lines (153 loc) · 6.51 KB
/
Clicker Game.html
File metadata and controls
172 lines (153 loc) · 6.51 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clicker Simulation Game</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
flex-direction: column;
text-align: center;
position: relative;
}
/* Button styles */
button {
font-size: 20px;
padding: 10px 20px;
cursor: pointer;
margin-bottom: 10px;
transition: background-color 0.3s ease;
}
/* Disabled button style */
.disabled {
background-color: darkgray; /* Dark gray when not enough points */
cursor: not-allowed; /* No entry sign cursor */
}
/* Enabled button style */
.enabled {
background-color: #4CAF50;
cursor: pointer;
}
/* Points counter styling */
#counter {
font-size: 30px;
margin-bottom: 40px; /* Space between points indicator and "Click me!" button */
position: absolute;
top: 100px;
/* Move it 100px down from the top */
}
/* Upgrade button container styling */
#upgrades {
display: flex;
flex-direction: column;
gap: 10px;
position: absolute;
top: 70%; /* Positioned further down */
}
/* Positioning the "Click me!" button */
#clickButton {
position: absolute;
top: 55%; /* Center vertically */
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<!-- Points indicator -->
<div id="counter">Points: 0</div>
<!-- Click me button -->
<button id="clickButton">Click me!</button>
<!-- Upgrade buttons (initially hidden) -->
<div id="upgrades">
<button id="doublePointsButton" class="disabled" onclick="purchaseUpgrade('doublePoints')">Double Points (Cost: 30)</button>
<button id="autoClickerButton" class="disabled" onclick="purchaseUpgrade('autoClicker')">Auto-Clicker (Cost: 80)</button>
<button id="bonusMultiplierButton" class="disabled" onclick="purchaseUpgrade('bonusMultiplier')">Bonus Multiplier (Cost: 200)</button>
<button id="instantClickButton" class="disabled" onclick="purchaseUpgrade('instantClick')">Instant Click (Cost: 400)</button>
<button id="triplePointsButton" class="disabled" onclick="purchaseUpgrade('triplePoints')">Triple Points (Cost: 100)</button>
</div>
<script>
let points = 0; // Player's points
let clickValue = 1; // Points per click
let autoClickerActive = false; // Auto-clicker status
let instantClickActive = false; // Instant click status
let autoClickInterval = null; // Holds auto-clicker interval
const upgrades = {
doublePoints: { cost: 30, purchased: false },
autoClicker: { cost: 80, purchased: false },
bonusMultiplier: { cost: 200, purchased: false },
instantClick: { cost: 400, purchased: false },
triplePoints: { cost: 100, purchased: false },
};
const clickButton = document.getElementById("clickButton");
const counterDiv = document.getElementById("counter");
// Update the points display
function updateCounter() {
counterDiv.textContent = `Points: ${points}`;
checkUpgrades(); // Check which upgrades can be unlocked based on points
}
// Handle the "Click me!" button click
clickButton.addEventListener("click", function() {
points += clickValue;
updateCounter();
});
// Purchase an upgrade
function purchaseUpgrade(upgrade) {
if (upgrades[upgrade].purchased) return; // Do nothing if already purchased
if (points >= upgrades[upgrade].cost) {
points -= upgrades[upgrade].cost; // Deduct points
upgrades[upgrade].purchased = true; // Mark as purchased
updateCounter();
if (upgrade === 'doublePoints') {
clickValue *= 2; // Double the points per click
} else if (upgrade === 'autoClicker' && !autoClickerActive) {
autoClickerActive = true;
autoClickInterval = setInterval(function() {
points += clickValue;
updateCounter();
}, 1000);
} else if (upgrade === 'bonusMultiplier') {
clickValue *= 3; // Triple the points per click
} else if (upgrade === 'instantClick') {
instantClickActive = true;
setInterval(function() {
if (instantClickActive) {
points += clickValue;
updateCounter();
}
}, 200);
} else if (upgrade === 'triplePoints') {
clickValue *= 3; // Triple the points per click
}
// Hide the button after purchase
document.getElementById(upgrade + 'Button').style.display = 'none';
}
}
// Check if the player can afford any upgrades and show/hide them accordingly
function checkUpgrades() {
for (let upgrade in upgrades) {
const upgradeButton = document.getElementById(upgrade + 'Button');
if (!upgrades[upgrade].purchased && points >= upgrades[upgrade].cost) {
// Show the upgrade button only when the player has enough points
upgradeButton.style.display = 'inline-block';
upgradeButton.classList.remove('disabled');
upgradeButton.classList.add('enabled');
} else if (upgrades[upgrade].purchased || points < upgrades[upgrade].cost) {
// Hide the button if the upgrade has been purchased or the player can't afford it
upgradeButton.style.display = 'none';
}
}
}
// Periodically check for upgrades to unlock (every second)
setInterval(checkUpgrades, 1000);
// Initialize the counter
updateCounter();
</script>
</body>
</html>