diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/idle-build-up.iml b/.idea/idle-build-up.iml new file mode 100644 index 0000000..1a5cf9a --- /dev/null +++ b/.idea/idle-build-up.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..146ab09 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d3f1dd9 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..071bb19 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/css/app.css b/css/app.css new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html new file mode 100644 index 0000000..133d206 --- /dev/null +++ b/index.html @@ -0,0 +1,50 @@ + + + + + Idle Buildup + + + + + +
+
+
+

{{ this.getAmountFormatted() }}

+
+

Buildings owned

+
    +
  • + + {{ building.name }} (Level {{ building.level }}) earning {{ building.amount.toFixed(2) }} every {{ building.intervalInSeconds.toFixed(2) }} seconds.
    +
    +
    + {{ building.loader }} % +
    +
    +
  • +
+ +
+

Buildings to buy

+
    +
  • + + {{ building.name }} could earn {{ building.amount }} every {{ building.intervalInSeconds }} seconds.
    +
  • +
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/js/MoneyManager.js b/js/MoneyManager.js new file mode 100644 index 0000000..aeb4dc0 --- /dev/null +++ b/js/MoneyManager.js @@ -0,0 +1,34 @@ +class MoneyManager { + constructor(startMoney = null) { + this.money = startMoney ?? this.getSavedMoney(); + return this.saveMoney(); + } + + saveMoney() { + localStorage.setItem('money', String(this.money)); + return this.getSavedMoney(); + } + + getSavedMoney() { + this.money = Number(localStorage.getItem('money') ?? 0); + return this.money; + } + + add(amount = 0) { + this.money += amount; + return this.saveMoney(); + } + + sub(amount = 0) { + this.money -= amount; + return this.saveMoney(); + } + + getAmount() { + return this.money; + } + + getAmountFormatted() { + return Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(this.money); + } +} \ No newline at end of file diff --git a/js/app.js b/js/app.js new file mode 100644 index 0000000..a145588 --- /dev/null +++ b/js/app.js @@ -0,0 +1,136 @@ +let game = new Vue({ + el: '#root', + data: { + money: 0, + buildings: [ + { + name: 'TestBuilding', + intervalInSeconds: 10, + amount: 1000, + level: 0, + price: 100, + isOwned: false + } + ], + loadedIntervals: [] + }, + created() { + this.money = this.getSavedMoney(); + this.saveMoney(); + + this.reloadBuildings(); + }, + methods: { + saveMoney() { + localStorage.setItem('money', String(this.money)); + return this.getSavedMoney(); + }, + + getSavedMoney() { + this.money = Number(localStorage.getItem('money') ?? 0); + return this.money; + }, + + add(amount = 0) { + this.money += amount; + return this.saveMoney(); + }, + + sub(amount = 0) { + this.money -= amount; + return this.saveMoney(); + }, + + getAmount() { + return this.money; + }, + + getAmountFormatted() { + return Intl.NumberFormat('de-DE', {style: 'currency', currency: 'EUR'}).format(this.money); + }, + + reloadBuildings() { + this.killIntervals(); + + let game = this; + this.buildings.forEach((building) => { + if (building.isOwned) { + this.loadedIntervals.push( + setInterval(() => { + game.add(building.amount); + }, building.intervalInSeconds * 1000) + ); + + this.loadedIntervals.push( + setInterval(() => { + if (building.loader < 100) { + building.loader += 10; + } else { + building.loader = 10; + } + + game.$forceUpdate() + }, building.intervalInSeconds / 10 * 1000) + ) + } + }); + }, + + killIntervals() { + this.buildings.forEach((building) => { + building.loader = 0; + }); + + this.loadedIntervals.forEach((interval) => { + clearInterval(interval) + }); + }, + + buyBuilding(building) { + if (this.money >= building.price) { + this.sub(building.price); + building.isOwned = true; + + this.upgradeBuilding(building, true); + this.saveBuildings(); + } else { + alert('Not enough money'); + } + }, + + buyUpgrade(building) { + if (this.money >= building.price) { + this.sub(building.price); + this.upgradeBuilding(building) + } else { + alert('Not enough money'); + } + }, + + upgradeBuilding(building, first = false) { + this.killIntervals(); + + building.level++; + building.price *= 1.25; + + if (first === false) { + building.intervalInSeconds *= 0.95; + } + + this.reloadBuildings(); + this.saveBuildings(); + }, + + saveBuildings() { + localStorage.setItem('buildings', JSON.stringify(this.buildings)); + }, + + loadBuildings: function () { + let savedBuildings = JSON.parse(localStorage.getItem('buildings')); + + if (savedBuildings.length > 0) { + this.buildings = savedBuildings; + } + } + }, +});