Hey there everyone
I'm a bit troubled with something I'm trying to construct, I'm trying to create an object that can reproduce itself, creating more objects that can be accessed also, to reproduce themselves. Each object would then be given a random name like: object1, object2 so they can be accessed to create object3, object4, object5 and object6.
I've come up with the following code, which has some segments that you might find weird but those are just testing.
function cMicrobe() {
var prInterval = 1.2;
var prNumber = 1;
this.puX = 50;
this.puY = 50;
this.move = function() {
this.puX += Math.floor(Math.random()*11);
this.puY += Math.floor(Math.random()*11);
}
this.reproduce = function(name) {
prNumber += prNumber;
name = new cMicrobe();
}
this.report = function() {
document.write("x: " + this.puX + "<br />y: " + this.puY + "<br /> <br />");
}
}
oMicrobe = new cMicrobe();
oMicrobe.report();
oMicrobe.move();
oMicrobe.report();
oMicrobe.reproduce("test");
test.report();
I'm quite stuck here, I don't know the keywords to search on Google for this so I can't figure out how I can make an additional object, named test. If I can make test I can make object2, etc.
I'd appreciate some help on this,
thanks