Skip to content

Commit

Permalink
back to typescript and saves (not loads)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljp-projects committed Oct 14, 2023
1 parent 78d31f4 commit 43934c8
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 924 deletions.
94 changes: 55 additions & 39 deletions buildings.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
var grill: HTMLAudioElement | null = new Audio("designed-fire-winds-swoosh-04-116788.mp3")
var bun: HTMLAudioElement | null = new Audio("crunch-crispy-breadbun-41340.mp3")
var dad: HTMLAudioElement | null = new Audio("dad-says-yummy-113126.mp3")
var farm: HTMLAudioElement | null = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3")
var factory: HTMLAudioElement | null = new Audio("some-kind-of-machine-103152.mp3")
var bank: HTMLAudioElement | null = new Audio("cash-register-purchase-87313.mp3")
var ambience: HTMLAudioElement | null = new Audio("./Hotdog-Clicker-Ambience.m4a")
const grill: HTMLAudioElement | null = new Audio("designed-fire-winds-swoosh-04-116788.mp3")
const bun: HTMLAudioElement | null = new Audio("crunch-crispy-breadbun-41340.mp3")
const dad: HTMLAudioElement | null = new Audio("dad-says-yummy-113126.mp3")
const farm: HTMLAudioElement | null = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3")
const factory: HTMLAudioElement | null = new Audio("some-kind-of-machine-103152.mp3")
const bank: HTMLAudioElement | null = new Audio("cash-register-purchase-87313.mp3")
const ambience: HTMLAudioElement | null = new Audio("./Hotdog-Clicker-Ambience.m4a")
ambience.loop = true;

var bunBuyable: string = "./Can-Buy-Bun-Button.svg"
var bunUnBuyable: string = "./Cant-Buy-Bun-Button.svg"
var bunBuying: string = "./Buying-Bun-Button.svg"
const bunBuyable: string = "./Can-Buy-Bun-Button.svg"
const bunUnBuyable: string = "./Cant-Buy-Bun-Button.svg"
const bunBuying: string = "./Buying-Bun-Button.svg"

var dadBuyable: string = "./Can-Buy-Dad-Button.svg"
var dadUnBuyable: string = "./Cant-Buy-Dad-Button.svg"
var dadBuying: string = "./Buying-Dad-Button.svg"
const dadBuyable: string = "./Can-Buy-Dad-Button.svg"
const dadUnBuyable: string = "./Cant-Buy-Dad-Button.svg"
const dadBuying: string = "./Buying-Dad-Button.svg"

var grillBuyable: string = "./Can-Buy-Grill-Button.svg"
var grillUnBuyable: string = "./Cant-Buy-Grill-Button.svg"
var grillBuying: string = "./Buying-Grill-Button.svg"
const grillBuyable: string = "./Can-Buy-Grill-Button.svg"
const grillUnBuyable: string = "./Cant-Buy-Grill-Button.svg"
const grillBuying: string = "./Buying-Grill-Button.svg"

var farmBuyable: string = "./Can-Buy-Farm-Button.svg"
var farmUnBuyable: string = "./Cant-Buy-Farm-Button.svg"
var farmBuying: string = "./Buying-Farm-Button.svg"
const farmBuyable: string = "./Can-Buy-Farm-Button.svg"
const farmUnBuyable: string = "./Cant-Buy-Farm-Button.svg"
const farmBuying: string = "./Buying-Farm-Button.svg"

var facBuyable: string = "./Can-Buy-Fac-Button.svg"
var facUnBuyable: string = "./Cant-Buy-Fac-Button.svg"
var facBuying: string = "./Buying-Fac-Button.svg"
const facBuyable: string = "./Can-Buy-Fac-Button.svg"
const facUnBuyable: string = "./Cant-Buy-Fac-Button.svg"
const facBuying: string = "./Buying-Fac-Button.svg"

var bankBuyable: string = "./Can-Buy-Bank-Button.svg"
var bankUnBuyable: string = "./Cant-Buy-Bank-Button.svg"
var bankBuying: string = "./Buying-Bank-Button.svg"
const bankBuyable: string = "./Can-Buy-Bank-Button.svg"
const bankUnBuyable: string = "./Cant-Buy-Bank-Button.svg"
const bankBuying: string = "./Buying-Bank-Button.svg"

