-
-
Save cymruu/1f48c2afcbeeba4dbde594864c2fc535 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
class Game{ | |
constructor(){ | |
this.coins = 500; | |
this.workers = [0,0]; | |
setInterval(()=>{this.tick();}, 1000); | |
} | |
updateWorkers(id){ | |
this.workers[id]++; | |
} | |
tick(){ | |
console.log(this.coins, this.workers); | |
this.coins += 1+this.workers[0]*3+this.workers[1]*15; | |
} | |
} | |
class Shop { | |
constructor() { | |
this.avaiable = [{name: 'worker', production: 3, price: 5},{name: 'machine', production: 15, price: 50}]; | |
} | |
buy(itemId){ | |
if(this.avaiable[itemId].price <= game.coins){ | |
game.workers[itemId]++; | |
game.coins-=this.avaiable[itemId].price; | |
return true; | |
}else{ | |
console.log('not enough money'); | |
return; | |
} | |
} | |
} | |
var game = new Game(); | |
var shop = new Shop(); | |
shop.buy(0); | |
shop.buy(0); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
shop.buy(1); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment