MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / generateSponge

Method generateSponge

code/main/TheSea.ts:398–425  ·  view source on GitHub ↗
(x1: number, x2: number)

Source from the content-addressed store, hash-verified

396 }
397
398 private generateSponge(x1: number, x2: number): void{
399 // If we don't already have a sponge and no sponge have been generated in this quest so far and the distance is at least 793
400 if(Saving.loadBool("gridItemPossessedSponge") == false && this.spongeGenerated == false && this.distance >= 793){ // 793 because Robert Edmond Grant, a sponge expert, was born in 1793 (source : wikipedia)
401 // Iterate over newly generated floors, searching for one which could receive a sponge
402 for(var i = x1; i <= x2; i++){
403 if(i >= 6 && // We're not too much on the left
404 this.floors[i].getType() == TheSeaFloorType.NORMAL && // This floor has the normal type
405 this.floors[i].getHowManyFloorsOfTheSameTypeBefore() >= 6 // And there's at least 6 floors of the same type before
406 ){
407 // Check if there is already a plant, if so return
408 for(var j = i-6; j <= i; j++){
409 // If this floor already has a plant on it, return
410 if(this.floors[j].getHasAPlant() == true) return;
411 }
412
413 // Add the sponge and change the spongeGenerated bool
414 this.spongeGenerated = true;
415 this.addEntity(new Sponge(this, new Pos(i-6, this.getRealQuestSize().y - this.floors[i].getHeight())));
416 this.getLastEntity().setHealthBar(new QuestEntityHealthBar(this.getLastEntity(), new Pos(6, 1)));
417
418 // Inform the floors that they now have a plant on them (well, actually its a sponge, but these "animals" looks kind of like plants, so don't worry about that)
419 for(var j = i-6; j <= i; j++){
420 this.floors[j].setHasAPlant(true);
421 }
422 }
423 }
424 }
425 }
426
427 private globalScrolling(): void{
428 // How much do we have to scroll ?

Callers 1

generateMethod · 0.95

Calls 9

getHasAPlantMethod · 0.80
addEntityMethod · 0.80
getRealQuestSizeMethod · 0.80
setHealthBarMethod · 0.80
getLastEntityMethod · 0.80
setHasAPlantMethod · 0.80
getTypeMethod · 0.45
getHeightMethod · 0.45

Tested by

no test coverage detected