diff --git a/style.css b/style.css index a767944..d1970c8 100644 --- a/style.css +++ b/style.css @@ -1,7 +1,9 @@ :root { + --primary-text: #00d000; + --primary-bg: black; font-family: 'Consolas', 'Cascadia Code', monospace; - color: #00d000; - background: black; + color: var(--primary-text); + background-color: var(--primary-bg); } .tooltip { @@ -42,4 +44,4 @@ a:hover{ font-size: x-large; color:#1F4F82; text-decoration:underline; -} \ No newline at end of file +} diff --git a/user-pages/chauncey-den/backend/game_manager.js b/user-pages/chauncey-den/backend/game_manager.js new file mode 100644 index 0000000..8946338 --- /dev/null +++ b/user-pages/chauncey-den/backend/game_manager.js @@ -0,0 +1,65 @@ +import { GameValue, GameUnlockable } from "../game_engine/types.js"; + +export class GameManager { + constructor() { + // Values + this.clickCount = new GameValue(0); + this.clickModifier = new GameValue(1); + this.chaunceyCount = new GameValue(0); + this.handlerCount = new GameValue(0); + + // Unlocks + this.unlocks = {}; + this.unlocks.firstClick = new GameUnlockable(); + this.unlocks.tenthClick = new GameUnlockable(); + + // Resource unlocks + this.unlocks.resources = new GameUnlockable(); + this.unlocks.chaunceys = new GameUnlockable(); + + // Upgrade unlocks + this.unlocks.upgrades = new GameUnlockable(); + this.unlocks.handlers = new GameUnlockable(); + + this._connectResourceMilestones(); + this._connectUpgradeMilestones(); + this._connectClickMilestones(); + } + + _connectResourceMilestones() { + // Unlock resources and chaunceys on first click + this.unlocks.firstClick.onUnlocked.onNextEventFired(() => { + this.unlocks.resources.onUnlocked.fireEvent(); + this.unlocks.chaunceys.onUnlocked.fireEvent(); + }); + } + + _connectUpgradeMilestones() { + // Unlock upgrades and handlers on tenth click + this.unlocks.tenthClick.onUnlocked.onNextEventFired(() => { + this.unlocks.upgrades.onUnlocked.fireEvent(); + this.unlocks.handlers.onUnlocked.fireEvent(); + }); + } + + _connectClickMilestones() { + // Increment chaunceys each click + this.clickCount.onChanged.onEachEventFired(() => { + this.chaunceyCount.value += this.clickModifier.value; + }); + + // Unlock first click + this.clickCount.onChanged.onNextEventFired(() => { + this.unlocks.firstClick.unlock(); + }); + + // Unlock tenth click + let unlockTenthClick = (clicks) => { + if (clicks >= 10) { + this.unlocks.tenthClick.unlock(); + this.clickCount.onChanged.removeRecurringCallback(self); + } + } + this.clickCount.onChanged.onEachEventFired(unlockTenthClick); + } +} diff --git a/user-pages/chauncey-den/chauncey-den.css b/user-pages/chauncey-den/chauncey-den.css index 0757cf6..6a82312 100644 --- a/user-pages/chauncey-den/chauncey-den.css +++ b/user-pages/chauncey-den/chauncey-den.css @@ -2,6 +2,10 @@ /* First media query is for phone. */ /* A second one is planned for desktops. */ +:root { + color: var(--primary-text) +} + #page-container { margin-block: 0; margin-inline: auto; @@ -51,11 +55,30 @@ h2 { p { margin: 0; - padding-inline: 3dvh; - padding-bottom: 0.75dvh; + margin-bottom: 0.75dvh; + font-size: 2.2dvh; +} + +span { font-size: 2.2dvh; } +button { + margin: 0; + margin-bottom: 0.75dvh; + font-size: 2.1dvh; + color: var(--primary-text); + background-color: var(--primary-bg); +} + +.indent-1 { + margin-left: 3dvh; +} + +.indent-2 { + margin-left: 6dvh; +} + /* Phone */ @media (max-width: 600px) { #page-container { @@ -80,8 +103,24 @@ p { } p { - padding-inline: 4dvw; - padding-bottom: 1dvw; + margin-bottom: 1dvw; font-size: 4dvw; } + + span { + font-size: 4dvw; + } + + button { + margin-bottom: 1dvw; + font-size: 3.8dvw; + } + + .indent-1 { + margin-left: 4dvw; + } + + .indent-2 { + margin-left: 8dvw; + } } diff --git a/user-pages/chauncey-den/chauncey-den.html b/user-pages/chauncey-den/chauncey-den.html index dbf67cb..3663d3c 100644 --- a/user-pages/chauncey-den/chauncey-den.html +++ b/user-pages/chauncey-den/chauncey-den.html @@ -5,7 +5,7 @@ - + Chauncey's Den @@ -15,7 +15,15 @@

Chauncey's Den

+ - \ No newline at end of file + diff --git a/user-pages/chauncey-den/chauncey-den.js b/user-pages/chauncey-den/chauncey-den.js deleted file mode 100644 index 3f4fddb..0000000 --- a/user-pages/chauncey-den/chauncey-den.js +++ /dev/null @@ -1,41 +0,0 @@ -import { GameManager } from "./game_manager.js"; - -// Global vars -let gameManager = new GameManager(); - -let chaunceyImage = document.getElementById("chauncey"); -let resourcesBox = document.getElementById("resources"); -let chaunceyCounter = document.getElementById("chauncey-counter"); - -// Run main when the html loads -document.addEventListener('DOMContentLoaded', function() { - main(); -}); - -function main() { - // Values - gameManager.chaunceyCount.onChanged.onEventFired(onChaunceyChange); - - // Unlocks - gameManager.unlocks.resources.onUnlocked.onEventFired(onUnlockedResources) - gameManager.unlocks.chaunceys.onUnlocked.onEventFired(onUnlockedChaunceys) - - // User Interaction - chaunceyImage.addEventListener("click", onChaunceyClick); -}; - -function onChaunceyClick() { - gameManager.chaunceyCount.value += 1; -} - -function onChaunceyChange(newChaunceyCount) { - chaunceyCounter.textContent = "Chaunceys: " + newChaunceyCount; -} - -function onUnlockedResources() { - resourcesBox.hidden = false; -} - -function onUnlockedChaunceys() { - chaunceyCounter.hidden = false; -} diff --git a/user-pages/chauncey-den/frontend/chauncey-den.js b/user-pages/chauncey-den/frontend/chauncey-den.js new file mode 100644 index 0000000..ae82e72 --- /dev/null +++ b/user-pages/chauncey-den/frontend/chauncey-den.js @@ -0,0 +1,71 @@ +import { GameManager } from "../backend/game_manager.js"; + +// Global vars +let gameManager = new GameManager(); + +let chaunceyButton = document.getElementById("chauncey"); + +// Resources +let resourcesBox = document.getElementById("resources"); +let chaunceyCounter = document.getElementById("chauncey-counter"); + +// Upgrades +let upgradesBox = document.getElementById("upgrades"); +let handlerBox = document.getElementById("handler-box"); +let handlerCounter = document.getElementById("handler-counter"); +let handlerButton = document.getElementById("handler-button"); + +// Run main when the html loads +document.addEventListener('DOMContentLoaded', function() { + main(); +}); + +function main() { + // Values + gameManager.chaunceyCount.onChanged.onEachEventFired(onChaunceyChange); + gameManager.handlerCount.onChanged.onEachEventFired(onHandlerChange); + + // Resource Unlocks + gameManager.unlocks.resources.onUnlocked.onNextEventFired(onUnlockedResources); + gameManager.unlocks.chaunceys.onUnlocked.onNextEventFired(onUnlockedChaunceys); + + // Upgrade Unlocks + gameManager.unlocks.upgrades.onUnlocked.onNextEventFired(onUnlockedUpgrades); + gameManager.unlocks.handlers.onUnlocked.onNextEventFired(onUnlockedHandlers); + + // User Interaction + chaunceyButton.addEventListener("click", onChaunceyClick); + handlerButton.addEventListener("click", onHandlerClick); +}; + +function onChaunceyClick() { + gameManager.clickCount.value += 1; +} + +function onHandlerClick() { + gameManager.handlerCount.value += 1; +} + +function onChaunceyChange(newChaunceyCount) { + chaunceyCounter.textContent = "Chaunceys: " + newChaunceyCount; +} + +function onHandlerChange(newHandlerCount) { + handlerCounter.textContent = "Chauncey Handlers: " + newHandlerCount; +} + +function onUnlockedResources() { + resourcesBox.hidden = false; +} + +function onUnlockedChaunceys() { + chaunceyCounter.hidden = false; +} + +function onUnlockedUpgrades() { + upgradesBox.hidden = false; +} + +function onUnlockedHandlers() { + handlerBox.hidden = false; +} diff --git a/user-pages/chauncey-den/game_engine/game_event.js b/user-pages/chauncey-den/game_engine/game_event.js new file mode 100644 index 0000000..1a5c666 --- /dev/null +++ b/user-pages/chauncey-den/game_engine/game_event.js @@ -0,0 +1,50 @@ +export class GameEvent { + constructor() { + this._callbacks = []; + this._tempCallbacks = []; + } + + // Call all callbacks + fireEvent(data) { + for (const callback of this._callbacks) + callback(data); + + for (const callback of this._tempCallbacks) + callback(data); + this._tempCallbacks = [] + } + + // Add a callback for the every time the event fires + onEachEventFired(callback) { + this._callbacks.push(callback); + } + + // Add a callback for the next time the event fires + onNextEventFired(callback) { + this._tempCallbacks.push(callback); + } + + // Remove a callback + removeCallback(callback) { + this.removeRecurringCallback(callback); + this.removeTempCallback(callback); + } + + // Remove a recurring callback + removeRecurringCallback(callback) { + let index = this._callbacks.indexOf(callback); + this._callbacks.splice(index, 1); + } + + // Remove a temporary callback + removeTempCallback(callback) { + let index = this._tempCallbacks.indexOf(callback); + this._tempCallbacks.splice(index, 1); + } + + // Clear all callbacks + clearAllCallbacks() { + this._callbacks = []; + this._tempCallbacks = []; + } +} diff --git a/user-pages/chauncey-den/game_engine/game_flag.js b/user-pages/chauncey-den/game_engine/game_flag.js new file mode 100644 index 0000000..b15db80 --- /dev/null +++ b/user-pages/chauncey-den/game_engine/game_flag.js @@ -0,0 +1,48 @@ +import { GameEvent } from "./game_event.js"; +import { GameValue } from "./game_value.js"; + +export class GameFlag { + constructor(initialValue) { + this._gameValue = new GameValue(!!initialValue); + + // Events + this.onEnabled = new GameEvent(); + this.onDisabled = new GameEvent(); + this.onChanged = new GameEvent(); + + // Event Cascades + this._gameValue.onChanged.onEachEventFired((newVal) => { + this.onChanged.fireEvent(newVal); + }); + + this.onChanged.onEachEventFired((newVal) => { + if (newVal) + this.onEnabled.fireEvent(); + else + this.onDisabled.fireEvent(); + }); + } + + get isEnabled() { + return this._gameValue.get(); + } + + set isEnabled(newVal) { + this._gameValue.set(!!newVal); + } + + // Enable the flag + enable() { + this.isEnabled = true; + } + + // Disable the flag + disable() { + this.isEnabled = false; + } + + // Toggle the flag + toggle() { + this.isEnabled = !this.isEnabled; + } +} diff --git a/user-pages/chauncey-den/game_engine/game_unlockable.js b/user-pages/chauncey-den/game_engine/game_unlockable.js new file mode 100644 index 0000000..bd34d87 --- /dev/null +++ b/user-pages/chauncey-den/game_engine/game_unlockable.js @@ -0,0 +1,26 @@ +import { GameEvent } from "./game_event.js"; +import { GameFlag } from "./game_flag.js"; + +export class GameUnlockable { + constructor() { + this._gameFlag = new GameFlag(false); + + // Event + this.onUnlocked = new GameEvent(); + + // Event Cascade + this._gameFlag.onEnabled.onNextEventFired(() => { + this.onUnlocked.fireEvent(); + }); + } + + get isUnlocked() { + return this._gameFlag.isEnabled; + } + + // Unlock the unlock + unlock() { + this._gameFlag.enable(); + this.onUnlocked + } +} diff --git a/user-pages/chauncey-den/game_engine/game_value.js b/user-pages/chauncey-den/game_engine/game_value.js new file mode 100644 index 0000000..1caa010 --- /dev/null +++ b/user-pages/chauncey-den/game_engine/game_value.js @@ -0,0 +1,33 @@ +import { GameEvent } from "./game_event.js"; + +export class GameValue { + constructor(initialValue) { + // Value + this._value = initialValue; + + // Event + this.onChanged = new GameEvent(); + } + + get value() { + return this._value; + } + + set value(newVal) { + // If the value hasn't changed, do nothing + if (newVal === this._value) + return; + + // Change value and fire events + this._value = newVal; + this.onChanged.fireEvent(newVal); + } + + get() { + return this.value; + } + + set(newVal) { + this.value = newVal; + } +} diff --git a/user-pages/chauncey-den/game_engine/types.js b/user-pages/chauncey-den/game_engine/types.js new file mode 100644 index 0000000..eefafac --- /dev/null +++ b/user-pages/chauncey-den/game_engine/types.js @@ -0,0 +1,4 @@ +export { GameEvent } from "./game_event.js"; +export { GameValue } from "./game_value.js"; +export { GameFlag } from "./game_flag.js"; +export { GameUnlockable } from "./game_unlockable.js"; diff --git a/user-pages/chauncey-den/game_manager.js b/user-pages/chauncey-den/game_manager.js deleted file mode 100644 index 61e08e2..0000000 --- a/user-pages/chauncey-den/game_manager.js +++ /dev/null @@ -1,142 +0,0 @@ -class GameEvent { - constructor() { - this._callbacks = []; - } - - // Call all callbacks - fireEvent(data) { - for (const callback of this._callbacks) { - callback(data); - } - } - - // Add a callback - onEventFired(callback) { - this._callbacks.push(callback); - } -} - -class GameValue { - constructor(initialValue) { - // Value - this._value = initialValue; - - // Event - this.onChanged = new GameEvent(); - } - - get value() { - return this._value; - } - - set value(newVal) { - // If the value hasn't changed, do nothing - if (newVal === this._value) - return; - - // Change value and fire events - this._value = newVal; - this.onChanged.fireEvent(newVal); - } - - get() { - return this.value; - } - - set(newVal) { - this.value = newVal; - } -} - -class GameFlag { - constructor(initialValue) { - this._gameValue = new GameValue(!!initialValue); - - // Events - this.onEnabled = new GameEvent(); - this.onDisabled = new GameEvent(); - this.onChanged = new GameEvent(); - - // Event Cascades - this._gameValue.onChanged.onEventFired((newVal) => { - this.onChanged.fireEvent(newVal); - }); - - this.onChanged.onEventFired((newVal) => { - if (newVal) - this.onEnabled.fireEvent(); - else - this.onDisabled.fireEvent(); - }); - } - - get isEnabled() { - return this._gameValue.get(); - } - - set isEnabled(newVal) { - this._gameValue.set(!!newVal); - } - - // Enable the flag - enable() { - this.isEnabled = true; - } - - // Disable the flag - disable() { - this.isEnabled = false; - } - - // Toggle the flag - toggle() { - this.isEnabled = !this.isEnabled; - } -} - -class GameUnlockable { - constructor() { - this._gameFlag = new GameFlag(false); - - // Event - this.onUnlocked = new GameEvent(); - - // Event Cascade - this._gameFlag.onEnabled.onEventFired(() => { - this.onUnlocked.fireEvent(); - }); - } - - get isUnlocked() { - return this._gameFlag.isEnabled; - } - - // Unlock the unlock - unlock() { - this._gameFlag.enable(); - } -} - -export class GameManager { - constructor() { - // Values - this.chaunceyCount = new GameValue(0); - - // Unlocks - this.unlocks = {}; - this.unlocks.firstClick = new GameUnlockable(); - this.unlocks.resources = new GameUnlockable(); - this.unlocks.chaunceys = new GameUnlockable(); - - // Unlock resources and chaunceys on first click - this.unlocks.firstClick.onUnlocked.onEventFired(() => { - this.unlocks.resources.onUnlocked.fireEvent(); - this.unlocks.chaunceys.onUnlocked.fireEvent(); - }); - - // Unlock first click when chauncey is clicked - this.chaunceyCount.onChanged.onEventFired(() => { - this.unlocks.firstClick.unlock(); - }); - } -}