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
@@ -59,8 +59,36 @@
self.phones.splice(index, 1);
}
};
});
+// Shop class representing the shop entity
+var Shop = Container.expand(function () {
+ var self = Container.call(this);
+ self.buyPhone = function (player) {
+ if (player.money >= 100) {
+ var newPhone = new Phone();
+ newPhone.x = Math.random() * 2048;
+ newPhone.y = Math.random() * 2732;
+ player.phones.push(newPhone);
+ game.addChild(newPhone);
+ player.money -= 100;
+ }
+ };
+ self.upgradePhone = function (player, phone) {
+ if (player.money >= 50) {
+ phone.upgrade();
+ player.money -= 50;
+ }
+ };
+ self.sellPhone = function (player, phone) {
+ var sellPrice = phone.sell();
+ player.money += sellPrice;
+ var index = player.phones.indexOf(phone);
+ if (index > -1) {
+ player.phones.splice(index, 1);
+ }
+ };
+});
/****
* Initialize Game
****/
@@ -73,8 +101,10 @@
****/
// Initialize player
var player = new Player();
game.addChild(player);
+// Initialize shop
+var shop = new Shop();
// Display player's money
var moneyTxt = new Text2('Money: $' + player.money, {
size: 50,
fill: "#ffffff"
@@ -103,13 +133,13 @@
}
if (touchedPhone) {
// Upgrade or sell the touched phone
if (obj.event.shiftKey) {
- player.sellPhone(touchedPhone);
+ shop.sellPhone(player, touchedPhone);
} else {
- player.upgradePhone(touchedPhone);
+ shop.upgradePhone(player, touchedPhone);
}
} else {
// Buy a new phone if no phone was touched
- player.buyPhone();
+ shop.buyPhone(player);
}
};
\ No newline at end of file