Skip to content

Instantly share code, notes, and snippets.

@cymruu
Created June 14, 2016 14:53
Show Gist options
  • Save cymruu/1f48c2afcbeeba4dbde594864c2fc535 to your computer and use it in GitHub Desktop.
Save cymruu/1f48c2afcbeeba4dbde594864c2fc535 to your computer and use it in GitHub Desktop.
'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