User prompt
make the villager alway move
User prompt
the villager have to alway move
User prompt
Fix Bug: 'ReferenceError: villagers is not defined' in this line: 'var villagerB = villagers[j];' Line Number: 251
User prompt
Fix Bug: 'ReferenceError: villagers is not defined' in this line: 'var villagerA = villagers[i];' Line Number: 250
User prompt
Fix Bug: 'ReferenceError: villagers is not defined' in this line: 'for (var j = i + 1; j < villagers.length; j++) {' Line Number: 249
User prompt
Fix Bug: 'ReferenceError: villagers is not defined' in this line: 'for (var i = 0; i < villagers.length; i++) {' Line Number: 248
User prompt
Fix Bug: 'ReferenceError: villagers is not defined' in this line: 'for (var i = 0; i < villagers.length; i++) {' Line Number: 327
User prompt
Fix Bug: 'TypeError: self.updateResourceDisplay is not a function' in this line: 'self.updateResourceDisplay();' Line Number: 322
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'villagerCountText.setText('Villagers: ' + self.villagers.length);' Line Number: 236
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'villagers')' in this line: 'self.villagers = game.villagers;' Line Number: 226
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'villagerCountText.setText('Villagers: ' + villagers.length);' Line Number: 235
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'villagerCountText.setText('Villagers: ' + villagers.length);' Line Number: 235
User prompt
Fix Bug: 'ReferenceError: villagerCountDisplay is not defined' in this line: 'villagerCountDisplay.update();' Line Number: 318
User prompt
Fix Bug: 'ReferenceError: villagerCountDisplay is not defined' in this line: 'villagerCountDisplay.update();' Line Number: 318
User prompt
Fix Bug: 'TypeError: self.updateVillagerCountDisplay is not a function' in this line: 'self.updateVillagerCountDisplay();' Line Number: 318
User prompt
Fix Bug: 'Uncaught ReferenceError: workplaces is not defined' in this line: 'workplaces.push(workplace);' Line Number: 315
User prompt
Fix Bug: 'Uncaught ReferenceError: workplaces is not defined' in this line: 'workplaces.push(self.createAndAddWorkplace());' Line Number: 306
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'this.workplaces.push(workplace);' Line Number: 302
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'this.houses.push(house);' Line Number: 292
User prompt
Fix Bug: 'Uncaught ReferenceError: villagers is not defined' in this line: 'villagers.push(self.createAndAddVillager(1024, 1366));' Line Number: 284
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in this line: 'this.villagers.push(villager);' Line Number: 280
User prompt
improve all the code in 20 pass
User prompt
improve all the code in 10 pass
User prompt
improve all the code
User prompt
improve 8 time
===================================================================
--- original.js
+++ change.js
@@ -38,9 +38,11 @@
var self = Container.call(this);
Villager.prototype.restAtHome = function () {
this.state = 'resting';
this.tiredness = Math.max(0, this.tiredness - 0.1);
- this.home.occupy(this);
+ if (this.home) {
+ this.home.occupy(this);
+ }
if (this.tiredness <= 0) {
this.state = 'atHome';
}
};
@@ -50,10 +52,10 @@
Villager.prototype.carriedWood = 0;
Villager.prototype.carriedRock = 0;
Villager.prototype.carriedFood = 0;
Villager.prototype.tiredness = 0;
- Villager.prototype.canBuildHouse = function () {
- return this.gameResources.wood.amount >= 200 && this.gameResources.rock.amount >= 200 && this.gameResources.food.amount >= 200;
+ Villager.prototype.canBuildHouse = function (gameResources) {
+ return gameResources.wood.amount >= 200 && gameResources.rock.amount >= 200 && gameResources.food.amount >= 200;
};
Villager.prototype.calculateBuildUtility = function () {
return this.canBuildHouse() ? 0.8 : 0;
};
@@ -196,40 +198,44 @@
self.occupy = function (villager) {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
- this.handleVillagersFallingInLove = function (villagers, houses, resources) {
+ self.handleVillagersFallingInLove = function () {
for (var i = 0; i < villagers.length; i++) {
for (var j = i + 1; j < villagers.length; j++) {
var villagerA = villagers[i];
var villagerB = villagers[j];
if (villagerA.canFallInLove(villagerB)) {
- var newVillager = new Villager(resources);
- newVillager.x = villagerA.home.x;
- newVillager.y = villagerA.home.y;
+ var newVillager = self.createAndAddVillager(villagerA.home.x, villagerA.home.y);
newVillager.home = villagerA.home;
newVillager.workplace = houses[Math.floor(Math.random() * houses.length)];
villagers.push(newVillager);
- this.addChild(newVillager);
villagerA.partner = villagerB;
villagerB.partner = villagerA;
break;
}
}
}
};
- var resources = {
- wood: new Resource('Wood', 100),
- rock: new Resource('Rock', 100),
- food: new Resource('Food', 100)
- };
+ function createResources() {
+ return {
+ wood: new Resource('Wood', 100),
+ rock: new Resource('Rock', 100),
+ food: new Resource('Food', 100)
+ };
+ }
+ var resources = createResources();
self.addChild(resources.wood);
self.addChild(resources.rock);
self.addChild(resources.food);
- var resourceDisplayText = new Text2('Resources: Wood ' + resources.wood.amount + ' Rock ' + resources.rock.amount + ' Food ' + resources.food.amount, {
+ self.updateResourceDisplay = function () {
+ resourceDisplayText.setText('Resources: Wood ' + resources.wood.amount + ' Rock ' + resources.rock.amount + ' Food ' + resources.food.amount);
+ };
+ var resourceDisplayText = new Text2('', {
size: 50,
fill: "#ffffff"
});
+ self.updateResourceDisplay();
resourceDisplayText.anchor.set(0.5, 0);
resourceDisplayText.x = 2048 / 2 - 800 - 500 + 100;
resourceDisplayText.y = 50;
LK.gui.topCenter.addChild(resourceDisplayText);
@@ -239,32 +245,47 @@
background.x = (2048 - background.width) / 2;
background.y = (2732 - background.height) / 2 - 400;
self.addChildAt(background, 0);
var resourceCollector = new ResourceCollector();
- var villagers = [new Villager(resources, resourceCollector), new Villager(resources, resourceCollector)];
- villagers[0].x = 1024;
- villagers[0].y = 1366;
- villagers[1].x = 1024;
- villagers[1].y = 1500;
- self.addChild(villagers[0]);
- self.addChild(villagers[1]);
- var villagerCountText = new Text2('Villagers: 0', {
+ self.createAndAddVillager = function (x, y) {
+ var villager = new Villager(resources);
+ villager.x = x;
+ villager.y = y;
+ self.addChild(villager);
+ return villager;
+ };
+ var villagers = [];
+ villagers.push(self.createAndAddVillager(1024, 1366));
+ villagers.push(self.createAndAddVillager(1024, 1500));
+ self.updateVillagerCountDisplay = function () {
+ villagerCountText.setText('Villagers: ' + villagers.length);
+ };
+ var villagerCountText = new Text2('', {
size: 50,
fill: "#ffffff"
});
+ self.updateVillagerCountDisplay();
villagerCountText.anchor.set(0.5, 0);
villagerCountText.x = 2048 / 2;
villagerCountText.y = 50;
- var houses = [new House()];
- houses[0].x = 2048 / 2;
- houses[0].y = 2732 / 2;
- self.addChild(houses[0]);
+ self.createAndAddHouse = function (x, y) {
+ var house = new House();
+ house.x = x;
+ house.y = y;
+ self.addChild(house);
+ return house;
+ };
+ var houses = [];
+ houses.push(self.createAndAddHouse(2048 / 2, 2732 / 2));
+ self.createAndAddWorkplace = function () {
+ var workplace = new EmployingWorkPlace();
+ workplace.x = Math.random() * 2048;
+ workplace.y = Math.random() * 2732;
+ self.addChild(workplace);
+ return workplace;
+ };
var workplaces = [];
- var workplace = new EmployingWorkPlace();
- workplace.x = Math.random() * 2048;
- workplace.y = Math.random() * 2732;
- workplaces.push(workplace);
- self.addChild(workplace);
+ workplaces.push(self.createAndAddWorkplace());
var house = new OccupiableHouse();
house.x = 2048 / 2;
house.y = 2732 / 2;
houses.push(house);
@@ -274,11 +295,13 @@
workplace.y = Math.random() * 2732;
workplaces.push(workplace);
self.addChild(workplace);
LK.on('tick', function () {
- villagerCountText.setText('Villagers: ' + villagers.length);
+ self.updateVillagerCountDisplay();
+ self.updateResourceDisplay();
LK.gui.topCenter.addChild(villagerCountText);
for (var i = 0; i < villagers.length; i++) {
villagers[i].update();
}
+ self.handleVillagersFallingInLove();
});
});
A background of a paysage with plain and without tree or montainbut no water see from the top in the air 100m by 100m Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
One human medieval villager in a warcraft 2 style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a house in a warcraft 2 style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A tree a rock and crambery in a RTS style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A heart comic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cloud in a comic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A market in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An Inn in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An school in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An bakery in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A well in a RTS fantasy style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A tree in a rts style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An apple in a rts style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A rock in a rts style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A home in a RTS and fantasy style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A brewery in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A lumberjack in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a marketplace in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a festival in a fantasy rts style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.