let passiveClicks: number = 0;
let clickCount: number = 0;
let bunCount: number = 0;
let dadCount: number = 0;
let grillCount: number = 0;
let dogFarmCount: number = 0;
let farmCount: number = 0;
let facCount: number = 0;
let bankCount: number = 0;

Expand All @@ -49,8 +49,8 @@ let dadRate: number = 2;
let grillCost: number = 500;
let grillRate: number = 10;

let dogFarmCost: number = 5000;
let dogFarmRate: number = 50;
let farmCost: number = 5000;
let farmRate: number = 50;

let facCost: number = 50000;
let facRate: number = 500;
Expand All @@ -66,15 +66,15 @@ const clickCountElement: HTMLElement | null = document.getElementById("clickCoun
const grillCountElement: HTMLElement | null = document.getElementById("grillCount");
const bunCountElement: HTMLElement | null = document.getElementById("bunCount");
const dadCountElement: HTMLElement | null = document.getElementById("dadCount");
const dogFarmCountElement: HTMLElement | null = document.getElementById("dogFarmCount");
const farmCountElement: HTMLElement | null = document.getElementById("farmCount");
const facCountElement: HTMLElement | null = document.getElementById("dogFacCount");
const bankCountElement: HTMLElement | null = document.getElementById("dogBankCount");

const hotdogButton: HTMLElement | null = document.getElementById("hotdogButton");
const bunButton: HTMLElement | null = document.getElementById("bunButton");
const dadButton: HTMLElement | null = document.getElementById("dadButton");
const grillButton: HTMLElement | null = document.getElementById("grillButton");
const dogFarmButton: HTMLElement | null = document.getElementById("dogFarmButton");
const farmButton: HTMLElement | null = document.getElementById("farmButton");
const facButton: HTMLElement | null = document.getElementById("dogFacButton");
const bankButton: HTMLElement | null = document.getElementById("dogBankButton")

Expand All @@ -92,6 +92,21 @@ const farmImage: HTMLImageElement | null = document.getElementById("farmImg") as
const facImage: HTMLImageElement | null = document.getElementById("facImg") as HTMLImageElement
const bankImage: HTMLImageElement | null = document.getElementById("bankImg") as HTMLImageElement

const save = (): void => {
const set = (key: string, value: string): void => {
localStorage.setItem(key, value)
}

set('hotdogs', `${clickCount}`)
set('hotdogs/sec', `${passiveClicks}`)
set('bun', `${bunCount},${bunRate},${bunCost}`)
set('dad', `${dadCount},${dadRate},${dadCost}`)
set('grill', `${grillCount},${grillRate},${grillCost}`)
set('farm', `${farmCount},${farmRate},${farmCost}`)
set('factory', `${facCount},${facRate},${facCost}`)
set('bank', `${bankCount},${bankRate},${bankCost}`)
}

const checkBuyables = () => {
if (clickCount >= bunCost) {
bunImage.src = bunBuyable
Expand Down Expand Up @@ -126,7 +141,7 @@ const checkBuyables = () => {
bankImage.src = bankUnBuyable
return
}
if (clickCount >= dogFarmCost) {
if (clickCount >= farmCost) {
farmImage.src = farmBuyable
} else {
console.log("Cant buy farm; therefore, cant buy anything more expensive than grill.")
Expand Down Expand Up @@ -210,17 +225,17 @@ grillButton?.addEventListener("click", function() {
grill?.play();
}
});
dogFarmButton?.addEventListener("click", function() {
if (clickCount >= dogFarmCost && farmPriceElement != null && clickCountElement != null && dogFarmCountElement != null && passiveClicksElement != null) {
clickCount -= dogFarmCost;
dogFarmCost *= increment;
farmButton?.addEventListener("click", function() {
if (clickCount >= farmCost && farmPriceElement != null && clickCountElement != null && farmCountElement != null && passiveClicksElement != null) {
clickCount -= farmCost;
farmCost *= increment;
checkBuyables();
farmImage.src = farmBuying
farmPriceElement.textContent = String(dogFarmCost.toFixed(1));
farmPriceElement.textContent = String(farmCost.toFixed(1));
clickCountElement.textContent = String(clickCount.toFixed(1));
dogFarmCount++;
dogFarmCountElement.textContent = String(dogFarmCount);
passiveClicks += dogFarmRate;
farmCount++;
farmCountElement.textContent = String(farmCount);
passiveClicks += farmRate;
passiveClicksElement.textContent = passiveClicks.toFixed(1);
farm?.play();
}
Expand Down Expand Up @@ -303,5 +318,6 @@ setInterval(function() {
clickCount += passiveClicks;
clickCountElement.textContent = clickCount.toFixed(1);
checkBuyables();
save()
}
}, 1000);
193 changes: 104 additions & 89 deletions buildings.js → dist/buildings.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,92 @@
var grill = new Audio("designed-fire-winds-swoosh-04-116788.mp3");
var bun = new Audio("crunch-crispy-breadbun-41340.mp3");
var dad = new Audio("dad-says-yummy-113126.mp3");
var farm = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3");
var factory = new Audio("some-kind-of-machine-103152.mp3");
var bank = new Audio("cash-register-purchase-87313.mp3");
var ambience = new Audio("./Hotdog-Clicker-Ambience.m4a");
"use strict";
const grill = new Audio("designed-fire-winds-swoosh-04-116788.mp3");
const bun = new Audio("crunch-crispy-breadbun-41340.mp3");
const dad = new Audio("dad-says-yummy-113126.mp3");
const farm = new Audio("zapsplat_impacts_hit_loose_ground_dirt_impact_collapse_fall_013_102682.mp3");
const factory = new Audio("some-kind-of-machine-103152.mp3");
const bank = new Audio("cash-register-purchase-87313.mp3");
const ambience = new Audio("./Hotdog-Clicker-Ambience.m4a");
ambience.loop = true;
var bunBuyable = "./Can-Buy-Bun-Button.svg";
var bunUnBuyable = "./Cant-Buy-Bun-Button.svg";
var bunBuying = "./Buying-Bun-Button.svg";
var dadBuyable = "./Can-Buy-Dad-Button.svg";
var dadUnBuyable = "./Cant-Buy-Dad-Button.svg";
var dadBuying = "./Buying-Dad-Button.svg";
var grillBuyable = "./Can-Buy-Grill-Button.svg";
var grillUnBuyable = "./Cant-Buy-Grill-Button.svg";
var grillBuying = "./Buying-Grill-Button.svg";
var farmBuyable = "./Can-Buy-Farm-Button.svg";
var farmUnBuyable = "./Cant-Buy-Farm-Button.svg";
var farmBuying = "./Buying-Farm-Button.svg";
var facBuyable = "./Can-Buy-Fac-Button.svg";
var facUnBuyable = "./Cant-Buy-Fac-Button.svg";
var facBuying = "./Buying-Fac-Button.svg";
var bankBuyable = "./Can-Buy-Bank-Button.svg";
var bankUnBuyable = "./Cant-Buy-Bank-Button.svg";
var bankBuying = "./Buying-Bank-Button.svg";
var passiveClicks = 0;
var clickCount = 0;
var bunCount = 0;
var dadCount = 0;
var grillCount = 0;
var dogFarmCount = 0;
var facCount = 0;
var bankCount = 0;
var bunCost = 10;
var bunRate = 0.2;
var dadCost = 100;
var dadRate = 2;
var grillCost = 500;
var grillRate = 10;
var dogFarmCost = 5000;
var dogFarmRate = 50;
var facCost = 50000;
var facRate = 500;
var bankCost = 250000;
var bankRate = 2500;
var increment = 1.3;
var passiveClicksElement = document.getElementById("passive");
var clickCountElement = document.getElementById("clickCount");
var grillCountElement = document.getElementById("grillCount");
var bunCountElement = document.getElementById("bunCount");
var dadCountElement = document.getElementById("dadCount");
var dogFarmCountElement = document.getElementById("dogFarmCount");
var facCountElement = document.getElementById("dogFacCount");
var bankCountElement = document.getElementById("dogBankCount");
var hotdogButton = document.getElementById("hotdogButton");
var bunButton = document.getElementById("bunButton");
var dadButton = document.getElementById("dadButton");
var grillButton = document.getElementById("grillButton");
var dogFarmButton = document.getElementById("dogFarmButton");
var facButton = document.getElementById("dogFacButton");
var bankButton = document.getElementById("dogBankButton");
var bunPriceElement = document.getElementById("bunPrice");
var dadPriceElement = document.getElementById("dadPrice");
var grillPriceElement = document.getElementById("grillPrice");
var farmPriceElement = document.getElementById("farmPrice");
var facPriceElement = document.getElementById("facPrice");
var bankPriceElement = document.getElementById("bankPrice");
var bunImage = document.getElementById("bunImg");
var dadImage = document.getElementById("dadImg");
var grillImage = document.getElementById("grillImg");
var farmImage = document.getElementById("farmImg");
var facImage = document.getElementById("facImg");
var bankImage = document.getElementById("bankImg");
var checkBuyables = function () {
const bunBuyable = "./Can-Buy-Bun-Button.svg";
const bunUnBuyable = "./Cant-Buy-Bun-Button.svg";
const bunBuying = "./Buying-Bun-Button.svg";
const dadBuyable = "./Can-Buy-Dad-Button.svg";
const dadUnBuyable = "./Cant-Buy-Dad-Button.svg";
const dadBuying = "./Buying-Dad-Button.svg";
const grillBuyable = "./Can-Buy-Grill-Button.svg";
const grillUnBuyable = "./Cant-Buy-Grill-Button.svg";
const grillBuying = "./Buying-Grill-Button.svg";
const farmBuyable = "./Can-Buy-Farm-Button.svg";
const farmUnBuyable = "./Cant-Buy-Farm-Button.svg";
const farmBuying = "./Buying-Farm-Button.svg";
const facBuyable = "./Can-Buy-Fac-Button.svg";
const facUnBuyable = "./Cant-Buy-Fac-Button.svg";
const facBuying = "./Buying-Fac-Button.svg";
const bankBuyable = "./Can-Buy-Bank-Button.svg";
const bankUnBuyable = "./Cant-Buy-Bank-Button.svg";
const bankBuying = "./Buying-Bank-Button.svg";
let passiveClicks = 0;
let clickCount = 0;
let bunCount = 0;
let dadCount = 0;
let grillCount = 0;
let farmCount = 0;
let facCount = 0;
let bankCount = 0;
let bunCost = 10;
let bunRate = 0.2;
let dadCost = 100;
let dadRate = 2;
let grillCost = 500;
let grillRate = 10;
let farmCost = 5000;
let farmRate = 50;
let facCost = 50000;
let facRate = 500;
let bankCost = 250000;
let bankRate = 2500;
const increment = 1.3;
const passiveClicksElement = document.getElementById("passive");
const clickCountElement = document.getElementById("clickCount");
const grillCountElement = document.getElementById("grillCount");
const bunCountElement = document.getElementById("bunCount");
const dadCountElement = document.getElementById("dadCount");
const farmCountElement = document.getElementById("farmCount");
const facCountElement = document.getElementById("dogFacCount");
const bankCountElement = document.getElementById("dogBankCount");
const hotdogButton = document.getElementById("hotdogButton");
const bunButton = document.getElementById("bunButton");
const dadButton = document.getElementById("dadButton");
const grillButton = document.getElementById("grillButton");
const farmButton = document.getElementById("farmButton");
const facButton = document.getElementById("dogFacButton");
const bankButton = document.getElementById("dogBankButton");
const bunPriceElement = document.getElementById("bunPrice");
const dadPriceElement = document.getElementById("dadPrice");
const grillPriceElement = document.getElementById("grillPrice");
const farmPriceElement = document.getElementById("farmPrice");
const facPriceElement = document.getElementById("facPrice");
const bankPriceElement = document.getElementById("bankPrice");
const bunImage = document.getElementById("bunImg");
const dadImage = document.getElementById("dadImg");
const grillImage = document.getElementById("grillImg");
const farmImage = document.getElementById("farmImg");
const facImage = document.getElementById("facImg");
const bankImage = document.getElementById("bankImg");
const save = () => {
const set = (key, value) => {
localStorage.setItem(key, value);
};
set('hotdogs', `${clickCount}`);
set('hotdogs/sec', `${passiveClicks}`);
set('bun', `${bunCount},${bunRate},${bunCost}`);
set('dad', `${dadCount},${dadRate},${dadCost}`);
set('grill', `${grillCount},${grillRate},${grillCost}`);
set('farm', `${farmCount},${farmRate},${farmCost}`);
set('factory', `${facCount},${facRate},${facCost}`);
set('bank', `${bankCount},${bankRate},${bankCost}`);
};
const checkBuyables = () => {
if (clickCount >= bunCost) {
bunImage.src = bunBuyable;
}
Expand Down Expand Up @@ -109,7 +123,7 @@ var checkBuyables = function () {
bankImage.src = bankUnBuyable;
return;
}
if (clickCount >= dogFarmCost) {
if (clickCount >= farmCost) {
farmImage.src = farmBuyable;
}
else {
Expand Down Expand Up @@ -195,17 +209,17 @@ grillButton === null || grillButton === void 0 ? void 0 : grillButton.addEventLi
grill === null || grill === void 0 ? void 0 : grill.play();
}
});
dogFarmButton === null || dogFarmButton === void 0 ? void 0 : dogFarmButton.addEventListener("click", function () {
if (clickCount >= dogFarmCost && farmPriceElement != null && clickCountElement != null && dogFarmCountElement != null && passiveClicksElement != null) {
clickCount -= dogFarmCost;
dogFarmCost *= increment;
farmButton === null || farmButton === void 0 ? void 0 : farmButton.addEventListener("click", function () {
if (clickCount >= farmCost && farmPriceElement != null && clickCountElement != null && farmCountElement != null && passiveClicksElement != null) {
clickCount -= farmCost;
farmCost *= increment;
checkBuyables();
farmImage.src = farmBuying;
farmPriceElement.textContent = String(dogFarmCost.toFixed(1));
farmPriceElement.textContent = String(farmCost.toFixed(1));
clickCountElement.textContent = String(clickCount.toFixed(1));
dogFarmCount++;
dogFarmCountElement.textContent = String(dogFarmCount);
passiveClicks += dogFarmRate;
farmCount++;
farmCountElement.textContent = String(farmCount);
passiveClicks += farmRate;
passiveClicksElement.textContent = passiveClicks.toFixed(1);
farm === null || farm === void 0 ? void 0 : farm.play();
}
Expand Down Expand Up @@ -241,12 +255,12 @@ bankButton === null || bankButton === void 0 ? void 0 : bankButton.addEventListe
}
});
// Upgrades
var mustardCost = 5000;
var tSauceCost = 1000;
var crispCost = 5000;
var tSauceButton = document.getElementById("tSauceButton");
var mustardButton = document.getElementById("mustardButton");
var crispButton = document.getElementById("crispButton");
const mustardCost = 5000;
const tSauceCost = 1000;
const crispCost = 5000;
const tSauceButton = document.getElementById("tSauceButton");
const mustardButton = document.getElementById("mustardButton");
const crispButton = document.getElementById("crispButton");
tSauceButton === null || tSauceButton === void 0 ? void 0 : tSauceButton.addEventListener("click", function () {
if (clickCount >= tSauceCost && clickCountElement != null && passiveClicksElement != null) {
clickCount -= tSauceCost;
Expand Down Expand Up @@ -281,5 +295,6 @@ setInterval(function () {
clickCount += passiveClicks;
clickCountElement.textContent = clickCount.toFixed(1);
checkBuyables();
save();
}
}, 1000);
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ <h1>Hotdog Clicker</h1>
<button id="crispButton">Buy Extra Crispy Buns (5000 hotdogs)</button>
</div>
</div>
<script src="./new.js"></script>
<script src="./dist/buildings.js"></script>
</body>
</html>
Loading

0 comments on commit 43934c8

Please sign in to comment.