Skip to content

Commit 08340b2

Browse files
committed
Add auto clickers variables to calculate points earned per second
1 parent 3d32bbb commit 08340b2

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/App.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ function App() {
55
//app component
66
const [points, setPoints] = useState(0); //set initial points to 0
77
const [pointsPerSecond, setPointsPerSecond] = useState(0);
8+
const [autoClickers, setAutoClickers] = useState(0); //set auto clickers to 0
89
const [clicks, setClicks] = useState(0); //set initial clicks pressed to 0
910
const [clickMultiplier, setClickMultiplier] = useState(1);
11+
const [clickers, setClickers] = useState(1); //set clickers to 1
1012
const [seconds, setSeconds] = useState(0); //set initial seconds played to 0
1113
useEffect(() => {
1214
const interval = setInterval(() => {
@@ -28,23 +30,33 @@ function App() {
2830
return false;
2931
}
3032
}
33+
function updateClickers() {
34+
//update click multiplier for clickers
35+
setClickMultiplier(clickers); //set click multiplier
36+
}
37+
function updateAutoClickers() {
38+
//update points per second for autoclickers
39+
setPointsPerSecond(autoClickers); //set points per second
40+
}
3141
function addPointsFromClick() {
3242
//add points from clicking a button
3343
setPoints(points + clickMultiplier); //increase points by 1 when button clicked
3444
setClicks(clicks + 1); //increase clicks made by 1
3545
}
3646
function upgradeClicker() {
3747
//upgrade clicker (points per click)
38-
if (checkPointsForUpgrade(points, 10 * Math.pow(2, clickMultiplier - 1))) {
39-
setPoints(points - 10 * Math.pow(2, clickMultiplier - 1)); //spend points
40-
setClickMultiplier(clickMultiplier + 1); //increase click multiplier by 1
48+
if (checkPointsForUpgrade(points, 10 * Math.pow(2, clickers - 1))) {
49+
setPoints(points - 10 * Math.pow(2, clickers - 1)); //spend points
50+
setClickers(clickers + 1); //increase clickers by 1
51+
updateClickers();
4152
}
4253
}
4354
function upgradePointsPerSecond() {
4455
//upgrade points per second
4556
if (checkPointsForUpgrade(points, 10 * Math.pow(2, pointsPerSecond))) {
4657
setPoints(points - 10 * Math.pow(2, pointsPerSecond));
47-
setPointsPerSecond(pointsPerSecond + 1); //increase points per second
58+
setAutoClickers(autoClickers + 1); //increase autoclickers by 1
59+
updateAutoClickers();
4860
}
4961
}
5062
return (
@@ -62,18 +74,17 @@ function App() {
6274
</p>
6375
{/*increase points from clicking a button*/}
6476
<button onClick={() => addPointsFromClick()}>Click to Add Points</button>
77+
<br />
6578
{/*upgrade clicker (points per click)*/}
6679
<button onClick={() => upgradeClicker()}>
6780
Upgrade Clicker (Points Per Click)
68-
<br />
69-
<CostDisplay cost={10 * Math.pow(2, clickMultiplier - 1)} />
7081
</button>
82+
<CostDisplay cost={10 * Math.pow(2, clickers - 1)} />
7183
{/*upgrade points per second*/}
7284
<button onClick={() => upgradePointsPerSecond()}>
7385
Upgrade Points Per Second
74-
<br />
75-
<CostDisplay cost={10 * Math.pow(2, pointsPerSecond)} />
7686
</button>
87+
<CostDisplay cost={10 * Math.pow(2, autoClickers)} />
7788
</div>
7889
);
7990
}

0 commit comments

Comments
 (0)