User prompt
Add houses
User prompt
Please fix the bug: 'Uncaught TypeError: phoneGraphics.containsPoint is not a function' in or related to this line: 'return phoneGraphics.containsPoint(point);' Line Number: 57
User prompt
Add phone in my shop
User prompt
Customer come my shop
User prompt
Customer come my shop
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'detail')' in or related to this line: 'if (obj.event.detail === 2) {' Line Number: 161
User prompt
Buy old phone
User prompt
Create a shop
User prompt
Please fix the bug: 'Uncaught TypeError: player.phones[i].containsPoint is not a function' in or related to this line: 'if (player.phones[i].containsPoint(localPos)) {' Line Number: 100
Initial prompt
Phone seller
===================================================================
--- original.js
+++ change.js
@@ -24,8 +24,34 @@
self.targetY = Math.random() * 2732;
}
};
});
+// House class representing a house entity
+var House = Container.expand(function () {
+ var self = Container.call(this);
+ var houseGraphics = self.attachAsset('house', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.price = 500; // Initial price of the house
+ self.upgradeLevel = 0; // Initial upgrade level
+ // Method to upgrade the house
+ self.upgrade = function () {
+ self.upgradeLevel++;
+ self.price += 200; // Increase price with each upgrade
+ };
+ // Method to sell the house
+ self.sell = function () {
+ var sellPrice = self.price;
+ self.destroy();
+ return sellPrice;
+ };
+ // Method to check if a point is within the house's bounds
+ self.containsPoint = function (point) {
+ var bounds = houseGraphics.getBounds();
+ return point.x >= bounds.x && point.x <= bounds.x + bounds.width && point.y >= bounds.y && point.y <= bounds.y + bounds.height;
+ };
+});
//<Assets used in the game will automatically appear here>
// Phone class representing a phone entity
var Phone = Container.expand(function () {
var self = Container.call(this);
@@ -111,8 +137,35 @@
if (index > -1) {
player.phones.splice(index, 1);
}
};
+ // Method to buy a house
+ self.buyHouse = function (player) {
+ if (player.money >= 500) {
+ var newHouse = new House();
+ newHouse.x = Math.random() * 2048;
+ newHouse.y = Math.random() * 2732;
+ houses.push(newHouse);
+ game.addChild(newHouse);
+ player.money -= 500;
+ }
+ };
+ // Method to upgrade a house
+ self.upgradeHouse = function (player, house) {
+ if (player.money >= 200) {
+ house.upgrade();
+ player.money -= 200;
+ }
+ };
+ // Method to sell a house
+ self.sellHouse = function (player, house) {
+ var sellPrice = house.sell();
+ player.money += sellPrice;
+ var index = houses.indexOf(house);
+ if (index > -1) {
+ houses.splice(index, 1);
+ }
+ };
// Method to buy an old phone
self.buyOldPhone = function (player) {
if (player.money >= 50) {
// Old phones cost less
@@ -153,8 +206,17 @@
customer.y = Math.random() * 2732;
customers.push(customer);
game.addChild(customer);
}
+// Initialize houses
+var houses = [];
+for (var i = 0; i < 3; i++) {
+ var house = new House();
+ house.x = Math.random() * 2048;
+ house.y = Math.random() * 2732;
+ houses.push(house);
+ game.addChild(house);
+}
// Initialize customers
var customers = [];
for (var i = 0; i < 5; i++) {
var customer = new Customer();
@@ -183,8 +245,12 @@
// Update customers' positions
for (var i = 0; i < customers.length; i++) {
customers[i].update();
}
+ // Update houses' positions
+ for (var i = 0; i < houses.length; i++) {
+ houses[i].update();
+ }
// Update customers' positions
for (var i = 0; i < customers.length; i++) {
customers[i].update();
}
@@ -207,13 +273,30 @@
} else {
shop.upgradePhone(player, touchedPhone);
}
} else {
- // Buy a new phone if no phone was touched
- if (obj.event && obj.event.detail === 2) {
- // Check for double click
- shop.buyOldPhone(player);
+ // Check if a house was touched
+ var touchedHouse = null;
+ for (var i = 0; i < houses.length; i++) {
+ if (houses[i].containsPoint(localPos)) {
+ touchedHouse = houses[i];
+ break;
+ }
+ }
+ if (touchedHouse) {
+ // Upgrade or sell the touched house
+ if (obj.event.shiftKey) {
+ shop.sellHouse(player, touchedHouse);
+ } else {
+ shop.upgradeHouse(player, touchedHouse);
+ }
} else {
- shop.buyPhone(player);
+ // Buy a new phone if no phone or house was touched
+ if (obj.event && obj.event.detail === 2) {
+ // Check for double click
+ shop.buyOldPhone(player);
+ } else {
+ shop.buyPhone(player);
+ }
}
}
};
\ No newline at end of file