===================================================================
--- original.js
+++ change.js
@@ -35,8 +35,22 @@
self.demand += Math.random() * 10; // Increase demand randomly
self.supply += Math.random() * 5; // Increase supply randomly
};
});
+// Player class to represent the player in the game
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ self.money = 1000; // Initial money for the player
+ self.update = function () {
+ // Update player logic here
+ // Player earns money from each business
+ for (var i = 0; i < businesses.length; i++) {
+ if (businesses[i].profit() > 0) {
+ self.money += businesses[i].profit();
+ }
+ }
+ };
+});
/****
* Initialize Game
****/
@@ -58,8 +72,11 @@
business.y = 1366; // Center vertically
businesses.push(business);
game.addChild(business);
}
+// Initialize the player
+var player = new Player();
+game.addChild(player);
// Game update logic
game.update = function () {
// Update each business
for (var i = 0; i < businesses.length; i++) {
@@ -70,12 +87,22 @@
}
}
// Update market
market.update();
+ // Update player
+ player.update();
};
// Handle touch events for interaction
game.down = function (x, y, obj) {
- // Handle touch down logic
+ // Buy a new business if the player has enough money
+ if (player.money >= 100) {
+ var business = new Business();
+ business.x = 400 + businesses.length * 300;
+ business.y = 1366; // Center vertically
+ businesses.push(business);
+ game.addChild(business);
+ player.money -= 100; // Deduct the cost of the business from the player's money
+ }
};
game.up = function (x, y, obj) {
// Handle touch up logic
};